xref: /petsc/src/dm/dt/interface/dtds.c (revision d71ae5a4db6382e7f06317b8d368875286fe9008)
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 
52db781477SPatrick Sanan .seealso: `PetscDSRegisterAll()`, `PetscDSRegisterDestroy()`
532764a2aaSMatthew G. Knepley 
542764a2aaSMatthew G. Knepley @*/
55*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
56*d71ae5a4SJacob Faibussowitsch {
572764a2aaSMatthew G. Knepley   PetscFunctionBegin;
589566063dSJacob Faibussowitsch   PetscCall(PetscFunctionListAdd(&PetscDSList, sname, function));
592764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
602764a2aaSMatthew G. Knepley }
612764a2aaSMatthew G. Knepley 
622764a2aaSMatthew G. Knepley /*@C
632764a2aaSMatthew G. Knepley   PetscDSSetType - Builds a particular PetscDS
642764a2aaSMatthew G. Knepley 
65d083f849SBarry Smith   Collective on prob
662764a2aaSMatthew G. Knepley 
672764a2aaSMatthew G. Knepley   Input Parameters:
682764a2aaSMatthew G. Knepley + prob - The PetscDS object
692764a2aaSMatthew G. Knepley - name - The kind of system
702764a2aaSMatthew G. Knepley 
712764a2aaSMatthew G. Knepley   Options Database Key:
722764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
732764a2aaSMatthew G. Knepley 
742764a2aaSMatthew G. Knepley   Level: intermediate
752764a2aaSMatthew G. Knepley 
76f5f57ec0SBarry Smith    Not available from Fortran
77f5f57ec0SBarry Smith 
78db781477SPatrick Sanan .seealso: `PetscDSGetType()`, `PetscDSCreate()`
792764a2aaSMatthew G. Knepley @*/
80*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
81*d71ae5a4SJacob Faibussowitsch {
822764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
832764a2aaSMatthew G. Knepley   PetscBool match;
842764a2aaSMatthew G. Knepley 
852764a2aaSMatthew G. Knepley   PetscFunctionBegin;
862764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
879566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject)prob, name, &match));
882764a2aaSMatthew G. Knepley   if (match) PetscFunctionReturn(0);
892764a2aaSMatthew G. Knepley 
909566063dSJacob Faibussowitsch   PetscCall(PetscDSRegisterAll());
919566063dSJacob Faibussowitsch   PetscCall(PetscFunctionListFind(PetscDSList, name, &r));
9228b400f6SJacob Faibussowitsch   PetscCheck(r, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
932764a2aaSMatthew G. Knepley 
94dbbe0bcdSBarry Smith   PetscTryTypeMethod(prob, destroy);
952764a2aaSMatthew G. Knepley   prob->ops->destroy = NULL;
96dbbe0bcdSBarry Smith 
979566063dSJacob Faibussowitsch   PetscCall((*r)(prob));
989566063dSJacob Faibussowitsch   PetscCall(PetscObjectChangeTypeName((PetscObject)prob, name));
992764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1002764a2aaSMatthew G. Knepley }
1012764a2aaSMatthew G. Knepley 
1022764a2aaSMatthew G. Knepley /*@C
1032764a2aaSMatthew G. Knepley   PetscDSGetType - Gets the PetscDS type name (as a string) from the object.
1042764a2aaSMatthew G. Knepley 
1052764a2aaSMatthew G. Knepley   Not Collective
1062764a2aaSMatthew G. Knepley 
1072764a2aaSMatthew G. Knepley   Input Parameter:
1082764a2aaSMatthew G. Knepley . prob  - The PetscDS
1092764a2aaSMatthew G. Knepley 
1102764a2aaSMatthew G. Knepley   Output Parameter:
1112764a2aaSMatthew G. Knepley . name - The PetscDS type name
1122764a2aaSMatthew G. Knepley 
1132764a2aaSMatthew G. Knepley   Level: intermediate
1142764a2aaSMatthew G. Knepley 
115f5f57ec0SBarry Smith    Not available from Fortran
116f5f57ec0SBarry Smith 
117db781477SPatrick Sanan .seealso: `PetscDSSetType()`, `PetscDSCreate()`
1182764a2aaSMatthew G. Knepley @*/
119*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
120*d71ae5a4SJacob Faibussowitsch {
1212764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1222764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
123c959eef4SJed Brown   PetscValidPointer(name, 2);
1249566063dSJacob Faibussowitsch   PetscCall(PetscDSRegisterAll());
1252764a2aaSMatthew G. Knepley   *name = ((PetscObject)prob)->type_name;
1262764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1272764a2aaSMatthew G. Knepley }
1282764a2aaSMatthew G. Knepley 
129*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSView_Ascii(PetscDS ds, PetscViewer viewer)
130*d71ae5a4SJacob Faibussowitsch {
1317d8a60eaSMatthew G. Knepley   PetscViewerFormat  format;
13297b6e6e8SMatthew G. Knepley   const PetscScalar *constants;
1335fedec97SMatthew G. Knepley   PetscInt           Nf, numConstants, f;
1347d8a60eaSMatthew G. Knepley 
1357d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1369566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(ds, &Nf));
1379566063dSJacob Faibussowitsch   PetscCall(PetscViewerGetFormat(viewer, &format));
13863a3b9bcSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPrintf(viewer, "Discrete System with %" PetscInt_FMT " fields\n", Nf));
1399566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPushTab(viewer));
14063a3b9bcSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPrintf(viewer, "  cell total dim %" PetscInt_FMT " total comp %" PetscInt_FMT "\n", ds->totDim, ds->totComp));
1419566063dSJacob Faibussowitsch   if (ds->isCohesive) PetscCall(PetscViewerASCIIPrintf(viewer, "  cohesive cell\n"));
1425fedec97SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
14340967b3bSMatthew G. Knepley     DSBoundary      b;
1447d8a60eaSMatthew G. Knepley     PetscObject     obj;
1457d8a60eaSMatthew G. Knepley     PetscClassId    id;
146f35450b9SMatthew G. Knepley     PetscQuadrature q;
1477d8a60eaSMatthew G. Knepley     const char     *name;
148f35450b9SMatthew G. Knepley     PetscInt        Nc, Nq, Nqc;
1497d8a60eaSMatthew G. Knepley 
1509566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(ds, f, &obj));
1519566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetClassId(obj, &id));
1529566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetName(obj, &name));
1539566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>"));
1549566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE));
1557d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
1569566063dSJacob Faibussowitsch       PetscCall(PetscFEGetNumComponents((PetscFE)obj, &Nc));
1579566063dSJacob Faibussowitsch       PetscCall(PetscFEGetQuadrature((PetscFE)obj, &q));
1589566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, " FEM"));
1597d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1609566063dSJacob Faibussowitsch       PetscCall(PetscFVGetNumComponents((PetscFV)obj, &Nc));
1619566063dSJacob Faibussowitsch       PetscCall(PetscFVGetQuadrature((PetscFV)obj, &q));
1629566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, " FVM"));
1639371c9d4SSatish Balay     } else SETERRQ(PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %" PetscInt_FMT, f);
16463a3b9bcSJacob Faibussowitsch     if (Nc > 1) PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT " components", Nc));
16563a3b9bcSJacob Faibussowitsch     else PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT " component ", Nc));
1669566063dSJacob Faibussowitsch     if (ds->implicit[f]) PetscCall(PetscViewerASCIIPrintf(viewer, " (implicit)"));
1679566063dSJacob Faibussowitsch     else PetscCall(PetscViewerASCIIPrintf(viewer, " (explicit)"));
1683e60c2a6SMatthew G. Knepley     if (q) {
1699566063dSJacob Faibussowitsch       PetscCall(PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL));
17063a3b9bcSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, " (Nq %" PetscInt_FMT " Nqc %" PetscInt_FMT ")", Nq, Nqc));
1713e60c2a6SMatthew G. Knepley     }
17263a3b9bcSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT "-jet", ds->jetDegree[f]));
1739566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, "\n"));
1749566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE));
1759566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPushTab(viewer));
1769566063dSJacob Faibussowitsch     if (id == PETSCFE_CLASSID) PetscCall(PetscFEView((PetscFE)obj, viewer));
1779566063dSJacob Faibussowitsch     else if (id == PETSCFV_CLASSID) PetscCall(PetscFVView((PetscFV)obj, viewer));
1789566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPopTab(viewer));
17940967b3bSMatthew G. Knepley 
1805fedec97SMatthew G. Knepley     for (b = ds->boundary; b; b = b->next) {
18106ad1575SMatthew G. Knepley       char    *name;
18240967b3bSMatthew G. Knepley       PetscInt c, i;
18340967b3bSMatthew G. Knepley 
18440967b3bSMatthew G. Knepley       if (b->field != f) continue;
1859566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPushTab(viewer));
1869566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->lname, DMBoundaryConditionTypes[b->type]));
18745480ffeSMatthew G. Knepley       if (!b->Nc) {
1889566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIPrintf(viewer, "  all components\n"));
18940967b3bSMatthew G. Knepley       } else {
1909566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIPrintf(viewer, "  components: "));
1919566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE));
19245480ffeSMatthew G. Knepley         for (c = 0; c < b->Nc; ++c) {
1939566063dSJacob Faibussowitsch           if (c > 0) PetscCall(PetscViewerASCIIPrintf(viewer, ", "));
19463a3b9bcSJacob Faibussowitsch           PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT, b->comps[c]));
19540967b3bSMatthew G. Knepley         }
1969566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIPrintf(viewer, "\n"));
1979566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE));
19840967b3bSMatthew G. Knepley       }
1999566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, "  values: "));
2009566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE));
20145480ffeSMatthew G. Knepley       for (i = 0; i < b->Nv; ++i) {
2029566063dSJacob Faibussowitsch         if (i > 0) PetscCall(PetscViewerASCIIPrintf(viewer, ", "));
20363a3b9bcSJacob Faibussowitsch         PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT, b->values[i]));
20440967b3bSMatthew G. Knepley       }
2059566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, "\n"));
2069566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE));
2078e0d8d9cSMatthew G. Knepley       if (b->func) {
2089566063dSJacob Faibussowitsch         PetscCall(PetscDLAddr(b->func, &name));
2099566063dSJacob Faibussowitsch         if (name) PetscCall(PetscViewerASCIIPrintf(viewer, "  func: %s\n", name));
2109566063dSJacob Faibussowitsch         else PetscCall(PetscViewerASCIIPrintf(viewer, "  func: %p\n", b->func));
2119566063dSJacob Faibussowitsch         PetscCall(PetscFree(name));
2128e0d8d9cSMatthew G. Knepley       }
2138e0d8d9cSMatthew G. Knepley       if (b->func_t) {
2149566063dSJacob Faibussowitsch         PetscCall(PetscDLAddr(b->func_t, &name));
2159566063dSJacob Faibussowitsch         if (name) PetscCall(PetscViewerASCIIPrintf(viewer, "  func_t: %s\n", name));
2169566063dSJacob Faibussowitsch         else PetscCall(PetscViewerASCIIPrintf(viewer, "  func_t: %p\n", b->func_t));
2179566063dSJacob Faibussowitsch         PetscCall(PetscFree(name));
2188e0d8d9cSMatthew G. Knepley       }
2199566063dSJacob Faibussowitsch       PetscCall(PetscWeakFormView(b->wf, viewer));
2209566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPopTab(viewer));
22140967b3bSMatthew G. Knepley     }
2227d8a60eaSMatthew G. Knepley   }
2239566063dSJacob Faibussowitsch   PetscCall(PetscDSGetConstants(ds, &numConstants, &constants));
22497b6e6e8SMatthew G. Knepley   if (numConstants) {
22563a3b9bcSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " constants\n", numConstants));
2269566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPushTab(viewer));
2279566063dSJacob Faibussowitsch     for (f = 0; f < numConstants; ++f) PetscCall(PetscViewerASCIIPrintf(viewer, "%g\n", (double)PetscRealPart(constants[f])));
2289566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPopTab(viewer));
22997b6e6e8SMatthew G. Knepley   }
2309566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormView(ds->wf, viewer));
2319566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPopTab(viewer));
2327d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
2337d8a60eaSMatthew G. Knepley }
2347d8a60eaSMatthew G. Knepley 
2352764a2aaSMatthew G. Knepley /*@C
236fe2efc57SMark    PetscDSViewFromOptions - View from Options
237fe2efc57SMark 
238fe2efc57SMark    Collective on PetscDS
239fe2efc57SMark 
240fe2efc57SMark    Input Parameters:
241fe2efc57SMark +  A - the PetscDS object
242736c3998SJose E. Roman .  obj - Optional object
243736c3998SJose E. Roman -  name - command line option
244fe2efc57SMark 
245fe2efc57SMark    Level: intermediate
246db781477SPatrick Sanan .seealso: `PetscDS`, `PetscDSView`, `PetscObjectViewFromOptions()`, `PetscDSCreate()`
247fe2efc57SMark @*/
248*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSViewFromOptions(PetscDS A, PetscObject obj, const char name[])
249*d71ae5a4SJacob Faibussowitsch {
250fe2efc57SMark   PetscFunctionBegin;
251fe2efc57SMark   PetscValidHeaderSpecific(A, PETSCDS_CLASSID, 1);
2529566063dSJacob Faibussowitsch   PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name));
253fe2efc57SMark   PetscFunctionReturn(0);
254fe2efc57SMark }
255fe2efc57SMark 
256fe2efc57SMark /*@C
2572764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
2582764a2aaSMatthew G. Knepley 
259d083f849SBarry Smith   Collective on prob
2602764a2aaSMatthew G. Knepley 
261d8d19677SJose E. Roman   Input Parameters:
2622764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
2632764a2aaSMatthew G. Knepley - v  - the viewer
2642764a2aaSMatthew G. Knepley 
2652764a2aaSMatthew G. Knepley   Level: developer
2662764a2aaSMatthew G. Knepley 
267db781477SPatrick Sanan .seealso `PetscDSDestroy()`
2682764a2aaSMatthew G. Knepley @*/
269*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
270*d71ae5a4SJacob Faibussowitsch {
2717d8a60eaSMatthew G. Knepley   PetscBool iascii;
2722764a2aaSMatthew G. Knepley 
2732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2742764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2759566063dSJacob Faibussowitsch   if (!v) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)prob), &v));
276ad540459SPierre Jolivet   else PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);
2779566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject)v, PETSCVIEWERASCII, &iascii));
2789566063dSJacob Faibussowitsch   if (iascii) PetscCall(PetscDSView_Ascii(prob, v));
279dbbe0bcdSBarry Smith   PetscTryTypeMethod(prob, view, v);
2802764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2812764a2aaSMatthew G. Knepley }
2822764a2aaSMatthew G. Knepley 
2832764a2aaSMatthew G. Knepley /*@
2842764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2852764a2aaSMatthew G. Knepley 
286d083f849SBarry Smith   Collective on prob
2872764a2aaSMatthew G. Knepley 
2882764a2aaSMatthew G. Knepley   Input Parameter:
2892764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2902764a2aaSMatthew G. Knepley 
2912764a2aaSMatthew G. Knepley   Options Database:
292147403d9SBarry Smith + -petscds_type <type>     - Set the DS type
293147403d9SBarry Smith . -petscds_view <view opt> - View the DS
294147403d9SBarry Smith . -petscds_jac_pre         - Turn formation of a separate Jacobian preconditioner on or off
295147403d9SBarry Smith . -bc_<name> <ids>         - Specify a list of label ids for a boundary condition
296147403d9SBarry Smith - -bc_<name>_comp <comps>  - Specify a list of field components to constrain for a boundary condition
2972764a2aaSMatthew G. Knepley 
2982764a2aaSMatthew G. Knepley   Level: developer
2992764a2aaSMatthew G. Knepley 
300db781477SPatrick Sanan .seealso `PetscDSView()`
3012764a2aaSMatthew G. Knepley @*/
302*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
303*d71ae5a4SJacob Faibussowitsch {
304f1fd5e65SToby Isaac   DSBoundary  b;
3052764a2aaSMatthew G. Knepley   const char *defaultType;
3062764a2aaSMatthew G. Knepley   char        name[256];
3072764a2aaSMatthew G. Knepley   PetscBool   flg;
3082764a2aaSMatthew G. Knepley 
3092764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3102764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3112764a2aaSMatthew G. Knepley   if (!((PetscObject)prob)->type_name) {
3122764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
3132764a2aaSMatthew G. Knepley   } else {
3142764a2aaSMatthew G. Knepley     defaultType = ((PetscObject)prob)->type_name;
3152764a2aaSMatthew G. Knepley   }
3169566063dSJacob Faibussowitsch   PetscCall(PetscDSRegisterAll());
3172764a2aaSMatthew G. Knepley 
318d0609cedSBarry Smith   PetscObjectOptionsBegin((PetscObject)prob);
319f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
320f1fd5e65SToby Isaac     char      optname[1024];
321f1fd5e65SToby Isaac     PetscInt  ids[1024], len = 1024;
322f1fd5e65SToby Isaac     PetscBool flg;
323f1fd5e65SToby Isaac 
3249566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name));
3259566063dSJacob Faibussowitsch     PetscCall(PetscMemzero(ids, sizeof(ids)));
3269566063dSJacob Faibussowitsch     PetscCall(PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg));
327f1fd5e65SToby Isaac     if (flg) {
32845480ffeSMatthew G. Knepley       b->Nv = len;
3299566063dSJacob Faibussowitsch       PetscCall(PetscFree(b->values));
3309566063dSJacob Faibussowitsch       PetscCall(PetscMalloc1(len, &b->values));
3319566063dSJacob Faibussowitsch       PetscCall(PetscArraycpy(b->values, ids, len));
3329566063dSJacob Faibussowitsch       PetscCall(PetscWeakFormRewriteKeys(b->wf, b->label, len, b->values));
333f1fd5e65SToby Isaac     }
334e7b0402cSSander Arens     len = 1024;
3359566063dSJacob Faibussowitsch     PetscCall(PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name));
3369566063dSJacob Faibussowitsch     PetscCall(PetscMemzero(ids, sizeof(ids)));
3379566063dSJacob Faibussowitsch     PetscCall(PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg));
338f1fd5e65SToby Isaac     if (flg) {
33945480ffeSMatthew G. Knepley       b->Nc = len;
3409566063dSJacob Faibussowitsch       PetscCall(PetscFree(b->comps));
3419566063dSJacob Faibussowitsch       PetscCall(PetscMalloc1(len, &b->comps));
3429566063dSJacob Faibussowitsch       PetscCall(PetscArraycpy(b->comps, ids, len));
343f1fd5e65SToby Isaac     }
344f1fd5e65SToby Isaac   }
3459566063dSJacob Faibussowitsch   PetscCall(PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg));
3462764a2aaSMatthew G. Knepley   if (flg) {
3479566063dSJacob Faibussowitsch     PetscCall(PetscDSSetType(prob, name));
3482764a2aaSMatthew G. Knepley   } else if (!((PetscObject)prob)->type_name) {
3499566063dSJacob Faibussowitsch     PetscCall(PetscDSSetType(prob, defaultType));
3502764a2aaSMatthew G. Knepley   }
3519566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg));
352dbbe0bcdSBarry Smith   PetscTryTypeMethod(prob, setfromoptions);
3532764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
354dbbe0bcdSBarry Smith   PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)prob, PetscOptionsObject));
355d0609cedSBarry Smith   PetscOptionsEnd();
3569566063dSJacob Faibussowitsch   if (prob->Nf) PetscCall(PetscDSViewFromOptions(prob, NULL, "-petscds_view"));
3572764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3582764a2aaSMatthew G. Knepley }
3592764a2aaSMatthew G. Knepley 
3602764a2aaSMatthew G. Knepley /*@C
3612764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
3622764a2aaSMatthew G. Knepley 
363d083f849SBarry Smith   Collective on prob
3642764a2aaSMatthew G. Knepley 
3652764a2aaSMatthew G. Knepley   Input Parameter:
3662764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
3672764a2aaSMatthew G. Knepley 
3682764a2aaSMatthew G. Knepley   Level: developer
3692764a2aaSMatthew G. Knepley 
370db781477SPatrick Sanan .seealso `PetscDSView()`, `PetscDSDestroy()`
3712764a2aaSMatthew G. Knepley @*/
372*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetUp(PetscDS prob)
373*d71ae5a4SJacob Faibussowitsch {
3742764a2aaSMatthew G. Knepley   const PetscInt Nf   = prob->Nf;
375f9244615SMatthew G. Knepley   PetscBool      hasH = PETSC_FALSE;
3764bee2e38SMatthew G. Knepley   PetscInt       dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f;
3772764a2aaSMatthew G. Knepley 
3782764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3792764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3802764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3812764a2aaSMatthew G. Knepley   /* Calculate sizes */
3829566063dSJacob Faibussowitsch   PetscCall(PetscDSGetSpatialDimension(prob, &dim));
3839566063dSJacob Faibussowitsch   PetscCall(PetscDSGetCoordinateDimension(prob, &dimEmbed));
384f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
3859566063dSJacob Faibussowitsch   PetscCall(PetscMalloc2(Nf, &prob->Nc, Nf, &prob->Nb));
3869566063dSJacob Faibussowitsch   PetscCall(PetscCalloc2(Nf + 1, &prob->off, Nf + 1, &prob->offDer));
3879566063dSJacob Faibussowitsch   PetscCall(PetscCalloc6(Nf + 1, &prob->offCohesive[0], Nf + 1, &prob->offCohesive[1], Nf + 1, &prob->offCohesive[2], Nf + 1, &prob->offDerCohesive[0], Nf + 1, &prob->offDerCohesive[1], Nf + 1, &prob->offDerCohesive[2]));
3889566063dSJacob Faibussowitsch   PetscCall(PetscMalloc2(Nf, &prob->T, Nf, &prob->Tf));
3892764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3909de99aefSMatthew G. Knepley     PetscObject     obj;
3919de99aefSMatthew G. Knepley     PetscClassId    id;
392665f567fSMatthew G. Knepley     PetscQuadrature q  = NULL;
3939de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
3942764a2aaSMatthew G. Knepley 
3959566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(prob, f, &obj));
396f9244615SMatthew G. Knepley     if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE;
397665f567fSMatthew G. Knepley     if (!obj) {
398665f567fSMatthew G. Knepley       /* Empty mesh */
399665f567fSMatthew G. Knepley       Nb = Nc    = 0;
400665f567fSMatthew G. Knepley       prob->T[f] = prob->Tf[f] = NULL;
401665f567fSMatthew G. Knepley     } else {
4029566063dSJacob Faibussowitsch       PetscCall(PetscObjectGetClassId(obj, &id));
4039de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {
4049de99aefSMatthew G. Knepley         PetscFE fe = (PetscFE)obj;
4059de99aefSMatthew G. Knepley 
4069566063dSJacob Faibussowitsch         PetscCall(PetscFEGetQuadrature(fe, &q));
4079566063dSJacob Faibussowitsch         PetscCall(PetscFEGetDimension(fe, &Nb));
4089566063dSJacob Faibussowitsch         PetscCall(PetscFEGetNumComponents(fe, &Nc));
4099566063dSJacob Faibussowitsch         PetscCall(PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f]));
4109566063dSJacob Faibussowitsch         PetscCall(PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f]));
4119de99aefSMatthew G. Knepley       } else if (id == PETSCFV_CLASSID) {
4129de99aefSMatthew G. Knepley         PetscFV fv = (PetscFV)obj;
4139de99aefSMatthew G. Knepley 
4149566063dSJacob Faibussowitsch         PetscCall(PetscFVGetQuadrature(fv, &q));
4159566063dSJacob Faibussowitsch         PetscCall(PetscFVGetNumComponents(fv, &Nc));
4169c3cf19fSMatthew G. Knepley         Nb = Nc;
4179566063dSJacob Faibussowitsch         PetscCall(PetscFVGetCellTabulation(fv, &prob->T[f]));
4184d0b9603SSander Arens         /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
41963a3b9bcSJacob Faibussowitsch       } else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %" PetscInt_FMT, f);
420665f567fSMatthew G. Knepley     }
42147e57110SSander Arens     prob->Nc[f]                    = Nc;
42247e57110SSander Arens     prob->Nb[f]                    = Nb;
423194d53e6SMatthew G. Knepley     prob->off[f + 1]               = Nc + prob->off[f];
424194d53e6SMatthew G. Knepley     prob->offDer[f + 1]            = Nc * dim + prob->offDer[f];
4259ee2af8cSMatthew G. Knepley     prob->offCohesive[0][f + 1]    = (prob->cohesive[f] ? Nc : Nc * 2) + prob->offCohesive[0][f];
4269ee2af8cSMatthew G. Knepley     prob->offDerCohesive[0][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) * dimEmbed + prob->offDerCohesive[0][f];
4279ee2af8cSMatthew G. Knepley     prob->offCohesive[1][f]        = (prob->cohesive[f] ? 0 : Nc) + prob->offCohesive[0][f];
4289ee2af8cSMatthew G. Knepley     prob->offDerCohesive[1][f]     = (prob->cohesive[f] ? 0 : Nc) * dimEmbed + prob->offDerCohesive[0][f];
4299ee2af8cSMatthew G. Knepley     prob->offCohesive[2][f + 1]    = (prob->cohesive[f] ? Nc : Nc * 2) + prob->offCohesive[2][f];
4309ee2af8cSMatthew G. Knepley     prob->offDerCohesive[2][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) * dimEmbed + prob->offDerCohesive[2][f];
4319566063dSJacob Faibussowitsch     if (q) PetscCall(PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL));
4322764a2aaSMatthew G. Knepley     NqMax = PetscMax(NqMax, Nq);
4334bee2e38SMatthew G. Knepley     NbMax = PetscMax(NbMax, Nb);
4342764a2aaSMatthew G. Knepley     NcMax = PetscMax(NcMax, Nc);
4359c3cf19fSMatthew G. Knepley     prob->totDim += Nb;
4362764a2aaSMatthew G. Knepley     prob->totComp += Nc;
4375fedec97SMatthew G. Knepley     /* There are two faces for all fields on a cohesive cell, except for cohesive fields */
4385fedec97SMatthew G. Knepley     if (prob->isCohesive && !prob->cohesive[f]) prob->totDim += Nb;
4392764a2aaSMatthew G. Knepley   }
4409ee2af8cSMatthew G. Knepley   prob->offCohesive[1][Nf]    = prob->offCohesive[0][Nf];
4419ee2af8cSMatthew G. Knepley   prob->offDerCohesive[1][Nf] = prob->offDerCohesive[0][Nf];
4422764a2aaSMatthew G. Knepley   /* Allocate works space */
4435fedec97SMatthew G. Knepley   NsMax = 2; /* A non-cohesive discretizations can be used on a cohesive cell, so we need this extra workspace for all DS */
4449566063dSJacob Faibussowitsch   PetscCall(PetscMalloc3(NsMax * prob->totComp, &prob->u, NsMax * prob->totComp, &prob->u_t, NsMax * prob->totComp * dimEmbed + (hasH ? NsMax * prob->totComp * dimEmbed * dimEmbed : 0), &prob->u_x));
4459566063dSJacob Faibussowitsch   PetscCall(PetscMalloc5(dimEmbed, &prob->x, NbMax * NcMax, &prob->basisReal, NbMax * NcMax * dimEmbed, &prob->basisDerReal, NbMax * NcMax, &prob->testReal, NbMax * NcMax * dimEmbed, &prob->testDerReal));
4469371c9d4SSatish Balay   PetscCall(PetscMalloc6(NsMax * NqMax * NcMax, &prob->f0, NsMax * NqMax * NcMax * dimEmbed, &prob->f1, NsMax * NsMax * NqMax * NcMax * NcMax, &prob->g0, NsMax * NsMax * NqMax * NcMax * NcMax * dimEmbed, &prob->g1, NsMax * NsMax * NqMax * NcMax * NcMax * dimEmbed,
4479371c9d4SSatish Balay                          &prob->g2, NsMax * NsMax * NqMax * NcMax * NcMax * dimEmbed * dimEmbed, &prob->g3));
448dbbe0bcdSBarry Smith   PetscTryTypeMethod(prob, setup);
4492764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
4502764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4512764a2aaSMatthew G. Knepley }
4522764a2aaSMatthew G. Knepley 
453*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
454*d71ae5a4SJacob Faibussowitsch {
4552764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4569566063dSJacob Faibussowitsch   PetscCall(PetscFree2(prob->Nc, prob->Nb));
4579566063dSJacob Faibussowitsch   PetscCall(PetscFree2(prob->off, prob->offDer));
4589566063dSJacob Faibussowitsch   PetscCall(PetscFree6(prob->offCohesive[0], prob->offCohesive[1], prob->offCohesive[2], prob->offDerCohesive[0], prob->offDerCohesive[1], prob->offDerCohesive[2]));
4599566063dSJacob Faibussowitsch   PetscCall(PetscFree2(prob->T, prob->Tf));
4609566063dSJacob Faibussowitsch   PetscCall(PetscFree3(prob->u, prob->u_t, prob->u_x));
4619566063dSJacob Faibussowitsch   PetscCall(PetscFree5(prob->x, prob->basisReal, prob->basisDerReal, prob->testReal, prob->testDerReal));
4629566063dSJacob Faibussowitsch   PetscCall(PetscFree6(prob->f0, prob->f1, prob->g0, prob->g1, prob->g2, prob->g3));
4632764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4642764a2aaSMatthew G. Knepley }
4652764a2aaSMatthew G. Knepley 
466*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
467*d71ae5a4SJacob Faibussowitsch {
468f744cafaSSander Arens   PetscObject          *tmpd;
46934aa8a36SMatthew G. Knepley   PetscBool            *tmpi;
470f9244615SMatthew G. Knepley   PetscInt             *tmpk;
4715fedec97SMatthew G. Knepley   PetscBool            *tmpc;
4726528b96dSMatthew G. Knepley   PetscPointFunc       *tmpup;
473f2cacb80SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol, *tmpexactSol_t;
474f2cacb80SMatthew G. Knepley   void                **tmpexactCtx, **tmpexactCtx_t;
4750c2f2876SMatthew G. Knepley   void                **tmpctx;
47634aa8a36SMatthew G. Knepley   PetscInt              Nf = prob->Nf, f;
4772764a2aaSMatthew G. Knepley 
4782764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4792764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
4802764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
4819566063dSJacob Faibussowitsch   PetscCall(PetscDSDestroyStructs_Static(prob));
4829566063dSJacob Faibussowitsch   PetscCall(PetscMalloc4(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpc, NfNew, &tmpk));
4839371c9d4SSatish Balay   for (f = 0; f < Nf; ++f) {
4849371c9d4SSatish Balay     tmpd[f] = prob->disc[f];
4859371c9d4SSatish Balay     tmpi[f] = prob->implicit[f];
4869371c9d4SSatish Balay     tmpc[f] = prob->cohesive[f];
4879371c9d4SSatish Balay     tmpk[f] = prob->jetDegree[f];
4889371c9d4SSatish Balay   }
4899371c9d4SSatish Balay   for (f = Nf; f < NfNew; ++f) {
4909371c9d4SSatish Balay     tmpd[f] = NULL;
4919371c9d4SSatish Balay     tmpi[f] = PETSC_TRUE, tmpc[f] = PETSC_FALSE;
4929371c9d4SSatish Balay     tmpk[f] = 1;
4939371c9d4SSatish Balay   }
4949566063dSJacob Faibussowitsch   PetscCall(PetscFree4(prob->disc, prob->implicit, prob->cohesive, prob->jetDegree));
4959566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(prob->wf, NfNew));
4962764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
4972764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
498249df284SMatthew G. Knepley   prob->implicit  = tmpi;
4995fedec97SMatthew G. Knepley   prob->cohesive  = tmpc;
500f9244615SMatthew G. Knepley   prob->jetDegree = tmpk;
5019566063dSJacob Faibussowitsch   PetscCall(PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx));
50232d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
5030c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
50432d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
5050c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
5069566063dSJacob Faibussowitsch   PetscCall(PetscFree2(prob->update, prob->ctx));
50732d2bbc9SMatthew G. Knepley   prob->update = tmpup;
5080c2f2876SMatthew G. Knepley   prob->ctx    = tmpctx;
5099566063dSJacob Faibussowitsch   PetscCall(PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t));
510c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
51195cbbfd3SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f];
512f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f];
513f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f];
514c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
51595cbbfd3SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL;
516f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL;
517f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL;
5189566063dSJacob Faibussowitsch   PetscCall(PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t));
519c371a6d1SMatthew G. Knepley   prob->exactSol   = tmpexactSol;
52095cbbfd3SMatthew G. Knepley   prob->exactCtx   = tmpexactCtx;
521f2cacb80SMatthew G. Knepley   prob->exactSol_t = tmpexactSol_t;
522f2cacb80SMatthew G. Knepley   prob->exactCtx_t = tmpexactCtx_t;
5232764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5242764a2aaSMatthew G. Knepley }
5252764a2aaSMatthew G. Knepley 
5262764a2aaSMatthew G. Knepley /*@
5272764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
5282764a2aaSMatthew G. Knepley 
529d083f849SBarry Smith   Collective on prob
5302764a2aaSMatthew G. Knepley 
5312764a2aaSMatthew G. Knepley   Input Parameter:
5322764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
5332764a2aaSMatthew G. Knepley 
5342764a2aaSMatthew G. Knepley   Level: developer
5352764a2aaSMatthew G. Knepley 
536db781477SPatrick Sanan .seealso `PetscDSView()`
5372764a2aaSMatthew G. Knepley @*/
538*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSDestroy(PetscDS *ds)
539*d71ae5a4SJacob Faibussowitsch {
5402764a2aaSMatthew G. Knepley   PetscInt f;
5412764a2aaSMatthew G. Knepley 
5422764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5436528b96dSMatthew G. Knepley   if (!*ds) PetscFunctionReturn(0);
5446528b96dSMatthew G. Knepley   PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1);
5452764a2aaSMatthew G. Knepley 
5469371c9d4SSatish Balay   if (--((PetscObject)(*ds))->refct > 0) {
5479371c9d4SSatish Balay     *ds = NULL;
5489371c9d4SSatish Balay     PetscFunctionReturn(0);
5499371c9d4SSatish Balay   }
5506528b96dSMatthew G. Knepley   ((PetscObject)(*ds))->refct = 0;
5516528b96dSMatthew G. Knepley   if ((*ds)->subprobs) {
552df3a45bdSMatthew G. Knepley     PetscInt dim, d;
553df3a45bdSMatthew G. Knepley 
5549566063dSJacob Faibussowitsch     PetscCall(PetscDSGetSpatialDimension(*ds, &dim));
5559566063dSJacob Faibussowitsch     for (d = 0; d < dim; ++d) PetscCall(PetscDSDestroy(&(*ds)->subprobs[d]));
556df3a45bdSMatthew G. Knepley   }
5579566063dSJacob Faibussowitsch   PetscCall(PetscFree((*ds)->subprobs));
5589566063dSJacob Faibussowitsch   PetscCall(PetscDSDestroyStructs_Static(*ds));
55948a46eb9SPierre Jolivet   for (f = 0; f < (*ds)->Nf; ++f) PetscCall(PetscObjectDereference((*ds)->disc[f]));
5609566063dSJacob Faibussowitsch   PetscCall(PetscFree4((*ds)->disc, (*ds)->implicit, (*ds)->cohesive, (*ds)->jetDegree));
5619566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormDestroy(&(*ds)->wf));
5629566063dSJacob Faibussowitsch   PetscCall(PetscFree2((*ds)->update, (*ds)->ctx));
5639566063dSJacob Faibussowitsch   PetscCall(PetscFree4((*ds)->exactSol, (*ds)->exactCtx, (*ds)->exactSol_t, (*ds)->exactCtx_t));
564dbbe0bcdSBarry Smith   PetscTryTypeMethod((*ds), destroy);
5659566063dSJacob Faibussowitsch   PetscCall(PetscDSDestroyBoundary(*ds));
5669566063dSJacob Faibussowitsch   PetscCall(PetscFree((*ds)->constants));
5679566063dSJacob Faibussowitsch   PetscCall(PetscHeaderDestroy(ds));
5682764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5692764a2aaSMatthew G. Knepley }
5702764a2aaSMatthew G. Knepley 
5712764a2aaSMatthew G. Knepley /*@
5722764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
5732764a2aaSMatthew G. Knepley 
574d083f849SBarry Smith   Collective
5752764a2aaSMatthew G. Knepley 
5762764a2aaSMatthew G. Knepley   Input Parameter:
5772764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
5782764a2aaSMatthew G. Knepley 
5792764a2aaSMatthew G. Knepley   Output Parameter:
5806528b96dSMatthew G. Knepley . ds   - The PetscDS object
5812764a2aaSMatthew G. Knepley 
5822764a2aaSMatthew G. Knepley   Level: beginner
5832764a2aaSMatthew G. Knepley 
584db781477SPatrick Sanan .seealso: `PetscDSSetType()`, `PETSCDSBASIC`
5852764a2aaSMatthew G. Knepley @*/
586*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds)
587*d71ae5a4SJacob Faibussowitsch {
5882764a2aaSMatthew G. Knepley   PetscDS p;
5892764a2aaSMatthew G. Knepley 
5902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5916528b96dSMatthew G. Knepley   PetscValidPointer(ds, 2);
5926528b96dSMatthew G. Knepley   *ds = NULL;
5939566063dSJacob Faibussowitsch   PetscCall(PetscDSInitializePackage());
5942764a2aaSMatthew G. Knepley 
5959566063dSJacob Faibussowitsch   PetscCall(PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView));
5962764a2aaSMatthew G. Knepley 
5972764a2aaSMatthew G. Knepley   p->Nf           = 0;
5982764a2aaSMatthew G. Knepley   p->setup        = PETSC_FALSE;
59997b6e6e8SMatthew G. Knepley   p->numConstants = 0;
60097b6e6e8SMatthew G. Knepley   p->constants    = NULL;
601a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
60255c1f793SMatthew G. Knepley   p->useJacPre    = PETSC_TRUE;
6039566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(comm, &p->wf));
6042764a2aaSMatthew G. Knepley 
6056528b96dSMatthew G. Knepley   *ds = p;
6062764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6072764a2aaSMatthew G. Knepley }
6082764a2aaSMatthew G. Knepley 
609bc4ae4beSMatthew G. Knepley /*@
610bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
611bc4ae4beSMatthew G. Knepley 
612bc4ae4beSMatthew G. Knepley   Not collective
613bc4ae4beSMatthew G. Knepley 
614bc4ae4beSMatthew G. Knepley   Input Parameter:
615bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
616bc4ae4beSMatthew G. Knepley 
617bc4ae4beSMatthew G. Knepley   Output Parameter:
618bc4ae4beSMatthew G. Knepley . Nf - The number of fields
619bc4ae4beSMatthew G. Knepley 
620bc4ae4beSMatthew G. Knepley   Level: beginner
621bc4ae4beSMatthew G. Knepley 
622db781477SPatrick Sanan .seealso: `PetscDSGetSpatialDimension()`, `PetscDSCreate()`
623bc4ae4beSMatthew G. Knepley @*/
624*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
625*d71ae5a4SJacob Faibussowitsch {
6262764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6272764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
628dadcf809SJacob Faibussowitsch   PetscValidIntPointer(Nf, 2);
6292764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
6302764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6312764a2aaSMatthew G. Knepley }
6322764a2aaSMatthew G. Knepley 
633bc4ae4beSMatthew G. Knepley /*@
634a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
635bc4ae4beSMatthew G. Knepley 
636bc4ae4beSMatthew G. Knepley   Not collective
637bc4ae4beSMatthew G. Knepley 
638bc4ae4beSMatthew G. Knepley   Input Parameter:
639bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
640bc4ae4beSMatthew G. Knepley 
641bc4ae4beSMatthew G. Knepley   Output Parameter:
642bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
643bc4ae4beSMatthew G. Knepley 
644bc4ae4beSMatthew G. Knepley   Level: beginner
645bc4ae4beSMatthew G. Knepley 
646db781477SPatrick Sanan .seealso: `PetscDSGetCoordinateDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
647bc4ae4beSMatthew G. Knepley @*/
648*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
649*d71ae5a4SJacob Faibussowitsch {
6502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6512764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
652dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dim, 2);
6532764a2aaSMatthew G. Knepley   *dim = 0;
6549de99aefSMatthew G. Knepley   if (prob->Nf) {
6559de99aefSMatthew G. Knepley     PetscObject  obj;
6569de99aefSMatthew G. Knepley     PetscClassId id;
6579de99aefSMatthew G. Knepley 
6589566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(prob, 0, &obj));
659665f567fSMatthew G. Knepley     if (obj) {
6609566063dSJacob Faibussowitsch       PetscCall(PetscObjectGetClassId(obj, &id));
6619566063dSJacob Faibussowitsch       if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetSpatialDimension((PetscFE)obj, dim));
6629566063dSJacob Faibussowitsch       else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetSpatialDimension((PetscFV)obj, dim));
66398921bdaSJacob Faibussowitsch       else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
6649de99aefSMatthew G. Knepley     }
665665f567fSMatthew G. Knepley   }
6662764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6672764a2aaSMatthew G. Knepley }
6682764a2aaSMatthew G. Knepley 
669bc4ae4beSMatthew G. Knepley /*@
670a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
671a859676bSMatthew G. Knepley 
672a859676bSMatthew G. Knepley   Not collective
673a859676bSMatthew G. Knepley 
674a859676bSMatthew G. Knepley   Input Parameter:
675a859676bSMatthew G. Knepley . prob - The PetscDS object
676a859676bSMatthew G. Knepley 
677a859676bSMatthew G. Knepley   Output Parameter:
678a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
679a859676bSMatthew G. Knepley 
680a859676bSMatthew G. Knepley   Level: beginner
681a859676bSMatthew G. Knepley 
682db781477SPatrick Sanan .seealso: `PetscDSSetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
683a859676bSMatthew G. Knepley @*/
684*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
685*d71ae5a4SJacob Faibussowitsch {
686a859676bSMatthew G. Knepley   PetscFunctionBegin;
687a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
688dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dimEmbed, 2);
68908401ef6SPierre Jolivet   PetscCheck(prob->dimEmbed >= 0, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
690a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
691a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
692a859676bSMatthew G. Knepley }
693a859676bSMatthew G. Knepley 
694a859676bSMatthew G. Knepley /*@
695a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
696a859676bSMatthew G. Knepley 
697d083f849SBarry Smith   Logically collective on prob
698a859676bSMatthew G. Knepley 
699a859676bSMatthew G. Knepley   Input Parameters:
700a859676bSMatthew G. Knepley + prob - The PetscDS object
701a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
702a859676bSMatthew G. Knepley 
703a859676bSMatthew G. Knepley   Level: beginner
704a859676bSMatthew G. Knepley 
705db781477SPatrick Sanan .seealso: `PetscDSGetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
706a859676bSMatthew G. Knepley @*/
707*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
708*d71ae5a4SJacob Faibussowitsch {
709a859676bSMatthew G. Knepley   PetscFunctionBegin;
710a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
71163a3b9bcSJacob Faibussowitsch   PetscCheck(dimEmbed >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %" PetscInt_FMT, dimEmbed);
712a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
713a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
714a859676bSMatthew G. Knepley }
715a859676bSMatthew G. Knepley 
716a859676bSMatthew G. Knepley /*@
7175fedec97SMatthew G. Knepley   PetscDSIsCohesive - Returns the flag indicating that this DS is for a cohesive cell
7188edf6225SMatthew G. Knepley 
7198edf6225SMatthew G. Knepley   Not collective
7208edf6225SMatthew G. Knepley 
7218edf6225SMatthew G. Knepley   Input Parameter:
7225fedec97SMatthew G. Knepley . ds - The PetscDS object
7238edf6225SMatthew G. Knepley 
7248edf6225SMatthew G. Knepley   Output Parameter:
7255fedec97SMatthew G. Knepley . isCohesive - The flag
7268edf6225SMatthew G. Knepley 
7278edf6225SMatthew G. Knepley   Level: developer
7288edf6225SMatthew G. Knepley 
729db781477SPatrick Sanan .seealso: `PetscDSGetNumCohesive()`, `PetscDSGetCohesive()`, `PetscDSSetCohesive()`, `PetscDSCreate()`
7308edf6225SMatthew G. Knepley @*/
731*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSIsCohesive(PetscDS ds, PetscBool *isCohesive)
732*d71ae5a4SJacob Faibussowitsch {
7338edf6225SMatthew G. Knepley   PetscFunctionBegin;
7345fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
735dadcf809SJacob Faibussowitsch   PetscValidBoolPointer(isCohesive, 2);
7365fedec97SMatthew G. Knepley   *isCohesive = ds->isCohesive;
7378edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
7388edf6225SMatthew G. Knepley }
7398edf6225SMatthew G. Knepley 
7408edf6225SMatthew G. Knepley /*@
7415fedec97SMatthew G. Knepley   PetscDSGetNumCohesive - Returns the numer of cohesive fields, meaning those defined on the interior of a cohesive cell
7425fedec97SMatthew G. Knepley 
7435fedec97SMatthew G. Knepley   Not collective
7445fedec97SMatthew G. Knepley 
7455fedec97SMatthew G. Knepley   Input Parameter:
7465fedec97SMatthew G. Knepley . ds - The PetscDS object
7475fedec97SMatthew G. Knepley 
7485fedec97SMatthew G. Knepley   Output Parameter:
7495fedec97SMatthew G. Knepley . numCohesive - The number of cohesive fields
7505fedec97SMatthew G. Knepley 
7515fedec97SMatthew G. Knepley   Level: developer
7525fedec97SMatthew G. Knepley 
753db781477SPatrick Sanan .seealso: `PetscDSSetCohesive()`, `PetscDSCreate()`
7545fedec97SMatthew G. Knepley @*/
755*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumCohesive(PetscDS ds, PetscInt *numCohesive)
756*d71ae5a4SJacob Faibussowitsch {
7575fedec97SMatthew G. Knepley   PetscInt f;
7585fedec97SMatthew G. Knepley 
7595fedec97SMatthew G. Knepley   PetscFunctionBegin;
7605fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
761dadcf809SJacob Faibussowitsch   PetscValidIntPointer(numCohesive, 2);
7625fedec97SMatthew G. Knepley   *numCohesive = 0;
7635fedec97SMatthew G. Knepley   for (f = 0; f < ds->Nf; ++f) *numCohesive += ds->cohesive[f] ? 1 : 0;
7645fedec97SMatthew G. Knepley   PetscFunctionReturn(0);
7655fedec97SMatthew G. Knepley }
7665fedec97SMatthew G. Knepley 
7675fedec97SMatthew G. Knepley /*@
7685fedec97SMatthew G. Knepley   PetscDSGetCohesive - Returns the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell
7695fedec97SMatthew G. Knepley 
7705fedec97SMatthew G. Knepley   Not collective
7715fedec97SMatthew G. Knepley 
772f1a722f8SMatthew G. Knepley   Input Parameters:
7735fedec97SMatthew G. Knepley + ds - The PetscDS object
7745fedec97SMatthew G. Knepley - f  - The field index
7755fedec97SMatthew G. Knepley 
7765fedec97SMatthew G. Knepley   Output Parameter:
7775fedec97SMatthew G. Knepley . isCohesive - The flag
7785fedec97SMatthew G. Knepley 
7795fedec97SMatthew G. Knepley   Level: developer
7805fedec97SMatthew G. Knepley 
781db781477SPatrick Sanan .seealso: `PetscDSSetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()`
7825fedec97SMatthew G. Knepley @*/
783*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetCohesive(PetscDS ds, PetscInt f, PetscBool *isCohesive)
784*d71ae5a4SJacob Faibussowitsch {
7855fedec97SMatthew G. Knepley   PetscFunctionBegin;
7865fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
787dadcf809SJacob Faibussowitsch   PetscValidBoolPointer(isCohesive, 3);
78863a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
7895fedec97SMatthew G. Knepley   *isCohesive = ds->cohesive[f];
7905fedec97SMatthew G. Knepley   PetscFunctionReturn(0);
7915fedec97SMatthew G. Knepley }
7925fedec97SMatthew G. Knepley 
7935fedec97SMatthew G. Knepley /*@
7945fedec97SMatthew G. Knepley   PetscDSSetCohesive - Set the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell
7958edf6225SMatthew G. Knepley 
7968edf6225SMatthew G. Knepley   Not collective
7978edf6225SMatthew G. Knepley 
7988edf6225SMatthew G. Knepley   Input Parameters:
7995fedec97SMatthew G. Knepley + ds - The PetscDS object
8005fedec97SMatthew G. Knepley . f  - The field index
8015fedec97SMatthew G. Knepley - isCohesive - The flag for a cohesive field
8028edf6225SMatthew G. Knepley 
8038edf6225SMatthew G. Knepley   Level: developer
8048edf6225SMatthew G. Knepley 
805db781477SPatrick Sanan .seealso: `PetscDSGetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()`
8068edf6225SMatthew G. Knepley @*/
807*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetCohesive(PetscDS ds, PetscInt f, PetscBool isCohesive)
808*d71ae5a4SJacob Faibussowitsch {
8095fedec97SMatthew G. Knepley   PetscInt i;
8105fedec97SMatthew G. Knepley 
8118edf6225SMatthew G. Knepley   PetscFunctionBegin;
8125fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
81363a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
8145fedec97SMatthew G. Knepley   ds->cohesive[f] = isCohesive;
8155fedec97SMatthew G. Knepley   ds->isCohesive  = PETSC_FALSE;
8165fedec97SMatthew G. Knepley   for (i = 0; i < ds->Nf; ++i) ds->isCohesive = ds->isCohesive || ds->cohesive[f] ? PETSC_TRUE : PETSC_FALSE;
8178edf6225SMatthew G. Knepley   PetscFunctionReturn(0);
8188edf6225SMatthew G. Knepley }
8198edf6225SMatthew G. Knepley 
8208edf6225SMatthew G. Knepley /*@
821bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
822bc4ae4beSMatthew G. Knepley 
823bc4ae4beSMatthew G. Knepley   Not collective
824bc4ae4beSMatthew G. Knepley 
825bc4ae4beSMatthew G. Knepley   Input Parameter:
826bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
827bc4ae4beSMatthew G. Knepley 
828bc4ae4beSMatthew G. Knepley   Output Parameter:
829bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
830bc4ae4beSMatthew G. Knepley 
831bc4ae4beSMatthew G. Knepley   Level: beginner
832bc4ae4beSMatthew G. Knepley 
833db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()`
834bc4ae4beSMatthew G. Knepley @*/
835*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
836*d71ae5a4SJacob Faibussowitsch {
8372764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8382764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8399566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
840dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dim, 2);
8412764a2aaSMatthew G. Knepley   *dim = prob->totDim;
8422764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8432764a2aaSMatthew G. Knepley }
8442764a2aaSMatthew G. Knepley 
845bc4ae4beSMatthew G. Knepley /*@
846bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
847bc4ae4beSMatthew G. Knepley 
848bc4ae4beSMatthew G. Knepley   Not collective
849bc4ae4beSMatthew G. Knepley 
850bc4ae4beSMatthew G. Knepley   Input Parameter:
851bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
852bc4ae4beSMatthew G. Knepley 
853bc4ae4beSMatthew G. Knepley   Output Parameter:
854bc4ae4beSMatthew G. Knepley . dim - The total number of components
855bc4ae4beSMatthew G. Knepley 
856bc4ae4beSMatthew G. Knepley   Level: beginner
857bc4ae4beSMatthew G. Knepley 
858db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()`
859bc4ae4beSMatthew G. Knepley @*/
860*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
861*d71ae5a4SJacob Faibussowitsch {
8622764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8632764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8649566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
865dadcf809SJacob Faibussowitsch   PetscValidIntPointer(Nc, 2);
8662764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
8672764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8682764a2aaSMatthew G. Knepley }
8692764a2aaSMatthew G. Knepley 
870bc4ae4beSMatthew G. Knepley /*@
871bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
872bc4ae4beSMatthew G. Knepley 
873bc4ae4beSMatthew G. Knepley   Not collective
874bc4ae4beSMatthew G. Knepley 
875bc4ae4beSMatthew G. Knepley   Input Parameters:
876bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
877bc4ae4beSMatthew G. Knepley - f - The field number
878bc4ae4beSMatthew G. Knepley 
879bc4ae4beSMatthew G. Knepley   Output Parameter:
880bc4ae4beSMatthew G. Knepley . disc - The discretization object
881bc4ae4beSMatthew G. Knepley 
882bc4ae4beSMatthew G. Knepley   Level: beginner
883bc4ae4beSMatthew G. Knepley 
884db781477SPatrick Sanan .seealso: `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
885bc4ae4beSMatthew G. Knepley @*/
886*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
887*d71ae5a4SJacob Faibussowitsch {
8886528b96dSMatthew G. Knepley   PetscFunctionBeginHot;
8892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8902764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
89163a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= prob->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, prob->Nf);
8922764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
8932764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8942764a2aaSMatthew G. Knepley }
8952764a2aaSMatthew G. Knepley 
896bc4ae4beSMatthew G. Knepley /*@
897bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
898bc4ae4beSMatthew G. Knepley 
899bc4ae4beSMatthew G. Knepley   Not collective
900bc4ae4beSMatthew G. Knepley 
901bc4ae4beSMatthew G. Knepley   Input Parameters:
902bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
903bc4ae4beSMatthew G. Knepley . f - The field number
904bc4ae4beSMatthew G. Knepley - disc - The discretization object
905bc4ae4beSMatthew G. Knepley 
906bc4ae4beSMatthew G. Knepley   Level: beginner
907bc4ae4beSMatthew G. Knepley 
908db781477SPatrick Sanan .seealso: `PetscDSGetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
909bc4ae4beSMatthew G. Knepley @*/
910*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
911*d71ae5a4SJacob Faibussowitsch {
9122764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9132764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
914665f567fSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
91563a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
9169566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(prob, f + 1));
9179566063dSJacob Faibussowitsch   PetscCall(PetscObjectDereference(prob->disc[f]));
9182764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
9199566063dSJacob Faibussowitsch   PetscCall(PetscObjectReference(disc));
920665f567fSMatthew G. Knepley   if (disc) {
921249df284SMatthew G. Knepley     PetscClassId id;
922249df284SMatthew G. Knepley 
9239566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetClassId(disc, &id));
9241cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
9259566063dSJacob Faibussowitsch       PetscCall(PetscDSSetImplicit(prob, f, PETSC_TRUE));
9261cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
9279566063dSJacob Faibussowitsch       PetscCall(PetscDSSetImplicit(prob, f, PETSC_FALSE));
928a6cbbb48SMatthew G. Knepley     }
9299566063dSJacob Faibussowitsch     PetscCall(PetscDSSetJetDegree(prob, f, 1));
930249df284SMatthew G. Knepley   }
9312764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9322764a2aaSMatthew G. Knepley }
9332764a2aaSMatthew G. Knepley 
934bc4ae4beSMatthew G. Knepley /*@
9356528b96dSMatthew G. Knepley   PetscDSGetWeakForm - Returns the weak form object
9366528b96dSMatthew G. Knepley 
9376528b96dSMatthew G. Knepley   Not collective
9386528b96dSMatthew G. Knepley 
9396528b96dSMatthew G. Knepley   Input Parameter:
9406528b96dSMatthew G. Knepley . ds - The PetscDS object
9416528b96dSMatthew G. Knepley 
9426528b96dSMatthew G. Knepley   Output Parameter:
9436528b96dSMatthew G. Knepley . wf - The weak form object
9446528b96dSMatthew G. Knepley 
9456528b96dSMatthew G. Knepley   Level: beginner
9466528b96dSMatthew G. Knepley 
947db781477SPatrick Sanan .seealso: `PetscDSSetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
9486528b96dSMatthew G. Knepley @*/
949*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf)
950*d71ae5a4SJacob Faibussowitsch {
9516528b96dSMatthew G. Knepley   PetscFunctionBegin;
9526528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
9536528b96dSMatthew G. Knepley   PetscValidPointer(wf, 2);
9546528b96dSMatthew G. Knepley   *wf = ds->wf;
9556528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9566528b96dSMatthew G. Knepley }
9576528b96dSMatthew G. Knepley 
9586528b96dSMatthew G. Knepley /*@
9596528b96dSMatthew G. Knepley   PetscDSSetWeakForm - Sets the weak form object
9606528b96dSMatthew G. Knepley 
9616528b96dSMatthew G. Knepley   Not collective
9626528b96dSMatthew G. Knepley 
9636528b96dSMatthew G. Knepley   Input Parameters:
9646528b96dSMatthew G. Knepley + ds - The PetscDS object
9656528b96dSMatthew G. Knepley - wf - The weak form object
9666528b96dSMatthew G. Knepley 
9676528b96dSMatthew G. Knepley   Level: beginner
9686528b96dSMatthew G. Knepley 
969db781477SPatrick Sanan .seealso: `PetscDSGetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
9706528b96dSMatthew G. Knepley @*/
971*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf)
972*d71ae5a4SJacob Faibussowitsch {
9736528b96dSMatthew G. Knepley   PetscFunctionBegin;
9746528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
9756528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2);
9769566063dSJacob Faibussowitsch   PetscCall(PetscObjectDereference((PetscObject)ds->wf));
9776528b96dSMatthew G. Knepley   ds->wf = wf;
9789566063dSJacob Faibussowitsch   PetscCall(PetscObjectReference((PetscObject)wf));
9799566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(wf, ds->Nf));
9806528b96dSMatthew G. Knepley   PetscFunctionReturn(0);
9816528b96dSMatthew G. Knepley }
9826528b96dSMatthew G. Knepley 
9836528b96dSMatthew G. Knepley /*@
984bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
985bc4ae4beSMatthew G. Knepley 
986bc4ae4beSMatthew G. Knepley   Not collective
987bc4ae4beSMatthew G. Knepley 
988bc4ae4beSMatthew G. Knepley   Input Parameters:
989bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
990bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
991bc4ae4beSMatthew G. Knepley 
992bc4ae4beSMatthew G. Knepley   Level: beginner
993bc4ae4beSMatthew G. Knepley 
994db781477SPatrick Sanan .seealso: `PetscDSGetDiscretization()`, `PetscDSSetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
995bc4ae4beSMatthew G. Knepley @*/
996*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
997*d71ae5a4SJacob Faibussowitsch {
9982764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9999566063dSJacob Faibussowitsch   PetscCall(PetscDSSetDiscretization(prob, prob->Nf, disc));
10002764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10012764a2aaSMatthew G. Knepley }
10022764a2aaSMatthew G. Knepley 
1003249df284SMatthew G. Knepley /*@
1004083401c6SMatthew G. Knepley   PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS
1005083401c6SMatthew G. Knepley 
1006083401c6SMatthew G. Knepley   Not collective
1007083401c6SMatthew G. Knepley 
1008083401c6SMatthew G. Knepley   Input Parameter:
1009083401c6SMatthew G. Knepley . prob - The PetscDS object
1010083401c6SMatthew G. Knepley 
1011083401c6SMatthew G. Knepley   Output Parameter:
1012083401c6SMatthew G. Knepley . q - The quadrature object
1013083401c6SMatthew G. Knepley 
1014083401c6SMatthew G. Knepley Level: intermediate
1015083401c6SMatthew G. Knepley 
1016db781477SPatrick Sanan .seealso: `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1017083401c6SMatthew G. Knepley @*/
1018*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q)
1019*d71ae5a4SJacob Faibussowitsch {
1020083401c6SMatthew G. Knepley   PetscObject  obj;
1021083401c6SMatthew G. Knepley   PetscClassId id;
1022083401c6SMatthew G. Knepley 
1023083401c6SMatthew G. Knepley   PetscFunctionBegin;
1024083401c6SMatthew G. Knepley   *q = NULL;
1025083401c6SMatthew G. Knepley   if (!prob->Nf) PetscFunctionReturn(0);
10269566063dSJacob Faibussowitsch   PetscCall(PetscDSGetDiscretization(prob, 0, &obj));
10279566063dSJacob Faibussowitsch   PetscCall(PetscObjectGetClassId(obj, &id));
10289566063dSJacob Faibussowitsch   if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetQuadrature((PetscFE)obj, q));
10299566063dSJacob Faibussowitsch   else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetQuadrature((PetscFV)obj, q));
103098921bdaSJacob Faibussowitsch   else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
1031083401c6SMatthew G. Knepley   PetscFunctionReturn(0);
1032083401c6SMatthew G. Knepley }
1033083401c6SMatthew G. Knepley 
1034083401c6SMatthew G. Knepley /*@
1035249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
1036249df284SMatthew G. Knepley 
1037249df284SMatthew G. Knepley   Not collective
1038249df284SMatthew G. Knepley 
1039249df284SMatthew G. Knepley   Input Parameters:
1040249df284SMatthew G. Knepley + prob - The PetscDS object
1041249df284SMatthew G. Knepley - f - The field number
1042249df284SMatthew G. Knepley 
1043249df284SMatthew G. Knepley   Output Parameter:
1044249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
1045249df284SMatthew G. Knepley 
1046249df284SMatthew G. Knepley   Level: developer
1047249df284SMatthew G. Knepley 
1048db781477SPatrick Sanan .seealso: `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1049249df284SMatthew G. Knepley @*/
1050*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
1051*d71ae5a4SJacob Faibussowitsch {
1052249df284SMatthew G. Knepley   PetscFunctionBegin;
1053249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1054dadcf809SJacob Faibussowitsch   PetscValidBoolPointer(implicit, 3);
105563a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= prob->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, prob->Nf);
1056249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
1057249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1058249df284SMatthew G. Knepley }
1059249df284SMatthew G. Knepley 
1060249df284SMatthew G. Knepley /*@
1061249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
1062249df284SMatthew G. Knepley 
1063249df284SMatthew G. Knepley   Not collective
1064249df284SMatthew G. Knepley 
1065249df284SMatthew G. Knepley   Input Parameters:
1066249df284SMatthew G. Knepley + prob - The PetscDS object
1067249df284SMatthew G. Knepley . f - The field number
1068249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
1069249df284SMatthew G. Knepley 
1070249df284SMatthew G. Knepley   Level: developer
1071249df284SMatthew G. Knepley 
1072db781477SPatrick Sanan .seealso: `PetscDSGetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1073249df284SMatthew G. Knepley @*/
1074*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
1075*d71ae5a4SJacob Faibussowitsch {
1076249df284SMatthew G. Knepley   PetscFunctionBegin;
1077249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
107863a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= prob->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, prob->Nf);
1079249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
1080249df284SMatthew G. Knepley   PetscFunctionReturn(0);
1081249df284SMatthew G. Knepley }
1082249df284SMatthew G. Knepley 
1083f9244615SMatthew G. Knepley /*@
1084f9244615SMatthew G. Knepley   PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1085f9244615SMatthew G. Knepley 
1086f9244615SMatthew G. Knepley   Not collective
1087f9244615SMatthew G. Knepley 
1088f9244615SMatthew G. Knepley   Input Parameters:
1089f9244615SMatthew G. Knepley + ds - The PetscDS object
1090f9244615SMatthew G. Knepley - f  - The field number
1091f9244615SMatthew G. Knepley 
1092f9244615SMatthew G. Knepley   Output Parameter:
1093f9244615SMatthew G. Knepley . k  - The highest derivative we need to tabulate
1094f9244615SMatthew G. Knepley 
1095f9244615SMatthew G. Knepley   Level: developer
1096f9244615SMatthew G. Knepley 
1097db781477SPatrick Sanan .seealso: `PetscDSSetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1098f9244615SMatthew G. Knepley @*/
1099*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k)
1100*d71ae5a4SJacob Faibussowitsch {
1101f9244615SMatthew G. Knepley   PetscFunctionBegin;
1102f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1103dadcf809SJacob Faibussowitsch   PetscValidIntPointer(k, 3);
110463a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
1105f9244615SMatthew G. Knepley   *k = ds->jetDegree[f];
1106f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1107f9244615SMatthew G. Knepley }
1108f9244615SMatthew G. Knepley 
1109f9244615SMatthew G. Knepley /*@
1110f9244615SMatthew G. Knepley   PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1111f9244615SMatthew G. Knepley 
1112f9244615SMatthew G. Knepley   Not collective
1113f9244615SMatthew G. Knepley 
1114f9244615SMatthew G. Knepley   Input Parameters:
1115f9244615SMatthew G. Knepley + ds - The PetscDS object
1116f9244615SMatthew G. Knepley . f  - The field number
1117f9244615SMatthew G. Knepley - k  - The highest derivative we need to tabulate
1118f9244615SMatthew G. Knepley 
1119f9244615SMatthew G. Knepley   Level: developer
1120f9244615SMatthew G. Knepley 
1121db781477SPatrick Sanan .seealso: `PetscDSGetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1122f9244615SMatthew G. Knepley @*/
1123*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k)
1124*d71ae5a4SJacob Faibussowitsch {
1125f9244615SMatthew G. Knepley   PetscFunctionBegin;
1126f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
112763a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
1128f9244615SMatthew G. Knepley   ds->jetDegree[f] = k;
1129f9244615SMatthew G. Knepley   PetscFunctionReturn(0);
1130f9244615SMatthew G. Knepley }
1131f9244615SMatthew G. Knepley 
1132*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetObjective(PetscDS ds, PetscInt f, void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
1133*d71ae5a4SJacob Faibussowitsch {
11346528b96dSMatthew G. Knepley   PetscPointFunc *tmp;
11356528b96dSMatthew G. Knepley   PetscInt        n;
11366528b96dSMatthew G. Knepley 
11372764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11386528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11396528b96dSMatthew G. Knepley   PetscValidPointer(obj, 3);
114063a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
11419566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetObjective(ds->wf, NULL, 0, f, 0, &n, &tmp));
11426528b96dSMatthew G. Knepley   *obj = tmp ? tmp[0] : NULL;
11432764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11442764a2aaSMatthew G. Knepley }
11452764a2aaSMatthew G. Knepley 
1146*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetObjective(PetscDS ds, PetscInt f, void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
1147*d71ae5a4SJacob Faibussowitsch {
11482764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11496528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11506528b96dSMatthew G. Knepley   if (obj) PetscValidFunction(obj, 3);
115163a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
11529566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, 0, obj));
11532764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11542764a2aaSMatthew G. Knepley }
11552764a2aaSMatthew G. Knepley 
1156194d53e6SMatthew G. Knepley /*@C
1157194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1158194d53e6SMatthew G. Knepley 
1159194d53e6SMatthew G. Knepley   Not collective
1160194d53e6SMatthew G. Knepley 
1161194d53e6SMatthew G. Knepley   Input Parameters:
11626528b96dSMatthew G. Knepley + ds - The PetscDS
1163194d53e6SMatthew G. Knepley - f  - The test field number
1164194d53e6SMatthew G. Knepley 
1165194d53e6SMatthew G. Knepley   Output Parameters:
1166194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1167194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1168194d53e6SMatthew G. Knepley 
1169194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1170194d53e6SMatthew G. Knepley 
1171194d53e6SMatthew 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)
1172194d53e6SMatthew G. Knepley 
1173194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1174194d53e6SMatthew G. Knepley 
117530b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1176194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1177194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1179194d53e6SMatthew G. Knepley 
1180194d53e6SMatthew G. Knepley + dim - the spatial dimension
1181194d53e6SMatthew G. Knepley . Nf - the number of fields
1182194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1183194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1184194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1185194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1186194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1187194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1188194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1189194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1190194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1191194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1192194d53e6SMatthew G. Knepley . t - current time
1193194d53e6SMatthew G. Knepley . x - coordinates of the current point
119497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
119597b6e6e8SMatthew G. Knepley . constants - constant parameters
1196194d53e6SMatthew G. Knepley - f0 - output values at the current point
1197194d53e6SMatthew G. Knepley 
1198194d53e6SMatthew G. Knepley   Level: intermediate
1199194d53e6SMatthew G. Knepley 
1200db781477SPatrick Sanan .seealso: `PetscDSSetResidual()`
1201194d53e6SMatthew G. Knepley @*/
1202*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetResidual(PetscDS ds, PetscInt f, void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
1203*d71ae5a4SJacob Faibussowitsch {
12046528b96dSMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
12056528b96dSMatthew G. Knepley   PetscInt        n0, n1;
12066528b96dSMatthew G. Knepley 
12072764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12086528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
120963a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
12109566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1));
12116528b96dSMatthew G. Knepley   *f0 = tmp0 ? tmp0[0] : NULL;
12126528b96dSMatthew G. Knepley   *f1 = tmp1 ? tmp1[0] : NULL;
12132764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12142764a2aaSMatthew G. Knepley }
12152764a2aaSMatthew G. Knepley 
1216194d53e6SMatthew G. Knepley /*@C
1217194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1218194d53e6SMatthew G. Knepley 
1219194d53e6SMatthew G. Knepley   Not collective
1220194d53e6SMatthew G. Knepley 
1221194d53e6SMatthew G. Knepley   Input Parameters:
12226528b96dSMatthew G. Knepley + ds - The PetscDS
1223194d53e6SMatthew G. Knepley . f  - The test field number
1224194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1225194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1226194d53e6SMatthew G. Knepley 
1227194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1228194d53e6SMatthew G. Knepley 
1229194d53e6SMatthew 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)
1230194d53e6SMatthew G. Knepley 
1231194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1232194d53e6SMatthew G. Knepley 
123330b9ff8bSMatthew G. Knepley $ f0(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[],
123630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1237194d53e6SMatthew G. Knepley 
1238194d53e6SMatthew G. Knepley + dim - the spatial dimension
1239194d53e6SMatthew G. Knepley . Nf - the number of fields
1240194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1241194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1242194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1243194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1244194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1245194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1246194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1247194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1248194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1249194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1250194d53e6SMatthew G. Knepley . t - current time
1251194d53e6SMatthew G. Knepley . x - coordinates of the current point
125297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
125397b6e6e8SMatthew G. Knepley . constants - constant parameters
1254194d53e6SMatthew G. Knepley - f0 - output values at the current point
1255194d53e6SMatthew G. Knepley 
1256194d53e6SMatthew G. Knepley   Level: intermediate
1257194d53e6SMatthew G. Knepley 
1258db781477SPatrick Sanan .seealso: `PetscDSGetResidual()`
1259194d53e6SMatthew G. Knepley @*/
1260*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetResidual(PetscDS ds, PetscInt f, void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
1261*d71ae5a4SJacob Faibussowitsch {
12622764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12636528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1264f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1265f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
126663a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
12679566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1));
12682764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12692764a2aaSMatthew G. Knepley }
12702764a2aaSMatthew G. Knepley 
12713e75805dSMatthew G. Knepley /*@C
1272cb36c0f9SMatthew G. Knepley   PetscDSGetRHSResidual - Get the pointwise RHS residual function for explicit timestepping for a given test field
1273cb36c0f9SMatthew G. Knepley 
1274cb36c0f9SMatthew G. Knepley   Not collective
1275cb36c0f9SMatthew G. Knepley 
1276cb36c0f9SMatthew G. Knepley   Input Parameters:
1277cb36c0f9SMatthew G. Knepley + ds - The PetscDS
1278cb36c0f9SMatthew G. Knepley - f  - The test field number
1279cb36c0f9SMatthew G. Knepley 
1280cb36c0f9SMatthew G. Knepley   Output Parameters:
1281cb36c0f9SMatthew G. Knepley + f0 - integrand for the test function term
1282cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term
1283cb36c0f9SMatthew G. Knepley 
1284cb36c0f9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1285cb36c0f9SMatthew G. Knepley 
1286cb36c0f9SMatthew 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)
1287cb36c0f9SMatthew G. Knepley 
1288cb36c0f9SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1289cb36c0f9SMatthew G. Knepley 
1290cb36c0f9SMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1291cb36c0f9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1292cb36c0f9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1293cb36c0f9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1294cb36c0f9SMatthew G. Knepley 
1295cb36c0f9SMatthew G. Knepley + dim - the spatial dimension
1296cb36c0f9SMatthew G. Knepley . Nf - the number of fields
1297cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1298cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1299cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point
1300cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1301cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1302cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1303cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1304cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1305cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1306cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1307cb36c0f9SMatthew G. Knepley . t - current time
1308cb36c0f9SMatthew G. Knepley . x - coordinates of the current point
1309cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters
1310cb36c0f9SMatthew G. Knepley . constants - constant parameters
1311cb36c0f9SMatthew G. Knepley - f0 - output values at the current point
1312cb36c0f9SMatthew G. Knepley 
1313cb36c0f9SMatthew G. Knepley   Level: intermediate
1314cb36c0f9SMatthew G. Knepley 
1315db781477SPatrick Sanan .seealso: `PetscDSSetRHSResidual()`
1316cb36c0f9SMatthew G. Knepley @*/
1317*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetRHSResidual(PetscDS ds, PetscInt f, void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
1318*d71ae5a4SJacob Faibussowitsch {
1319cb36c0f9SMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
1320cb36c0f9SMatthew G. Knepley   PetscInt        n0, n1;
1321cb36c0f9SMatthew G. Knepley 
1322cb36c0f9SMatthew G. Knepley   PetscFunctionBegin;
1323cb36c0f9SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
132463a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
13259566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 100, &n0, &tmp0, &n1, &tmp1));
1326cb36c0f9SMatthew G. Knepley   *f0 = tmp0 ? tmp0[0] : NULL;
1327cb36c0f9SMatthew G. Knepley   *f1 = tmp1 ? tmp1[0] : NULL;
1328cb36c0f9SMatthew G. Knepley   PetscFunctionReturn(0);
1329cb36c0f9SMatthew G. Knepley }
1330cb36c0f9SMatthew G. Knepley 
1331cb36c0f9SMatthew G. Knepley /*@C
1332cb36c0f9SMatthew G. Knepley   PetscDSSetRHSResidual - Set the pointwise residual function for explicit timestepping for a given test field
1333cb36c0f9SMatthew G. Knepley 
1334cb36c0f9SMatthew G. Knepley   Not collective
1335cb36c0f9SMatthew G. Knepley 
1336cb36c0f9SMatthew G. Knepley   Input Parameters:
1337cb36c0f9SMatthew G. Knepley + ds - The PetscDS
1338cb36c0f9SMatthew G. Knepley . f  - The test field number
1339cb36c0f9SMatthew G. Knepley . f0 - integrand for the test function term
1340cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term
1341cb36c0f9SMatthew G. Knepley 
1342cb36c0f9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1343cb36c0f9SMatthew G. Knepley 
1344cb36c0f9SMatthew 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)
1345cb36c0f9SMatthew G. Knepley 
1346cb36c0f9SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1347cb36c0f9SMatthew G. Knepley 
1348cb36c0f9SMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1349cb36c0f9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1350cb36c0f9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1351cb36c0f9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1352cb36c0f9SMatthew G. Knepley 
1353cb36c0f9SMatthew G. Knepley + dim - the spatial dimension
1354cb36c0f9SMatthew G. Knepley . Nf - the number of fields
1355cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1356cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1357cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point
1358cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1359cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1360cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1361cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1362cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1363cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1364cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1365cb36c0f9SMatthew G. Knepley . t - current time
1366cb36c0f9SMatthew G. Knepley . x - coordinates of the current point
1367cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters
1368cb36c0f9SMatthew G. Knepley . constants - constant parameters
1369cb36c0f9SMatthew G. Knepley - f0 - output values at the current point
1370cb36c0f9SMatthew G. Knepley 
1371cb36c0f9SMatthew G. Knepley   Level: intermediate
1372cb36c0f9SMatthew G. Knepley 
1373db781477SPatrick Sanan .seealso: `PetscDSGetResidual()`
1374cb36c0f9SMatthew G. Knepley @*/
1375*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetRHSResidual(PetscDS ds, PetscInt f, void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
1376*d71ae5a4SJacob Faibussowitsch {
1377cb36c0f9SMatthew G. Knepley   PetscFunctionBegin;
1378cb36c0f9SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1379cb36c0f9SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1380cb36c0f9SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
138163a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
13829566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 100, 0, f0, 0, f1));
1383cb36c0f9SMatthew G. Knepley   PetscFunctionReturn(0);
1384cb36c0f9SMatthew G. Knepley }
1385cb36c0f9SMatthew G. Knepley 
1386cb36c0f9SMatthew G. Knepley /*@C
13873e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
13883e75805dSMatthew G. Knepley 
13893e75805dSMatthew G. Knepley   Not collective
13903e75805dSMatthew G. Knepley 
13913e75805dSMatthew G. Knepley   Input Parameter:
13923e75805dSMatthew G. Knepley . prob - The PetscDS
13933e75805dSMatthew G. Knepley 
13943e75805dSMatthew G. Knepley   Output Parameter:
13953e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
13963e75805dSMatthew G. Knepley 
13973e75805dSMatthew G. Knepley   Level: intermediate
13983e75805dSMatthew G. Knepley 
1399db781477SPatrick Sanan .seealso: `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
14003e75805dSMatthew G. Knepley @*/
1401*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac)
1402*d71ae5a4SJacob Faibussowitsch {
14033e75805dSMatthew G. Knepley   PetscFunctionBegin;
14046528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
14059566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasJacobian(ds->wf, hasJac));
14063e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
14073e75805dSMatthew G. Knepley }
14083e75805dSMatthew G. Knepley 
1409194d53e6SMatthew G. Knepley /*@C
1410194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1411194d53e6SMatthew G. Knepley 
1412194d53e6SMatthew G. Knepley   Not collective
1413194d53e6SMatthew G. Knepley 
1414194d53e6SMatthew G. Knepley   Input Parameters:
14156528b96dSMatthew G. Knepley + ds - The PetscDS
1416194d53e6SMatthew G. Knepley . f  - The test field number
1417194d53e6SMatthew G. Knepley - g  - The field number
1418194d53e6SMatthew G. Knepley 
1419194d53e6SMatthew G. Knepley   Output Parameters:
1420194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1421194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1422194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1423194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1424194d53e6SMatthew G. Knepley 
1425194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1426194d53e6SMatthew G. Knepley 
1427194d53e6SMatthew 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
1428194d53e6SMatthew G. Knepley 
1429194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1430194d53e6SMatthew G. Knepley 
143130b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1432194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1433194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
143430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1435194d53e6SMatthew G. Knepley 
1436194d53e6SMatthew G. Knepley + dim - the spatial dimension
1437194d53e6SMatthew G. Knepley . Nf - the number of fields
1438194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1439194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1440194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1441194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1442194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1443194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1444194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1445194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1446194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1447194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1448194d53e6SMatthew G. Knepley . t - current time
14492aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1450194d53e6SMatthew G. Knepley . x - coordinates of the current point
145197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
145297b6e6e8SMatthew G. Knepley . constants - constant parameters
1453194d53e6SMatthew G. Knepley - g0 - output values at the current point
1454194d53e6SMatthew G. Knepley 
1455194d53e6SMatthew G. Knepley   Level: intermediate
1456194d53e6SMatthew G. Knepley 
1457db781477SPatrick Sanan .seealso: `PetscDSSetJacobian()`
1458194d53e6SMatthew G. Knepley @*/
1459*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetJacobian(PetscDS ds, PetscInt f, PetscInt g, void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1460*d71ae5a4SJacob Faibussowitsch {
14616528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
14626528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
14636528b96dSMatthew G. Knepley 
14642764a2aaSMatthew G. Knepley   PetscFunctionBegin;
14656528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
146663a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
146763a3b9bcSJacob Faibussowitsch   PetscCheck(!(g < 0) && !(g >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", g, ds->Nf);
14689566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
14696528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
14706528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
14716528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
14726528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
14732764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
14742764a2aaSMatthew G. Knepley }
14752764a2aaSMatthew G. Knepley 
1476194d53e6SMatthew G. Knepley /*@C
1477194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1478194d53e6SMatthew G. Knepley 
1479194d53e6SMatthew G. Knepley   Not collective
1480194d53e6SMatthew G. Knepley 
1481194d53e6SMatthew G. Knepley   Input Parameters:
14826528b96dSMatthew G. Knepley + ds - The PetscDS
1483194d53e6SMatthew G. Knepley . f  - The test field number
1484194d53e6SMatthew G. Knepley . g  - The field number
1485194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1486194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1487194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1488194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1489194d53e6SMatthew G. Knepley 
1490194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1491194d53e6SMatthew G. Knepley 
1492194d53e6SMatthew 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
1493194d53e6SMatthew G. Knepley 
1494194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1495194d53e6SMatthew G. Knepley 
149630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1497194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1498194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
149930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1500194d53e6SMatthew G. Knepley 
1501194d53e6SMatthew G. Knepley + dim - the spatial dimension
1502194d53e6SMatthew G. Knepley . Nf - the number of fields
1503194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1504194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1505194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1506194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1507194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1508194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1509194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1510194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1511194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1512194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1513194d53e6SMatthew G. Knepley . t - current time
15142aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1515194d53e6SMatthew G. Knepley . x - coordinates of the current point
151697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
151797b6e6e8SMatthew G. Knepley . constants - constant parameters
1518194d53e6SMatthew G. Knepley - g0 - output values at the current point
1519194d53e6SMatthew G. Knepley 
1520194d53e6SMatthew G. Knepley   Level: intermediate
1521194d53e6SMatthew G. Knepley 
1522db781477SPatrick Sanan .seealso: `PetscDSGetJacobian()`
1523194d53e6SMatthew G. Knepley @*/
1524*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetJacobian(PetscDS ds, PetscInt f, PetscInt g, void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1525*d71ae5a4SJacob Faibussowitsch {
15262764a2aaSMatthew G. Knepley   PetscFunctionBegin;
15276528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
15282764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
15292764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
15302764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
15312764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
153263a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
153363a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
15349566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
15352764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
15362764a2aaSMatthew G. Knepley }
15372764a2aaSMatthew G. Knepley 
1538475e0ac9SMatthew G. Knepley /*@C
153955c1f793SMatthew G. Knepley   PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner
154055c1f793SMatthew G. Knepley 
154155c1f793SMatthew G. Knepley   Not collective
154255c1f793SMatthew G. Knepley 
154355c1f793SMatthew G. Knepley   Input Parameters:
154455c1f793SMatthew G. Knepley + prob - The PetscDS
154555c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
154655c1f793SMatthew G. Knepley 
154755c1f793SMatthew G. Knepley   Level: intermediate
154855c1f793SMatthew G. Knepley 
1549db781477SPatrick Sanan .seealso: `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
155055c1f793SMatthew G. Knepley @*/
1551*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
1552*d71ae5a4SJacob Faibussowitsch {
155355c1f793SMatthew G. Knepley   PetscFunctionBegin;
155455c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
155555c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
155655c1f793SMatthew G. Knepley   PetscFunctionReturn(0);
155755c1f793SMatthew G. Knepley }
155855c1f793SMatthew G. Knepley 
155955c1f793SMatthew G. Knepley /*@C
1560475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1561475e0ac9SMatthew G. Knepley 
1562475e0ac9SMatthew G. Knepley   Not collective
1563475e0ac9SMatthew G. Knepley 
1564475e0ac9SMatthew G. Knepley   Input Parameter:
1565475e0ac9SMatthew G. Knepley . prob - The PetscDS
1566475e0ac9SMatthew G. Knepley 
1567475e0ac9SMatthew G. Knepley   Output Parameter:
1568475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1569475e0ac9SMatthew G. Knepley 
1570475e0ac9SMatthew G. Knepley   Level: intermediate
1571475e0ac9SMatthew G. Knepley 
1572db781477SPatrick Sanan .seealso: `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
1573475e0ac9SMatthew G. Knepley @*/
1574*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre)
1575*d71ae5a4SJacob Faibussowitsch {
1576475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
15776528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1578475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
15796528b96dSMatthew G. Knepley   if (!ds->useJacPre) PetscFunctionReturn(0);
15809566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre));
1581475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1582475e0ac9SMatthew G. Knepley }
1583475e0ac9SMatthew G. Knepley 
1584475e0ac9SMatthew G. Knepley /*@C
1585475e0ac9SMatthew 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.
1586475e0ac9SMatthew G. Knepley 
1587475e0ac9SMatthew G. Knepley   Not collective
1588475e0ac9SMatthew G. Knepley 
1589475e0ac9SMatthew G. Knepley   Input Parameters:
15906528b96dSMatthew G. Knepley + ds - The PetscDS
1591475e0ac9SMatthew G. Knepley . f  - The test field number
1592475e0ac9SMatthew G. Knepley - g  - The field number
1593475e0ac9SMatthew G. Knepley 
1594475e0ac9SMatthew G. Knepley   Output Parameters:
1595475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1596475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1597475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1598475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1599475e0ac9SMatthew G. Knepley 
1600475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1601475e0ac9SMatthew G. Knepley 
1602475e0ac9SMatthew 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
1603475e0ac9SMatthew G. Knepley 
1604475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1605475e0ac9SMatthew G. Knepley 
1606475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1607475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1608475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1609475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1610475e0ac9SMatthew G. Knepley 
1611475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1612475e0ac9SMatthew G. Knepley . Nf - the number of fields
1613475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1614475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1615475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1616475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1617475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1618475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1619475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1620475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1621475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1622475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1623475e0ac9SMatthew G. Knepley . t - current time
1624475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1625475e0ac9SMatthew G. Knepley . x - coordinates of the current point
162697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
162797b6e6e8SMatthew G. Knepley . constants - constant parameters
1628475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1629475e0ac9SMatthew G. Knepley 
1630475e0ac9SMatthew G. Knepley   Level: intermediate
1631475e0ac9SMatthew G. Knepley 
1632db781477SPatrick Sanan .seealso: `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
1633475e0ac9SMatthew G. Knepley @*/
1634*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1635*d71ae5a4SJacob Faibussowitsch {
16366528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
16376528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
16386528b96dSMatthew G. Knepley 
1639475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
16406528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
164163a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
164263a3b9bcSJacob Faibussowitsch   PetscCheck(!(g < 0) && !(g >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", g, ds->Nf);
16439566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
16446528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
16456528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
16466528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
16476528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
1648475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1649475e0ac9SMatthew G. Knepley }
1650475e0ac9SMatthew G. Knepley 
1651475e0ac9SMatthew G. Knepley /*@C
1652475e0ac9SMatthew 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.
1653475e0ac9SMatthew G. Knepley 
1654475e0ac9SMatthew G. Knepley   Not collective
1655475e0ac9SMatthew G. Knepley 
1656475e0ac9SMatthew G. Knepley   Input Parameters:
16576528b96dSMatthew G. Knepley + ds - The PetscDS
1658475e0ac9SMatthew G. Knepley . f  - The test field number
1659475e0ac9SMatthew G. Knepley . g  - The field number
1660475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1661475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1662475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1663475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1664475e0ac9SMatthew G. Knepley 
1665475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1666475e0ac9SMatthew G. Knepley 
1667475e0ac9SMatthew 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
1668475e0ac9SMatthew G. Knepley 
1669475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1670475e0ac9SMatthew G. Knepley 
1671475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1672475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1673475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1674475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1675475e0ac9SMatthew G. Knepley 
1676475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1677475e0ac9SMatthew G. Knepley . Nf - the number of fields
1678475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1679475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1680475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1681475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1682475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1683475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1684475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1685475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1686475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1687475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1688475e0ac9SMatthew G. Knepley . t - current time
1689475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1690475e0ac9SMatthew G. Knepley . x - coordinates of the current point
169197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
169297b6e6e8SMatthew G. Knepley . constants - constant parameters
1693475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1694475e0ac9SMatthew G. Knepley 
1695475e0ac9SMatthew G. Knepley   Level: intermediate
1696475e0ac9SMatthew G. Knepley 
1697db781477SPatrick Sanan .seealso: `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobian()`
1698475e0ac9SMatthew G. Knepley @*/
1699*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1700*d71ae5a4SJacob Faibussowitsch {
1701475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
17026528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1703475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1704475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1705475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1706475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
170763a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
170863a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
17099566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
1710475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1711475e0ac9SMatthew G. Knepley }
1712475e0ac9SMatthew G. Knepley 
1713b7e05686SMatthew G. Knepley /*@C
1714b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1715b7e05686SMatthew G. Knepley 
1716b7e05686SMatthew G. Knepley   Not collective
1717b7e05686SMatthew G. Knepley 
1718b7e05686SMatthew G. Knepley   Input Parameter:
17196528b96dSMatthew G. Knepley . ds - The PetscDS
1720b7e05686SMatthew G. Knepley 
1721b7e05686SMatthew G. Knepley   Output Parameter:
1722b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1723b7e05686SMatthew G. Knepley 
1724b7e05686SMatthew G. Knepley   Level: intermediate
1725b7e05686SMatthew G. Knepley 
1726db781477SPatrick Sanan .seealso: `PetscDSGetDynamicJacobian()`, `PetscDSSetDynamicJacobian()`, `PetscDSGetJacobian()`
1727b7e05686SMatthew G. Knepley @*/
1728*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac)
1729*d71ae5a4SJacob Faibussowitsch {
1730b7e05686SMatthew G. Knepley   PetscFunctionBegin;
17316528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
17329566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac));
1733b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1734b7e05686SMatthew G. Knepley }
1735b7e05686SMatthew G. Knepley 
1736b7e05686SMatthew G. Knepley /*@C
1737b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1738b7e05686SMatthew G. Knepley 
1739b7e05686SMatthew G. Knepley   Not collective
1740b7e05686SMatthew G. Knepley 
1741b7e05686SMatthew G. Knepley   Input Parameters:
17426528b96dSMatthew G. Knepley + ds - The PetscDS
1743b7e05686SMatthew G. Knepley . f  - The test field number
1744b7e05686SMatthew G. Knepley - g  - The field number
1745b7e05686SMatthew G. Knepley 
1746b7e05686SMatthew G. Knepley   Output Parameters:
1747b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1748b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1749b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1750b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1751b7e05686SMatthew G. Knepley 
1752b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1753b7e05686SMatthew G. Knepley 
1754b7e05686SMatthew 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
1755b7e05686SMatthew G. Knepley 
1756b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1757b7e05686SMatthew G. Knepley 
1758b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1759b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1760b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1761b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1762b7e05686SMatthew G. Knepley 
1763b7e05686SMatthew G. Knepley + dim - the spatial dimension
1764b7e05686SMatthew G. Knepley . Nf - the number of fields
1765b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1766b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1767b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1768b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1769b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1770b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1771b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1772b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1773b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1774b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1775b7e05686SMatthew G. Knepley . t - current time
1776b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1777b7e05686SMatthew G. Knepley . x - coordinates of the current point
177897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
177997b6e6e8SMatthew G. Knepley . constants - constant parameters
1780b7e05686SMatthew G. Knepley - g0 - output values at the current point
1781b7e05686SMatthew G. Knepley 
1782b7e05686SMatthew G. Knepley   Level: intermediate
1783b7e05686SMatthew G. Knepley 
1784db781477SPatrick Sanan .seealso: `PetscDSSetJacobian()`
1785b7e05686SMatthew G. Knepley @*/
1786*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g, void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1787*d71ae5a4SJacob Faibussowitsch {
17886528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
17896528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
17906528b96dSMatthew G. Knepley 
1791b7e05686SMatthew G. Knepley   PetscFunctionBegin;
17926528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
179363a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
179463a3b9bcSJacob Faibussowitsch   PetscCheck(!(g < 0) && !(g >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", g, ds->Nf);
17959566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
17966528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
17976528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
17986528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
17996528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
1800b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1801b7e05686SMatthew G. Knepley }
1802b7e05686SMatthew G. Knepley 
1803b7e05686SMatthew G. Knepley /*@C
1804b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1805b7e05686SMatthew G. Knepley 
1806b7e05686SMatthew G. Knepley   Not collective
1807b7e05686SMatthew G. Knepley 
1808b7e05686SMatthew G. Knepley   Input Parameters:
18096528b96dSMatthew G. Knepley + ds - The PetscDS
1810b7e05686SMatthew G. Knepley . f  - The test field number
1811b7e05686SMatthew G. Knepley . g  - The field number
1812b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1813b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1814b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1815b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1816b7e05686SMatthew G. Knepley 
1817b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1818b7e05686SMatthew G. Knepley 
1819b7e05686SMatthew 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
1820b7e05686SMatthew G. Knepley 
1821b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1822b7e05686SMatthew G. Knepley 
1823b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1824b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1825b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1826b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1827b7e05686SMatthew G. Knepley 
1828b7e05686SMatthew G. Knepley + dim - the spatial dimension
1829b7e05686SMatthew G. Knepley . Nf - the number of fields
1830b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1831b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1832b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1833b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1834b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1835b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1836b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1837b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1838b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1839b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1840b7e05686SMatthew G. Knepley . t - current time
1841b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1842b7e05686SMatthew G. Knepley . x - coordinates of the current point
184397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
184497b6e6e8SMatthew G. Knepley . constants - constant parameters
1845b7e05686SMatthew G. Knepley - g0 - output values at the current point
1846b7e05686SMatthew G. Knepley 
1847b7e05686SMatthew G. Knepley   Level: intermediate
1848b7e05686SMatthew G. Knepley 
1849db781477SPatrick Sanan .seealso: `PetscDSGetJacobian()`
1850b7e05686SMatthew G. Knepley @*/
1851*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g, void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1852*d71ae5a4SJacob Faibussowitsch {
1853b7e05686SMatthew G. Knepley   PetscFunctionBegin;
18546528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1855b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1856b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1857b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1858b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
185963a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
186063a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
18619566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
1862b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1863b7e05686SMatthew G. Knepley }
1864b7e05686SMatthew G. Knepley 
18650c2f2876SMatthew G. Knepley /*@C
18660c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
18670c2f2876SMatthew G. Knepley 
18680c2f2876SMatthew G. Knepley   Not collective
18690c2f2876SMatthew G. Knepley 
18704165533cSJose E. Roman   Input Parameters:
18716528b96dSMatthew G. Knepley + ds - The PetscDS object
18720c2f2876SMatthew G. Knepley - f  - The field number
18730c2f2876SMatthew G. Knepley 
18744165533cSJose E. Roman   Output Parameter:
18750c2f2876SMatthew G. Knepley . r    - Riemann solver
18760c2f2876SMatthew G. Knepley 
18770c2f2876SMatthew G. Knepley   Calling sequence for r:
18780c2f2876SMatthew G. Knepley 
18795db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
18800c2f2876SMatthew G. Knepley 
18815db36cf9SMatthew G. Knepley + dim  - The spatial dimension
18825db36cf9SMatthew G. Knepley . Nf   - The number of fields
18835db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
18840c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
18850c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
18860c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
18870c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
188897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
188997b6e6e8SMatthew G. Knepley . constants - constant parameters
18900c2f2876SMatthew G. Knepley - ctx  - optional user context
18910c2f2876SMatthew G. Knepley 
18920c2f2876SMatthew G. Knepley   Level: intermediate
18930c2f2876SMatthew G. Knepley 
1894db781477SPatrick Sanan .seealso: `PetscDSSetRiemannSolver()`
18950c2f2876SMatthew G. Knepley @*/
1896*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetRiemannSolver(PetscDS ds, PetscInt f, 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))
1897*d71ae5a4SJacob Faibussowitsch {
18986528b96dSMatthew G. Knepley   PetscRiemannFunc *tmp;
18996528b96dSMatthew G. Knepley   PetscInt          n;
19006528b96dSMatthew G. Knepley 
19010c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19026528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
19030c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
190463a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
19059566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, 0, &n, &tmp));
19066528b96dSMatthew G. Knepley   *r = tmp ? tmp[0] : NULL;
19070c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19080c2f2876SMatthew G. Knepley }
19090c2f2876SMatthew G. Knepley 
19100c2f2876SMatthew G. Knepley /*@C
19110c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
19120c2f2876SMatthew G. Knepley 
19130c2f2876SMatthew G. Knepley   Not collective
19140c2f2876SMatthew G. Knepley 
19154165533cSJose E. Roman   Input Parameters:
19166528b96dSMatthew G. Knepley + ds - The PetscDS object
19170c2f2876SMatthew G. Knepley . f  - The field number
19180c2f2876SMatthew G. Knepley - r  - Riemann solver
19190c2f2876SMatthew G. Knepley 
19200c2f2876SMatthew G. Knepley   Calling sequence for r:
19210c2f2876SMatthew G. Knepley 
19225db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
19230c2f2876SMatthew G. Knepley 
19245db36cf9SMatthew G. Knepley + dim  - The spatial dimension
19255db36cf9SMatthew G. Knepley . Nf   - The number of fields
19265db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
19270c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
19280c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
19290c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
19300c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
193197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
193297b6e6e8SMatthew G. Knepley . constants - constant parameters
19330c2f2876SMatthew G. Knepley - ctx  - optional user context
19340c2f2876SMatthew G. Knepley 
19350c2f2876SMatthew G. Knepley   Level: intermediate
19360c2f2876SMatthew G. Knepley 
1937db781477SPatrick Sanan .seealso: `PetscDSGetRiemannSolver()`
19380c2f2876SMatthew G. Knepley @*/
1939*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetRiemannSolver(PetscDS ds, PetscInt f, 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))
1940*d71ae5a4SJacob Faibussowitsch {
19410c2f2876SMatthew G. Knepley   PetscFunctionBegin;
19426528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1943de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
194463a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
19459566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, 0, r));
19460c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
19470c2f2876SMatthew G. Knepley }
19480c2f2876SMatthew G. Knepley 
194932d2bbc9SMatthew G. Knepley /*@C
195032d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
195132d2bbc9SMatthew G. Knepley 
195232d2bbc9SMatthew G. Knepley   Not collective
195332d2bbc9SMatthew G. Knepley 
195432d2bbc9SMatthew G. Knepley   Input Parameters:
19556528b96dSMatthew G. Knepley + ds - The PetscDS
195632d2bbc9SMatthew G. Knepley - f  - The field number
195732d2bbc9SMatthew G. Knepley 
1958f899ff85SJose E. Roman   Output Parameter:
1959a2b725a8SWilliam Gropp . update - update function
196032d2bbc9SMatthew G. Knepley 
196132d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
196232d2bbc9SMatthew G. Knepley 
196332d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
196432d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
196532d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
196632d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
196732d2bbc9SMatthew G. Knepley 
196832d2bbc9SMatthew G. Knepley + dim - the spatial dimension
196932d2bbc9SMatthew G. Knepley . Nf - the number of fields
197032d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
197132d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
197232d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
197332d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
197432d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
197532d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
197632d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
197732d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
197832d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
197932d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
198032d2bbc9SMatthew G. Knepley . t - current time
198132d2bbc9SMatthew G. Knepley . x - coordinates of the current point
198232d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
198332d2bbc9SMatthew G. Knepley 
198432d2bbc9SMatthew G. Knepley   Level: intermediate
198532d2bbc9SMatthew G. Knepley 
1986db781477SPatrick Sanan .seealso: `PetscDSSetUpdate()`, `PetscDSSetResidual()`
198732d2bbc9SMatthew G. Knepley @*/
1988*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetUpdate(PetscDS ds, PetscInt f, void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
1989*d71ae5a4SJacob Faibussowitsch {
199032d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
19916528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
199263a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
19939371c9d4SSatish Balay   if (update) {
19949371c9d4SSatish Balay     PetscValidPointer(update, 3);
19959371c9d4SSatish Balay     *update = ds->update[f];
19969371c9d4SSatish Balay   }
199732d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
199832d2bbc9SMatthew G. Knepley }
199932d2bbc9SMatthew G. Knepley 
200032d2bbc9SMatthew G. Knepley /*@C
20013fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
200232d2bbc9SMatthew G. Knepley 
200332d2bbc9SMatthew G. Knepley   Not collective
200432d2bbc9SMatthew G. Knepley 
200532d2bbc9SMatthew G. Knepley   Input Parameters:
20066528b96dSMatthew G. Knepley + ds     - The PetscDS
200732d2bbc9SMatthew G. Knepley . f      - The field number
200832d2bbc9SMatthew G. Knepley - update - update function
200932d2bbc9SMatthew G. Knepley 
201032d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
201132d2bbc9SMatthew G. Knepley 
201232d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
201332d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
201432d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
201532d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
201632d2bbc9SMatthew G. Knepley 
201732d2bbc9SMatthew G. Knepley + dim - the spatial dimension
201832d2bbc9SMatthew G. Knepley . Nf - the number of fields
201932d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
202032d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
202132d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
202232d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
202332d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
202432d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
202532d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
202632d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
202732d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
202832d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
202932d2bbc9SMatthew G. Knepley . t - current time
203032d2bbc9SMatthew G. Knepley . x - coordinates of the current point
203132d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
203232d2bbc9SMatthew G. Knepley 
203332d2bbc9SMatthew G. Knepley   Level: intermediate
203432d2bbc9SMatthew G. Knepley 
2035db781477SPatrick Sanan .seealso: `PetscDSGetResidual()`
203632d2bbc9SMatthew G. Knepley @*/
2037*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetUpdate(PetscDS ds, PetscInt f, void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
2038*d71ae5a4SJacob Faibussowitsch {
203932d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
20406528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
204132d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
204263a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
20439566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(ds, f + 1));
20446528b96dSMatthew G. Knepley   ds->update[f] = update;
204532d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
204632d2bbc9SMatthew G. Knepley }
204732d2bbc9SMatthew G. Knepley 
2048*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void *ctx)
2049*d71ae5a4SJacob Faibussowitsch {
20500c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20516528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
205263a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
20530c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
20543ec1f749SStefano Zampini   *(void **)ctx = ds->ctx[f];
20550c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20560c2f2876SMatthew G. Knepley }
20570c2f2876SMatthew G. Knepley 
2058*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx)
2059*d71ae5a4SJacob Faibussowitsch {
20600c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20616528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
206263a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
20639566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(ds, f + 1));
20646528b96dSMatthew G. Knepley   ds->ctx[f] = ctx;
20650c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
20660c2f2876SMatthew G. Knepley }
20670c2f2876SMatthew G. Knepley 
2068194d53e6SMatthew G. Knepley /*@C
2069194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
2070194d53e6SMatthew G. Knepley 
2071194d53e6SMatthew G. Knepley   Not collective
2072194d53e6SMatthew G. Knepley 
2073194d53e6SMatthew G. Knepley   Input Parameters:
20746528b96dSMatthew G. Knepley + ds - The PetscDS
2075194d53e6SMatthew G. Knepley - f  - The test field number
2076194d53e6SMatthew G. Knepley 
2077194d53e6SMatthew G. Knepley   Output Parameters:
2078194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
2079194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2080194d53e6SMatthew G. Knepley 
2081194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2082194d53e6SMatthew G. Knepley 
2083194d53e6SMatthew 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
2084194d53e6SMatthew G. Knepley 
2085194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2086194d53e6SMatthew G. Knepley 
208730b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2088194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2089194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
209030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2091194d53e6SMatthew G. Knepley 
2092194d53e6SMatthew G. Knepley + dim - the spatial dimension
2093194d53e6SMatthew G. Knepley . Nf - the number of fields
2094194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2095194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2096194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2097194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2098194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2099194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2100194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2101194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2102194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2103194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2104194d53e6SMatthew G. Knepley . t - current time
2105194d53e6SMatthew G. Knepley . x - coordinates of the current point
2106194d53e6SMatthew G. Knepley . n - unit normal at the current point
210797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
210897b6e6e8SMatthew G. Knepley . constants - constant parameters
2109194d53e6SMatthew G. Knepley - f0 - output values at the current point
2110194d53e6SMatthew G. Knepley 
2111194d53e6SMatthew G. Knepley   Level: intermediate
2112194d53e6SMatthew G. Knepley 
2113db781477SPatrick Sanan .seealso: `PetscDSSetBdResidual()`
2114194d53e6SMatthew G. Knepley @*/
2115*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetBdResidual(PetscDS ds, PetscInt f, void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
2116*d71ae5a4SJacob Faibussowitsch {
21176528b96dSMatthew G. Knepley   PetscBdPointFunc *tmp0, *tmp1;
21186528b96dSMatthew G. Knepley   PetscInt          n0, n1;
21196528b96dSMatthew G. Knepley 
21202764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21216528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
212263a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
21239566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1));
21246528b96dSMatthew G. Knepley   *f0 = tmp0 ? tmp0[0] : NULL;
21256528b96dSMatthew G. Knepley   *f1 = tmp1 ? tmp1[0] : NULL;
21262764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21272764a2aaSMatthew G. Knepley }
21282764a2aaSMatthew G. Knepley 
2129194d53e6SMatthew G. Knepley /*@C
2130194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2131194d53e6SMatthew G. Knepley 
2132194d53e6SMatthew G. Knepley   Not collective
2133194d53e6SMatthew G. Knepley 
2134194d53e6SMatthew G. Knepley   Input Parameters:
21356528b96dSMatthew G. Knepley + ds - The PetscDS
2136194d53e6SMatthew G. Knepley . f  - The test field number
2137194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2138194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2139194d53e6SMatthew G. Knepley 
2140194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2141194d53e6SMatthew G. Knepley 
2142194d53e6SMatthew 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
2143194d53e6SMatthew G. Knepley 
2144194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
2145194d53e6SMatthew G. Knepley 
214630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2147194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2148194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
214930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2150194d53e6SMatthew G. Knepley 
2151194d53e6SMatthew G. Knepley + dim - the spatial dimension
2152194d53e6SMatthew G. Knepley . Nf - the number of fields
2153194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2154194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2155194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2156194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2157194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2158194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2159194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2160194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2161194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2162194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2163194d53e6SMatthew G. Knepley . t - current time
2164194d53e6SMatthew G. Knepley . x - coordinates of the current point
2165194d53e6SMatthew G. Knepley . n - unit normal at the current point
216697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
216797b6e6e8SMatthew G. Knepley . constants - constant parameters
2168194d53e6SMatthew G. Knepley - f0 - output values at the current point
2169194d53e6SMatthew G. Knepley 
2170194d53e6SMatthew G. Knepley   Level: intermediate
2171194d53e6SMatthew G. Knepley 
2172db781477SPatrick Sanan .seealso: `PetscDSGetBdResidual()`
2173194d53e6SMatthew G. Knepley @*/
2174*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetBdResidual(PetscDS ds, PetscInt f, void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
2175*d71ae5a4SJacob Faibussowitsch {
21762764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21776528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
217863a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
21799566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1));
21802764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21812764a2aaSMatthew G. Knepley }
21822764a2aaSMatthew G. Knepley 
218327f02ce8SMatthew G. Knepley /*@
218427f02ce8SMatthew G. Knepley   PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set
218527f02ce8SMatthew G. Knepley 
218627f02ce8SMatthew G. Knepley   Not collective
218727f02ce8SMatthew G. Knepley 
218827f02ce8SMatthew G. Knepley   Input Parameter:
21896528b96dSMatthew G. Knepley . ds - The PetscDS
219027f02ce8SMatthew G. Knepley 
219127f02ce8SMatthew G. Knepley   Output Parameter:
219227f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set
219327f02ce8SMatthew G. Knepley 
219427f02ce8SMatthew G. Knepley   Level: intermediate
219527f02ce8SMatthew G. Knepley 
2196db781477SPatrick Sanan .seealso: `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()`
219727f02ce8SMatthew G. Knepley @*/
2198*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac)
2199*d71ae5a4SJacob Faibussowitsch {
220027f02ce8SMatthew G. Knepley   PetscFunctionBegin;
22016528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
22026528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJac, 2);
22039566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasBdJacobian(ds->wf, hasBdJac));
220427f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
220527f02ce8SMatthew G. Knepley }
220627f02ce8SMatthew G. Knepley 
2207194d53e6SMatthew G. Knepley /*@C
2208194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2209194d53e6SMatthew G. Knepley 
2210194d53e6SMatthew G. Knepley   Not collective
2211194d53e6SMatthew G. Knepley 
2212194d53e6SMatthew G. Knepley   Input Parameters:
22136528b96dSMatthew G. Knepley + ds - The PetscDS
2214194d53e6SMatthew G. Knepley . f  - The test field number
2215194d53e6SMatthew G. Knepley - g  - The field number
2216194d53e6SMatthew G. Knepley 
2217194d53e6SMatthew G. Knepley   Output Parameters:
2218194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2219194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2220194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2221194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2222194d53e6SMatthew G. Knepley 
2223194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2224194d53e6SMatthew G. Knepley 
2225194d53e6SMatthew 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
2226194d53e6SMatthew G. Knepley 
2227194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2228194d53e6SMatthew G. Knepley 
222930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2230194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2231194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
223230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2233194d53e6SMatthew G. Knepley 
2234194d53e6SMatthew G. Knepley + dim - the spatial dimension
2235194d53e6SMatthew G. Knepley . Nf - the number of fields
2236194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2237194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2238194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2239194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2240194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2241194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2242194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2243194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2244194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2245194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2246194d53e6SMatthew G. Knepley . t - current time
22472aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2248194d53e6SMatthew G. Knepley . x - coordinates of the current point
2249194d53e6SMatthew G. Knepley . n - normal at the current point
225097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
225197b6e6e8SMatthew G. Knepley . constants - constant parameters
2252194d53e6SMatthew G. Knepley - g0 - output values at the current point
2253194d53e6SMatthew G. Knepley 
2254194d53e6SMatthew G. Knepley   Level: intermediate
2255194d53e6SMatthew G. Knepley 
2256db781477SPatrick Sanan .seealso: `PetscDSSetBdJacobian()`
2257194d53e6SMatthew G. Knepley @*/
2258*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetBdJacobian(PetscDS ds, PetscInt f, PetscInt g, void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
2259*d71ae5a4SJacob Faibussowitsch {
22606528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
22616528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
22626528b96dSMatthew G. Knepley 
22632764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22646528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
226563a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
226663a3b9bcSJacob Faibussowitsch   PetscCheck(!(g < 0) && !(g >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", g, ds->Nf);
22679566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
22686528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
22696528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
22706528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
22716528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
22722764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22732764a2aaSMatthew G. Knepley }
22742764a2aaSMatthew G. Knepley 
2275194d53e6SMatthew G. Knepley /*@C
2276194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2277194d53e6SMatthew G. Knepley 
2278194d53e6SMatthew G. Knepley   Not collective
2279194d53e6SMatthew G. Knepley 
2280194d53e6SMatthew G. Knepley   Input Parameters:
22816528b96dSMatthew G. Knepley + ds - The PetscDS
2282194d53e6SMatthew G. Knepley . f  - The test field number
2283194d53e6SMatthew G. Knepley . g  - The field number
2284194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2285194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2286194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2287194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2288194d53e6SMatthew G. Knepley 
2289194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2290194d53e6SMatthew G. Knepley 
2291194d53e6SMatthew 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
2292194d53e6SMatthew G. Knepley 
2293194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2294194d53e6SMatthew G. Knepley 
229530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2296194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2297194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
229830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2299194d53e6SMatthew G. Knepley 
2300194d53e6SMatthew G. Knepley + dim - the spatial dimension
2301194d53e6SMatthew G. Knepley . Nf - the number of fields
2302194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2303194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2304194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2305194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2306194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2307194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2308194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2309194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2310194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2311194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2312194d53e6SMatthew G. Knepley . t - current time
23132aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2314194d53e6SMatthew G. Knepley . x - coordinates of the current point
2315194d53e6SMatthew G. Knepley . n - normal at the current point
231697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
231797b6e6e8SMatthew G. Knepley . constants - constant parameters
2318194d53e6SMatthew G. Knepley - g0 - output values at the current point
2319194d53e6SMatthew G. Knepley 
2320194d53e6SMatthew G. Knepley   Level: intermediate
2321194d53e6SMatthew G. Knepley 
2322db781477SPatrick Sanan .seealso: `PetscDSGetBdJacobian()`
2323194d53e6SMatthew G. Knepley @*/
2324*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetBdJacobian(PetscDS ds, PetscInt f, PetscInt g, void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
2325*d71ae5a4SJacob Faibussowitsch {
23262764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23276528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
23282764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
23292764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
23302764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
23312764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
233263a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
233363a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
23349566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
23352764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23362764a2aaSMatthew G. Knepley }
23372764a2aaSMatthew G. Knepley 
233827f02ce8SMatthew G. Knepley /*@
233927f02ce8SMatthew G. Knepley   PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set
234027f02ce8SMatthew G. Knepley 
234127f02ce8SMatthew G. Knepley   Not collective
234227f02ce8SMatthew G. Knepley 
234327f02ce8SMatthew G. Knepley   Input Parameter:
23446528b96dSMatthew G. Knepley . ds - The PetscDS
234527f02ce8SMatthew G. Knepley 
234627f02ce8SMatthew G. Knepley   Output Parameter:
234727f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set
234827f02ce8SMatthew G. Knepley 
234927f02ce8SMatthew G. Knepley   Level: intermediate
235027f02ce8SMatthew G. Knepley 
2351db781477SPatrick Sanan .seealso: `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()`
235227f02ce8SMatthew G. Knepley @*/
2353*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre)
2354*d71ae5a4SJacob Faibussowitsch {
235527f02ce8SMatthew G. Knepley   PetscFunctionBegin;
23566528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
23576528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJacPre, 2);
23589566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre));
235927f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
236027f02ce8SMatthew G. Knepley }
236127f02ce8SMatthew G. Knepley 
236227f02ce8SMatthew G. Knepley /*@C
236327f02ce8SMatthew G. Knepley   PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field
236427f02ce8SMatthew G. Knepley 
236527f02ce8SMatthew G. Knepley   Not collective
236627f02ce8SMatthew G. Knepley 
236727f02ce8SMatthew G. Knepley   Input Parameters:
23686528b96dSMatthew G. Knepley + ds - The PetscDS
236927f02ce8SMatthew G. Knepley . f  - The test field number
237027f02ce8SMatthew G. Knepley - g  - The field number
237127f02ce8SMatthew G. Knepley 
237227f02ce8SMatthew G. Knepley   Output Parameters:
237327f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term
237427f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
237527f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
237627f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
237727f02ce8SMatthew G. Knepley 
237827f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
237927f02ce8SMatthew G. Knepley 
238027f02ce8SMatthew 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
238127f02ce8SMatthew G. Knepley 
238227f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
238327f02ce8SMatthew G. Knepley 
238427f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
238527f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
238627f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
238727f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
238827f02ce8SMatthew G. Knepley 
238927f02ce8SMatthew G. Knepley + dim - the spatial dimension
239027f02ce8SMatthew G. Knepley . Nf - the number of fields
239127f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
239227f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
239327f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
239427f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
239527f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
239627f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
239727f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
239827f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
239927f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
240027f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
240127f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
240227f02ce8SMatthew G. Knepley . t - current time
240327f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
240427f02ce8SMatthew G. Knepley . x - coordinates of the current point
240527f02ce8SMatthew G. Knepley . n - normal at the current point
240627f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
240727f02ce8SMatthew G. Knepley . constants - constant parameters
240827f02ce8SMatthew G. Knepley - g0 - output values at the current point
240927f02ce8SMatthew G. Knepley 
241027f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
241127f02ce8SMatthew G. Knepley 
241227f02ce8SMatthew G. Knepley   Level: intermediate
241327f02ce8SMatthew G. Knepley 
2414db781477SPatrick Sanan .seealso: `PetscDSSetBdJacobianPreconditioner()`
241527f02ce8SMatthew G. Knepley @*/
2416*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
2417*d71ae5a4SJacob Faibussowitsch {
24186528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
24196528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
24206528b96dSMatthew G. Knepley 
242127f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24226528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
242363a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
242463a3b9bcSJacob Faibussowitsch   PetscCheck(!(g < 0) && !(g >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", g, ds->Nf);
24259566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
24266528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
24276528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
24286528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
24296528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
243027f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
243127f02ce8SMatthew G. Knepley }
243227f02ce8SMatthew G. Knepley 
243327f02ce8SMatthew G. Knepley /*@C
243427f02ce8SMatthew G. Knepley   PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field
243527f02ce8SMatthew G. Knepley 
243627f02ce8SMatthew G. Knepley   Not collective
243727f02ce8SMatthew G. Knepley 
243827f02ce8SMatthew G. Knepley   Input Parameters:
24396528b96dSMatthew G. Knepley + ds - The PetscDS
244027f02ce8SMatthew G. Knepley . f  - The test field number
244127f02ce8SMatthew G. Knepley . g  - The field number
244227f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term
244327f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
244427f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
244527f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
244627f02ce8SMatthew G. Knepley 
244727f02ce8SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
244827f02ce8SMatthew G. Knepley 
244927f02ce8SMatthew 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
245027f02ce8SMatthew G. Knepley 
245127f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
245227f02ce8SMatthew G. Knepley 
245327f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
245427f02ce8SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
245527f02ce8SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
245627f02ce8SMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
245727f02ce8SMatthew G. Knepley 
245827f02ce8SMatthew G. Knepley + dim - the spatial dimension
245927f02ce8SMatthew G. Knepley . Nf - the number of fields
246027f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
246127f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
246227f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
246327f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
246427f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
246527f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
246627f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
246727f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
246827f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
246927f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
247027f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
247127f02ce8SMatthew G. Knepley . t - current time
247227f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
247327f02ce8SMatthew G. Knepley . x - coordinates of the current point
247427f02ce8SMatthew G. Knepley . n - normal at the current point
247527f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
247627f02ce8SMatthew G. Knepley . constants - constant parameters
247727f02ce8SMatthew G. Knepley - g0 - output values at the current point
247827f02ce8SMatthew G. Knepley 
247927f02ce8SMatthew G. Knepley   This is not yet available in Fortran.
248027f02ce8SMatthew G. Knepley 
248127f02ce8SMatthew G. Knepley   Level: intermediate
248227f02ce8SMatthew G. Knepley 
2483db781477SPatrick Sanan .seealso: `PetscDSGetBdJacobianPreconditioner()`
248427f02ce8SMatthew G. Knepley @*/
2485*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
2486*d71ae5a4SJacob Faibussowitsch {
248727f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24886528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
248927f02ce8SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
249027f02ce8SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
249127f02ce8SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
249227f02ce8SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
249363a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
249463a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
24959566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
249627f02ce8SMatthew G. Knepley   PetscFunctionReturn(0);
249727f02ce8SMatthew G. Knepley }
249827f02ce8SMatthew G. Knepley 
24990d3e9b51SMatthew G. Knepley /*@C
2500c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2501c371a6d1SMatthew G. Knepley 
2502c371a6d1SMatthew G. Knepley   Not collective
2503c371a6d1SMatthew G. Knepley 
2504c371a6d1SMatthew G. Knepley   Input Parameters:
2505c371a6d1SMatthew G. Knepley + prob - The PetscDS
2506c371a6d1SMatthew G. Knepley - f    - The test field number
2507c371a6d1SMatthew G. Knepley 
2508d8d19677SJose E. Roman   Output Parameters:
250995cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field
251095cbbfd3SMatthew G. Knepley - exactCtx - exact solution context
2511c371a6d1SMatthew G. Knepley 
2512c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2513c371a6d1SMatthew G. Knepley 
2514c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2515c371a6d1SMatthew G. Knepley 
2516c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2517c371a6d1SMatthew G. Knepley . t - current time
2518c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2519c371a6d1SMatthew G. Knepley . Nc - the number of field components
2520c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2521c371a6d1SMatthew G. Knepley - ctx - a user context
2522c371a6d1SMatthew G. Knepley 
2523c371a6d1SMatthew G. Knepley   Level: intermediate
2524c371a6d1SMatthew G. Knepley 
2525db781477SPatrick Sanan .seealso: `PetscDSSetExactSolution()`, `PetscDSGetExactSolutionTimeDerivative()`
2526c371a6d1SMatthew G. Knepley @*/
2527*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2528*d71ae5a4SJacob Faibussowitsch {
2529c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2530c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
253163a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= prob->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, prob->Nf);
25329371c9d4SSatish Balay   if (sol) {
25339371c9d4SSatish Balay     PetscValidPointer(sol, 3);
25349371c9d4SSatish Balay     *sol = prob->exactSol[f];
25359371c9d4SSatish Balay   }
25369371c9d4SSatish Balay   if (ctx) {
25379371c9d4SSatish Balay     PetscValidPointer(ctx, 4);
25389371c9d4SSatish Balay     *ctx = prob->exactCtx[f];
25399371c9d4SSatish Balay   }
2540c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2541c371a6d1SMatthew G. Knepley }
2542c371a6d1SMatthew G. Knepley 
2543c371a6d1SMatthew G. Knepley /*@C
2544578a5ef5SMatthew Knepley   PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field
2545c371a6d1SMatthew G. Knepley 
2546c371a6d1SMatthew G. Knepley   Not collective
2547c371a6d1SMatthew G. Knepley 
2548c371a6d1SMatthew G. Knepley   Input Parameters:
2549c371a6d1SMatthew G. Knepley + prob - The PetscDS
2550c371a6d1SMatthew G. Knepley . f    - The test field number
255195cbbfd3SMatthew G. Knepley . sol  - solution function for the test fields
255295cbbfd3SMatthew G. Knepley - ctx  - solution context or NULL
2553c371a6d1SMatthew G. Knepley 
2554c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2555c371a6d1SMatthew G. Knepley 
2556c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2557c371a6d1SMatthew G. Knepley 
2558c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2559c371a6d1SMatthew G. Knepley . t - current time
2560c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2561c371a6d1SMatthew G. Knepley . Nc - the number of field components
2562c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2563c371a6d1SMatthew G. Knepley - ctx - a user context
2564c371a6d1SMatthew G. Knepley 
2565c371a6d1SMatthew G. Knepley   Level: intermediate
2566c371a6d1SMatthew G. Knepley 
2567db781477SPatrick Sanan .seealso: `PetscDSGetExactSolution()`
2568c371a6d1SMatthew G. Knepley @*/
2569*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2570*d71ae5a4SJacob Faibussowitsch {
2571c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2572c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
257363a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
25749566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(prob, f + 1));
25759371c9d4SSatish Balay   if (sol) {
25769371c9d4SSatish Balay     PetscValidFunction(sol, 3);
25779371c9d4SSatish Balay     prob->exactSol[f] = sol;
25789371c9d4SSatish Balay   }
25799371c9d4SSatish Balay   if (ctx) {
25809371c9d4SSatish Balay     PetscValidFunction(ctx, 4);
25819371c9d4SSatish Balay     prob->exactCtx[f] = ctx;
25829371c9d4SSatish Balay   }
2583c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2584c371a6d1SMatthew G. Knepley }
2585c371a6d1SMatthew G. Knepley 
25865638fd0eSMatthew G. Knepley /*@C
2587f2cacb80SMatthew G. Knepley   PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field
2588f2cacb80SMatthew G. Knepley 
2589f2cacb80SMatthew G. Knepley   Not collective
2590f2cacb80SMatthew G. Knepley 
2591f2cacb80SMatthew G. Knepley   Input Parameters:
2592f2cacb80SMatthew G. Knepley + prob - The PetscDS
2593f2cacb80SMatthew G. Knepley - f    - The test field number
2594f2cacb80SMatthew G. Knepley 
2595d8d19677SJose E. Roman   Output Parameters:
2596f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field
2597f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context
2598f2cacb80SMatthew G. Knepley 
2599f2cacb80SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2600f2cacb80SMatthew G. Knepley 
2601f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2602f2cacb80SMatthew G. Knepley 
2603f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2604f2cacb80SMatthew G. Knepley . t - current time
2605f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2606f2cacb80SMatthew G. Knepley . Nc - the number of field components
2607f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2608f2cacb80SMatthew G. Knepley - ctx - a user context
2609f2cacb80SMatthew G. Knepley 
2610f2cacb80SMatthew G. Knepley   Level: intermediate
2611f2cacb80SMatthew G. Knepley 
2612db781477SPatrick Sanan .seealso: `PetscDSSetExactSolutionTimeDerivative()`, `PetscDSGetExactSolution()`
2613f2cacb80SMatthew G. Knepley @*/
2614*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2615*d71ae5a4SJacob Faibussowitsch {
2616f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2617f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
261863a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= prob->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, prob->Nf);
26199371c9d4SSatish Balay   if (sol) {
26209371c9d4SSatish Balay     PetscValidPointer(sol, 3);
26219371c9d4SSatish Balay     *sol = prob->exactSol_t[f];
26229371c9d4SSatish Balay   }
26239371c9d4SSatish Balay   if (ctx) {
26249371c9d4SSatish Balay     PetscValidPointer(ctx, 4);
26259371c9d4SSatish Balay     *ctx = prob->exactCtx_t[f];
26269371c9d4SSatish Balay   }
2627f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2628f2cacb80SMatthew G. Knepley }
2629f2cacb80SMatthew G. Knepley 
2630f2cacb80SMatthew G. Knepley /*@C
2631f2cacb80SMatthew G. Knepley   PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field
2632f2cacb80SMatthew G. Knepley 
2633f2cacb80SMatthew G. Knepley   Not collective
2634f2cacb80SMatthew G. Knepley 
2635f2cacb80SMatthew G. Knepley   Input Parameters:
2636f2cacb80SMatthew G. Knepley + prob - The PetscDS
2637f2cacb80SMatthew G. Knepley . f    - The test field number
2638f2cacb80SMatthew G. Knepley . sol  - time derivative of the solution function for the test fields
2639f2cacb80SMatthew G. Knepley - ctx  - time derivative of the solution context or NULL
2640f2cacb80SMatthew G. Knepley 
2641f2cacb80SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2642f2cacb80SMatthew G. Knepley 
2643f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2644f2cacb80SMatthew G. Knepley 
2645f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2646f2cacb80SMatthew G. Knepley . t - current time
2647f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2648f2cacb80SMatthew G. Knepley . Nc - the number of field components
2649f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2650f2cacb80SMatthew G. Knepley - ctx - a user context
2651f2cacb80SMatthew G. Knepley 
2652f2cacb80SMatthew G. Knepley   Level: intermediate
2653f2cacb80SMatthew G. Knepley 
2654db781477SPatrick Sanan .seealso: `PetscDSGetExactSolutionTimeDerivative()`, `PetscDSSetExactSolution()`
2655f2cacb80SMatthew G. Knepley @*/
2656*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2657*d71ae5a4SJacob Faibussowitsch {
2658f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2659f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
266063a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
26619566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(prob, f + 1));
26629371c9d4SSatish Balay   if (sol) {
26639371c9d4SSatish Balay     PetscValidFunction(sol, 3);
26649371c9d4SSatish Balay     prob->exactSol_t[f] = sol;
26659371c9d4SSatish Balay   }
26669371c9d4SSatish Balay   if (ctx) {
26679371c9d4SSatish Balay     PetscValidFunction(ctx, 4);
26689371c9d4SSatish Balay     prob->exactCtx_t[f] = ctx;
26699371c9d4SSatish Balay   }
2670f2cacb80SMatthew G. Knepley   PetscFunctionReturn(0);
2671f2cacb80SMatthew G. Knepley }
2672f2cacb80SMatthew G. Knepley 
2673f2cacb80SMatthew G. Knepley /*@C
267497b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
267597b6e6e8SMatthew G. Knepley 
267697b6e6e8SMatthew G. Knepley   Not collective
267797b6e6e8SMatthew G. Knepley 
267897b6e6e8SMatthew G. Knepley   Input Parameter:
267997b6e6e8SMatthew G. Knepley . prob - The PetscDS object
268097b6e6e8SMatthew G. Knepley 
268197b6e6e8SMatthew G. Knepley   Output Parameters:
268297b6e6e8SMatthew G. Knepley + numConstants - The number of constants
268397b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
268497b6e6e8SMatthew G. Knepley 
268597b6e6e8SMatthew G. Knepley   Level: intermediate
268697b6e6e8SMatthew G. Knepley 
2687db781477SPatrick Sanan .seealso: `PetscDSSetConstants()`, `PetscDSCreate()`
268897b6e6e8SMatthew G. Knepley @*/
2689*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
2690*d71ae5a4SJacob Faibussowitsch {
269197b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
269297b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26939371c9d4SSatish Balay   if (numConstants) {
26949371c9d4SSatish Balay     PetscValidIntPointer(numConstants, 2);
26959371c9d4SSatish Balay     *numConstants = prob->numConstants;
26969371c9d4SSatish Balay   }
26979371c9d4SSatish Balay   if (constants) {
26989371c9d4SSatish Balay     PetscValidPointer(constants, 3);
26999371c9d4SSatish Balay     *constants = prob->constants;
27009371c9d4SSatish Balay   }
270197b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
270297b6e6e8SMatthew G. Knepley }
270397b6e6e8SMatthew G. Knepley 
27040d3e9b51SMatthew G. Knepley /*@C
270597b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
270697b6e6e8SMatthew G. Knepley 
270797b6e6e8SMatthew G. Knepley   Not collective
270897b6e6e8SMatthew G. Knepley 
270997b6e6e8SMatthew G. Knepley   Input Parameters:
271097b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
271197b6e6e8SMatthew G. Knepley . numConstants - The number of constants
271297b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
271397b6e6e8SMatthew G. Knepley 
271497b6e6e8SMatthew G. Knepley   Level: intermediate
271597b6e6e8SMatthew G. Knepley 
2716db781477SPatrick Sanan .seealso: `PetscDSGetConstants()`, `PetscDSCreate()`
271797b6e6e8SMatthew G. Knepley @*/
2718*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
2719*d71ae5a4SJacob Faibussowitsch {
272097b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
272197b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
272297b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
27239566063dSJacob Faibussowitsch     PetscCall(PetscFree(prob->constants));
272497b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
272597b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
27269566063dSJacob Faibussowitsch       PetscCall(PetscMalloc1(prob->numConstants, &prob->constants));
272720be0f5bSMatthew G. Knepley     } else {
272820be0f5bSMatthew G. Knepley       prob->constants = NULL;
272920be0f5bSMatthew G. Knepley     }
273020be0f5bSMatthew G. Knepley   }
273120be0f5bSMatthew G. Knepley   if (prob->numConstants) {
2732dadcf809SJacob Faibussowitsch     PetscValidScalarPointer(constants, 3);
27339566063dSJacob Faibussowitsch     PetscCall(PetscArraycpy(prob->constants, constants, prob->numConstants));
273497b6e6e8SMatthew G. Knepley   }
273597b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
273697b6e6e8SMatthew G. Knepley }
273797b6e6e8SMatthew G. Knepley 
27384cd1e086SMatthew G. Knepley /*@
27394cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
27404cd1e086SMatthew G. Knepley 
27414cd1e086SMatthew G. Knepley   Not collective
27424cd1e086SMatthew G. Knepley 
27434cd1e086SMatthew G. Knepley   Input Parameters:
27444cd1e086SMatthew G. Knepley + prob - The PetscDS object
27454cd1e086SMatthew G. Knepley - disc - The discretization object
27464cd1e086SMatthew G. Knepley 
27474cd1e086SMatthew G. Knepley   Output Parameter:
27484cd1e086SMatthew G. Knepley . f - The field number
27494cd1e086SMatthew G. Knepley 
27504cd1e086SMatthew G. Knepley   Level: beginner
27514cd1e086SMatthew G. Knepley 
2752db781477SPatrick Sanan .seealso: `PetscGetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
27534cd1e086SMatthew G. Knepley @*/
2754*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
2755*d71ae5a4SJacob Faibussowitsch {
27564cd1e086SMatthew G. Knepley   PetscInt g;
27574cd1e086SMatthew G. Knepley 
27584cd1e086SMatthew G. Knepley   PetscFunctionBegin;
27594cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2760dadcf809SJacob Faibussowitsch   PetscValidIntPointer(f, 3);
27614cd1e086SMatthew G. Knepley   *f = -1;
27629371c9d4SSatish Balay   for (g = 0; g < prob->Nf; ++g) {
27639371c9d4SSatish Balay     if (disc == prob->disc[g]) break;
27649371c9d4SSatish Balay   }
276508401ef6SPierre Jolivet   PetscCheck(g != prob->Nf, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
27664cd1e086SMatthew G. Knepley   *f = g;
27674cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
27684cd1e086SMatthew G. Knepley }
27694cd1e086SMatthew G. Knepley 
27704cd1e086SMatthew G. Knepley /*@
27714cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
27724cd1e086SMatthew G. Knepley 
27734cd1e086SMatthew G. Knepley   Not collective
27744cd1e086SMatthew G. Knepley 
27754cd1e086SMatthew G. Knepley   Input Parameters:
27764cd1e086SMatthew G. Knepley + prob - The PetscDS object
27774cd1e086SMatthew G. Knepley - f - The field number
27784cd1e086SMatthew G. Knepley 
27794cd1e086SMatthew G. Knepley   Output Parameter:
27804cd1e086SMatthew G. Knepley . size - The size
27814cd1e086SMatthew G. Knepley 
27824cd1e086SMatthew G. Knepley   Level: beginner
27834cd1e086SMatthew G. Knepley 
2784db781477SPatrick Sanan .seealso: `PetscDSGetFieldOffset()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
27854cd1e086SMatthew G. Knepley @*/
2786*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
2787*d71ae5a4SJacob Faibussowitsch {
27884cd1e086SMatthew G. Knepley   PetscFunctionBegin;
27894cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2790dadcf809SJacob Faibussowitsch   PetscValidIntPointer(size, 3);
279163a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= prob->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, prob->Nf);
27929566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
2793d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
27944cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
27954cd1e086SMatthew G. Knepley }
27964cd1e086SMatthew G. Knepley 
2797bc4ae4beSMatthew G. Knepley /*@
2798bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2799bc4ae4beSMatthew G. Knepley 
2800bc4ae4beSMatthew G. Knepley   Not collective
2801bc4ae4beSMatthew G. Knepley 
2802bc4ae4beSMatthew G. Knepley   Input Parameters:
2803bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2804bc4ae4beSMatthew G. Knepley - f - The field number
2805bc4ae4beSMatthew G. Knepley 
2806bc4ae4beSMatthew G. Knepley   Output Parameter:
2807bc4ae4beSMatthew G. Knepley . off - The offset
2808bc4ae4beSMatthew G. Knepley 
2809bc4ae4beSMatthew G. Knepley   Level: beginner
2810bc4ae4beSMatthew G. Knepley 
2811db781477SPatrick Sanan .seealso: `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
2812bc4ae4beSMatthew G. Knepley @*/
2813*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
2814*d71ae5a4SJacob Faibussowitsch {
28154cd1e086SMatthew G. Knepley   PetscInt size, g;
28162764a2aaSMatthew G. Knepley 
28172764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28182764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2819dadcf809SJacob Faibussowitsch   PetscValidIntPointer(off, 3);
282063a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= prob->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, prob->Nf);
28212764a2aaSMatthew G. Knepley   *off = 0;
28222764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
28239566063dSJacob Faibussowitsch     PetscCall(PetscDSGetFieldSize(prob, g, &size));
28244cd1e086SMatthew G. Knepley     *off += size;
28252764a2aaSMatthew G. Knepley   }
28262764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28272764a2aaSMatthew G. Knepley }
28282764a2aaSMatthew G. Knepley 
2829bc4ae4beSMatthew G. Knepley /*@
28305fedec97SMatthew G. Knepley   PetscDSGetFieldOffsetCohesive - Returns the offset of the given field in the full space basis on a cohesive cell
28315fedec97SMatthew G. Knepley 
28325fedec97SMatthew G. Knepley   Not collective
28335fedec97SMatthew G. Knepley 
28345fedec97SMatthew G. Knepley   Input Parameters:
28355fedec97SMatthew G. Knepley + prob - The PetscDS object
28365fedec97SMatthew G. Knepley - f - The field number
28375fedec97SMatthew G. Knepley 
28385fedec97SMatthew G. Knepley   Output Parameter:
28395fedec97SMatthew G. Knepley . off - The offset
28405fedec97SMatthew G. Knepley 
28415fedec97SMatthew G. Knepley   Level: beginner
28425fedec97SMatthew G. Knepley 
2843db781477SPatrick Sanan .seealso: `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
28445fedec97SMatthew G. Knepley @*/
2845*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldOffsetCohesive(PetscDS ds, PetscInt f, PetscInt *off)
2846*d71ae5a4SJacob Faibussowitsch {
28475fedec97SMatthew G. Knepley   PetscInt size, g;
28485fedec97SMatthew G. Knepley 
28495fedec97SMatthew G. Knepley   PetscFunctionBegin;
28505fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2851dadcf809SJacob Faibussowitsch   PetscValidIntPointer(off, 3);
285263a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= ds->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, ds->Nf);
28535fedec97SMatthew G. Knepley   *off = 0;
28545fedec97SMatthew G. Knepley   for (g = 0; g < f; ++g) {
28555fedec97SMatthew G. Knepley     PetscBool cohesive;
28565fedec97SMatthew G. Knepley 
28579566063dSJacob Faibussowitsch     PetscCall(PetscDSGetCohesive(ds, g, &cohesive));
28589566063dSJacob Faibussowitsch     PetscCall(PetscDSGetFieldSize(ds, g, &size));
28595fedec97SMatthew G. Knepley     *off += cohesive ? size : size * 2;
28605fedec97SMatthew G. Knepley   }
28615fedec97SMatthew G. Knepley   PetscFunctionReturn(0);
28625fedec97SMatthew G. Knepley }
28635fedec97SMatthew G. Knepley 
28645fedec97SMatthew G. Knepley /*@
286547e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2866bc4ae4beSMatthew G. Knepley 
2867bc4ae4beSMatthew G. Knepley   Not collective
2868bc4ae4beSMatthew G. Knepley 
286947e57110SSander Arens   Input Parameter:
287047e57110SSander Arens . prob - The PetscDS object
2871bc4ae4beSMatthew G. Knepley 
2872bc4ae4beSMatthew G. Knepley   Output Parameter:
287347e57110SSander Arens . dimensions - The number of dimensions
2874bc4ae4beSMatthew G. Knepley 
2875bc4ae4beSMatthew G. Knepley   Level: beginner
2876bc4ae4beSMatthew G. Knepley 
2877db781477SPatrick Sanan .seealso: `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
2878bc4ae4beSMatthew G. Knepley @*/
2879*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
2880*d71ae5a4SJacob Faibussowitsch {
28812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28822764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28839566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
288447e57110SSander Arens   PetscValidPointer(dimensions, 2);
288547e57110SSander Arens   *dimensions = prob->Nb;
288647e57110SSander Arens   PetscFunctionReturn(0);
28876ce16762SMatthew G. Knepley }
288847e57110SSander Arens 
288947e57110SSander Arens /*@
289047e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
289147e57110SSander Arens 
289247e57110SSander Arens   Not collective
289347e57110SSander Arens 
289447e57110SSander Arens   Input Parameter:
289547e57110SSander Arens . prob - The PetscDS object
289647e57110SSander Arens 
289747e57110SSander Arens   Output Parameter:
289847e57110SSander Arens . components - The number of components
289947e57110SSander Arens 
290047e57110SSander Arens   Level: beginner
290147e57110SSander Arens 
2902db781477SPatrick Sanan .seealso: `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
290347e57110SSander Arens @*/
2904*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
2905*d71ae5a4SJacob Faibussowitsch {
290647e57110SSander Arens   PetscFunctionBegin;
290747e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29089566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
290947e57110SSander Arens   PetscValidPointer(components, 2);
291047e57110SSander Arens   *components = prob->Nc;
29116ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
29126ce16762SMatthew G. Knepley }
29136ce16762SMatthew G. Knepley 
29146ce16762SMatthew G. Knepley /*@
29156ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
29166ce16762SMatthew G. Knepley 
29176ce16762SMatthew G. Knepley   Not collective
29186ce16762SMatthew G. Knepley 
29196ce16762SMatthew G. Knepley   Input Parameters:
29206ce16762SMatthew G. Knepley + prob - The PetscDS object
29216ce16762SMatthew G. Knepley - f - The field number
29226ce16762SMatthew G. Knepley 
29236ce16762SMatthew G. Knepley   Output Parameter:
29246ce16762SMatthew G. Knepley . off - The offset
29256ce16762SMatthew G. Knepley 
29266ce16762SMatthew G. Knepley   Level: beginner
29276ce16762SMatthew G. Knepley 
2928db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()`
29296ce16762SMatthew G. Knepley @*/
2930*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
2931*d71ae5a4SJacob Faibussowitsch {
29326ce16762SMatthew G. Knepley   PetscFunctionBegin;
29336ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2934dadcf809SJacob Faibussowitsch   PetscValidIntPointer(off, 3);
293563a3b9bcSJacob Faibussowitsch   PetscCheck(!(f < 0) && !(f >= prob->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, prob->Nf);
29369566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
293747e57110SSander Arens   *off = prob->off[f];
29382764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29392764a2aaSMatthew G. Knepley }
29402764a2aaSMatthew G. Knepley 
2941194d53e6SMatthew G. Knepley /*@
2942194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2943194d53e6SMatthew G. Knepley 
2944194d53e6SMatthew G. Knepley   Not collective
2945194d53e6SMatthew G. Knepley 
2946194d53e6SMatthew G. Knepley   Input Parameter:
2947194d53e6SMatthew G. Knepley . prob - The PetscDS object
2948194d53e6SMatthew G. Knepley 
2949194d53e6SMatthew G. Knepley   Output Parameter:
2950194d53e6SMatthew G. Knepley . offsets - The offsets
2951194d53e6SMatthew G. Knepley 
2952194d53e6SMatthew G. Knepley   Level: beginner
2953194d53e6SMatthew G. Knepley 
2954db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()`
2955194d53e6SMatthew G. Knepley @*/
2956*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2957*d71ae5a4SJacob Faibussowitsch {
2958194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2959194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2960194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
29619566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
2962194d53e6SMatthew G. Knepley   *offsets = prob->off;
2963194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2964194d53e6SMatthew G. Knepley }
2965194d53e6SMatthew G. Knepley 
2966194d53e6SMatthew G. Knepley /*@
2967194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2968194d53e6SMatthew G. Knepley 
2969194d53e6SMatthew G. Knepley   Not collective
2970194d53e6SMatthew G. Knepley 
2971194d53e6SMatthew G. Knepley   Input Parameter:
2972194d53e6SMatthew G. Knepley . prob - The PetscDS object
2973194d53e6SMatthew G. Knepley 
2974194d53e6SMatthew G. Knepley   Output Parameter:
2975194d53e6SMatthew G. Knepley . offsets - The offsets
2976194d53e6SMatthew G. Knepley 
2977194d53e6SMatthew G. Knepley   Level: beginner
2978194d53e6SMatthew G. Knepley 
2979db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()`
2980194d53e6SMatthew G. Knepley @*/
2981*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2982*d71ae5a4SJacob Faibussowitsch {
2983194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2984194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2985194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
29869566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
2987194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
2988194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2989194d53e6SMatthew G. Knepley }
2990194d53e6SMatthew G. Knepley 
29919ee2af8cSMatthew G. Knepley /*@
29929ee2af8cSMatthew G. Knepley   PetscDSGetComponentOffsetsCohesive - Returns the offset of each field on an evaluation point
29939ee2af8cSMatthew G. Knepley 
29949ee2af8cSMatthew G. Knepley   Not collective
29959ee2af8cSMatthew G. Knepley 
29969ee2af8cSMatthew G. Knepley   Input Parameters:
29979ee2af8cSMatthew G. Knepley + ds - The PetscDS object
29989ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
29999ee2af8cSMatthew G. Knepley 
30009ee2af8cSMatthew G. Knepley   Output Parameter:
30019ee2af8cSMatthew G. Knepley . offsets - The offsets
30029ee2af8cSMatthew G. Knepley 
30039ee2af8cSMatthew G. Knepley   Level: beginner
30049ee2af8cSMatthew G. Knepley 
3005db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()`
30069ee2af8cSMatthew G. Knepley @*/
3007*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
3008*d71ae5a4SJacob Faibussowitsch {
30099ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
30109ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
30119ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
301228b400f6SJacob Faibussowitsch   PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
301363a3b9bcSJacob Faibussowitsch   PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s);
30149566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(ds));
30159ee2af8cSMatthew G. Knepley   *offsets = ds->offCohesive[s];
30169ee2af8cSMatthew G. Knepley   PetscFunctionReturn(0);
30179ee2af8cSMatthew G. Knepley }
30189ee2af8cSMatthew G. Knepley 
30199ee2af8cSMatthew G. Knepley /*@
30209ee2af8cSMatthew G. Knepley   PetscDSGetComponentDerivativeOffsetsCohesive - Returns the offset of each field derivative on an evaluation point
30219ee2af8cSMatthew G. Knepley 
30229ee2af8cSMatthew G. Knepley   Not collective
30239ee2af8cSMatthew G. Knepley 
30249ee2af8cSMatthew G. Knepley   Input Parameters:
30259ee2af8cSMatthew G. Knepley + ds - The PetscDS object
30269ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
30279ee2af8cSMatthew G. Knepley 
30289ee2af8cSMatthew G. Knepley   Output Parameter:
30299ee2af8cSMatthew G. Knepley . offsets - The offsets
30309ee2af8cSMatthew G. Knepley 
30319ee2af8cSMatthew G. Knepley   Level: beginner
30329ee2af8cSMatthew G. Knepley 
3033db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()`
30349ee2af8cSMatthew G. Knepley @*/
3035*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentDerivativeOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
3036*d71ae5a4SJacob Faibussowitsch {
30379ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
30389ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
30399ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
304028b400f6SJacob Faibussowitsch   PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
304163a3b9bcSJacob Faibussowitsch   PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s);
30429566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(ds));
30439ee2af8cSMatthew G. Knepley   *offsets = ds->offDerCohesive[s];
30449ee2af8cSMatthew G. Knepley   PetscFunctionReturn(0);
30459ee2af8cSMatthew G. Knepley }
30469ee2af8cSMatthew G. Knepley 
304768c9edb9SMatthew G. Knepley /*@C
304868c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
304968c9edb9SMatthew G. Knepley 
305068c9edb9SMatthew G. Knepley   Not collective
305168c9edb9SMatthew G. Knepley 
305268c9edb9SMatthew G. Knepley   Input Parameter:
305368c9edb9SMatthew G. Knepley . prob - The PetscDS object
305468c9edb9SMatthew G. Knepley 
3055ef0bb6c7SMatthew G. Knepley   Output Parameter:
3056ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field
305768c9edb9SMatthew G. Knepley 
305868c9edb9SMatthew G. Knepley   Level: intermediate
305968c9edb9SMatthew G. Knepley 
3060db781477SPatrick Sanan .seealso: `PetscDSCreate()`
306168c9edb9SMatthew G. Knepley @*/
3062*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[])
3063*d71ae5a4SJacob Faibussowitsch {
30642764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30652764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3066ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
30679566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3068ef0bb6c7SMatthew G. Knepley   *T = prob->T;
30692764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30702764a2aaSMatthew G. Knepley }
30712764a2aaSMatthew G. Knepley 
307268c9edb9SMatthew G. Knepley /*@C
30734d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
307468c9edb9SMatthew G. Knepley 
307568c9edb9SMatthew G. Knepley   Not collective
307668c9edb9SMatthew G. Knepley 
307768c9edb9SMatthew G. Knepley   Input Parameter:
307868c9edb9SMatthew G. Knepley . prob - The PetscDS object
307968c9edb9SMatthew G. Knepley 
3080ef0bb6c7SMatthew G. Knepley   Output Parameter:
3081a5b23f4aSJose E. Roman . Tf - The basis function and derivative tabulation on each local face at quadrature points for each and field
308268c9edb9SMatthew G. Knepley 
308368c9edb9SMatthew G. Knepley   Level: intermediate
308468c9edb9SMatthew G. Knepley 
3085db781477SPatrick Sanan .seealso: `PetscDSGetTabulation()`, `PetscDSCreate()`
308668c9edb9SMatthew G. Knepley @*/
3087*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[])
3088*d71ae5a4SJacob Faibussowitsch {
30892764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30902764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3091ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
30929566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3093ef0bb6c7SMatthew G. Knepley   *Tf = prob->Tf;
30942764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30952764a2aaSMatthew G. Knepley }
30962764a2aaSMatthew G. Knepley 
3097*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
3098*d71ae5a4SJacob Faibussowitsch {
30992764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31002764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31019566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
31029371c9d4SSatish Balay   if (u) {
31039371c9d4SSatish Balay     PetscValidPointer(u, 2);
31049371c9d4SSatish Balay     *u = prob->u;
31059371c9d4SSatish Balay   }
31069371c9d4SSatish Balay   if (u_t) {
31079371c9d4SSatish Balay     PetscValidPointer(u_t, 3);
31089371c9d4SSatish Balay     *u_t = prob->u_t;
31099371c9d4SSatish Balay   }
31109371c9d4SSatish Balay   if (u_x) {
31119371c9d4SSatish Balay     PetscValidPointer(u_x, 4);
31129371c9d4SSatish Balay     *u_x = prob->u_x;
31139371c9d4SSatish Balay   }
31142764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31152764a2aaSMatthew G. Knepley }
31162764a2aaSMatthew G. Knepley 
3117*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
3118*d71ae5a4SJacob Faibussowitsch {
31192764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31202764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31219566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
31229371c9d4SSatish Balay   if (f0) {
31239371c9d4SSatish Balay     PetscValidPointer(f0, 2);
31249371c9d4SSatish Balay     *f0 = prob->f0;
31259371c9d4SSatish Balay   }
31269371c9d4SSatish Balay   if (f1) {
31279371c9d4SSatish Balay     PetscValidPointer(f1, 3);
31289371c9d4SSatish Balay     *f1 = prob->f1;
31299371c9d4SSatish Balay   }
31309371c9d4SSatish Balay   if (g0) {
31319371c9d4SSatish Balay     PetscValidPointer(g0, 4);
31329371c9d4SSatish Balay     *g0 = prob->g0;
31339371c9d4SSatish Balay   }
31349371c9d4SSatish Balay   if (g1) {
31359371c9d4SSatish Balay     PetscValidPointer(g1, 5);
31369371c9d4SSatish Balay     *g1 = prob->g1;
31379371c9d4SSatish Balay   }
31389371c9d4SSatish Balay   if (g2) {
31399371c9d4SSatish Balay     PetscValidPointer(g2, 6);
31409371c9d4SSatish Balay     *g2 = prob->g2;
31419371c9d4SSatish Balay   }
31429371c9d4SSatish Balay   if (g3) {
31439371c9d4SSatish Balay     PetscValidPointer(g3, 7);
31449371c9d4SSatish Balay     *g3 = prob->g3;
31459371c9d4SSatish Balay   }
31462764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31472764a2aaSMatthew G. Knepley }
31482764a2aaSMatthew G. Knepley 
3149*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal)
3150*d71ae5a4SJacob Faibussowitsch {
31512764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31522764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31539566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
31549371c9d4SSatish Balay   if (x) {
31559371c9d4SSatish Balay     PetscValidPointer(x, 2);
31569371c9d4SSatish Balay     *x = prob->x;
31579371c9d4SSatish Balay   }
31589371c9d4SSatish Balay   if (basisReal) {
31599371c9d4SSatish Balay     PetscValidPointer(basisReal, 3);
31609371c9d4SSatish Balay     *basisReal = prob->basisReal;
31619371c9d4SSatish Balay   }
31629371c9d4SSatish Balay   if (basisDerReal) {
31639371c9d4SSatish Balay     PetscValidPointer(basisDerReal, 4);
31649371c9d4SSatish Balay     *basisDerReal = prob->basisDerReal;
31659371c9d4SSatish Balay   }
31669371c9d4SSatish Balay   if (testReal) {
31679371c9d4SSatish Balay     PetscValidPointer(testReal, 5);
31689371c9d4SSatish Balay     *testReal = prob->testReal;
31699371c9d4SSatish Balay   }
31709371c9d4SSatish Balay   if (testDerReal) {
31719371c9d4SSatish Balay     PetscValidPointer(testDerReal, 6);
31729371c9d4SSatish Balay     *testDerReal = prob->testDerReal;
31739371c9d4SSatish Balay   }
31742764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
31752764a2aaSMatthew G. Knepley }
31762764a2aaSMatthew G. Knepley 
317758ebd649SToby Isaac /*@C
31786aad120cSJose E. Roman   PetscDSAddBoundary - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performed, using the kernels from PetscDSSetBdResidual().
317958ebd649SToby Isaac 
3180783e2ec8SMatthew G. Knepley   Collective on ds
3181783e2ec8SMatthew G. Knepley 
318258ebd649SToby Isaac   Input Parameters:
318358ebd649SToby Isaac + ds       - The PetscDS object
31842d47a189SJulian Andrej . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
318558ebd649SToby Isaac . name     - The BC name
318645480ffeSMatthew G. Knepley . label    - The label defining constrained points
318745480ffeSMatthew G. Knepley . Nv       - The number of DMLabel values for constrained points
318845480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
318958ebd649SToby Isaac . field    - The field to constrain
319045480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
319158ebd649SToby Isaac . comps    - An array of constrained component numbers
319258ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3193a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
319458ebd649SToby Isaac - ctx      - An optional user context for bcFunc
319558ebd649SToby Isaac 
319645480ffeSMatthew G. Knepley   Output Parameters:
319745480ffeSMatthew G. Knepley - bd       - The boundary number
319845480ffeSMatthew G. Knepley 
319958ebd649SToby Isaac   Options Database Keys:
320058ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
320158ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
320258ebd649SToby Isaac 
320356cf3b9cSMatthew G. Knepley   Note:
320456cf3b9cSMatthew G. Knepley   Both bcFunc abd bcFunc_t will depend on the boundary condition type. If the type if DM_BC_ESSENTIAL, Then the calling sequence is:
320556cf3b9cSMatthew G. Knepley 
320656cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
320756cf3b9cSMatthew G. Knepley 
320856cf3b9cSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
320956cf3b9cSMatthew G. Knepley 
321056cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
321156cf3b9cSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
321256cf3b9cSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
321356cf3b9cSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
321456cf3b9cSMatthew G. Knepley 
321556cf3b9cSMatthew G. Knepley + dim - the spatial dimension
321656cf3b9cSMatthew G. Knepley . Nf - the number of fields
321756cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
321856cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
321956cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point
322056cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
322156cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
322256cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
322356cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
322456cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
322556cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
322656cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
322756cf3b9cSMatthew G. Knepley . t - current time
322856cf3b9cSMatthew G. Knepley . x - coordinates of the current point
322956cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters
323056cf3b9cSMatthew G. Knepley . constants - constant parameters
323156cf3b9cSMatthew G. Knepley - bcval - output values at the current point
323256cf3b9cSMatthew G. Knepley 
323358ebd649SToby Isaac   Level: developer
323458ebd649SToby Isaac 
3235db781477SPatrick Sanan .seealso: `PetscDSAddBoundaryByName()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()`
323658ebd649SToby Isaac @*/
3237*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], DMLabel label, PetscInt Nv, const PetscInt values[], PetscInt field, PetscInt Nc, const PetscInt comps[], void (*bcFunc)(void), void (*bcFunc_t)(void), void *ctx, PetscInt *bd)
3238*d71ae5a4SJacob Faibussowitsch {
323945480ffeSMatthew G. Knepley   DSBoundary  head = ds->boundary, b;
324045480ffeSMatthew G. Knepley   PetscInt    n    = 0;
324145480ffeSMatthew G. Knepley   const char *lname;
324258ebd649SToby Isaac 
324358ebd649SToby Isaac   PetscFunctionBegin;
324458ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3245783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
324645480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
324745480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4);
324845480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
324945480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
325045480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
3251d57bb9dbSMatthew G. Knepley   if (Nc > 0) {
3252d57bb9dbSMatthew G. Knepley     PetscInt *fcomps;
3253d57bb9dbSMatthew G. Knepley     PetscInt  c;
3254d57bb9dbSMatthew G. Knepley 
32559566063dSJacob Faibussowitsch     PetscCall(PetscDSGetComponents(ds, &fcomps));
325663a3b9bcSJacob Faibussowitsch     PetscCheck(Nc <= fcomps[field], PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_OUTOFRANGE, "Number of constrained components %" PetscInt_FMT " > %" PetscInt_FMT " components for field %" PetscInt_FMT, Nc, fcomps[field], field);
3257d57bb9dbSMatthew G. Knepley     for (c = 0; c < Nc; ++c) {
32581dca8a05SBarry Smith       PetscCheck(comps[c] >= 0 && comps[c] < fcomps[field], PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_OUTOFRANGE, "Constrained component[%" PetscInt_FMT "] %" PetscInt_FMT " not in [0, %" PetscInt_FMT ") components for field %" PetscInt_FMT, c, comps[c], fcomps[field], field);
3259d57bb9dbSMatthew G. Knepley     }
3260d57bb9dbSMatthew G. Knepley   }
32619566063dSJacob Faibussowitsch   PetscCall(PetscNew(&b));
32629566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(name, (char **)&b->name));
32639566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf));
32649566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf));
32659566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nv, &b->values));
32669566063dSJacob Faibussowitsch   if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv));
32679566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nc, &b->comps));
32689566063dSJacob Faibussowitsch   if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc));
32699566063dSJacob Faibussowitsch   PetscCall(PetscObjectGetName((PetscObject)label, &lname));
32709566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(lname, (char **)&b->lname));
3271f971fd6bSMatthew G. Knepley   b->type   = type;
327245480ffeSMatthew G. Knepley   b->label  = label;
327345480ffeSMatthew G. Knepley   b->Nv     = Nv;
327458ebd649SToby Isaac   b->field  = field;
327545480ffeSMatthew G. Knepley   b->Nc     = Nc;
327658ebd649SToby Isaac   b->func   = bcFunc;
327756cf3b9cSMatthew G. Knepley   b->func_t = bcFunc_t;
327858ebd649SToby Isaac   b->ctx    = ctx;
327945480ffeSMatthew G. Knepley   b->next   = NULL;
328045480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
328145480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
328245480ffeSMatthew G. Knepley   while (head) {
328345480ffeSMatthew G. Knepley     if (!head->next) {
328445480ffeSMatthew G. Knepley       head->next = b;
328545480ffeSMatthew G. Knepley       head       = b;
328645480ffeSMatthew G. Knepley     }
328745480ffeSMatthew G. Knepley     head = head->next;
328845480ffeSMatthew G. Knepley     ++n;
328945480ffeSMatthew G. Knepley   }
32909371c9d4SSatish Balay   if (bd) {
32919371c9d4SSatish Balay     PetscValidIntPointer(bd, 13);
32929371c9d4SSatish Balay     *bd = n;
32939371c9d4SSatish Balay   }
329445480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
329545480ffeSMatthew G. Knepley }
329645480ffeSMatthew G. Knepley 
329745480ffeSMatthew G. Knepley /*@C
32986aad120cSJose E. Roman   PetscDSAddBoundaryByName - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performed, using the kernels from PetscDSSetBdResidual().
329945480ffeSMatthew G. Knepley 
330045480ffeSMatthew G. Knepley   Collective on ds
330145480ffeSMatthew G. Knepley 
330245480ffeSMatthew G. Knepley   Input Parameters:
330345480ffeSMatthew G. Knepley + ds       - The PetscDS object
330445480ffeSMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
330545480ffeSMatthew G. Knepley . name     - The BC name
330645480ffeSMatthew G. Knepley . lname    - The naem of the label defining constrained points
330745480ffeSMatthew G. Knepley . Nv       - The number of DMLabel values for constrained points
330845480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
330945480ffeSMatthew G. Knepley . field    - The field to constrain
331045480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
331145480ffeSMatthew G. Knepley . comps    - An array of constrained component numbers
331245480ffeSMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3313a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
331445480ffeSMatthew G. Knepley - ctx      - An optional user context for bcFunc
331545480ffeSMatthew G. Knepley 
331645480ffeSMatthew G. Knepley   Output Parameters:
331745480ffeSMatthew G. Knepley - bd       - The boundary number
331845480ffeSMatthew G. Knepley 
331945480ffeSMatthew G. Knepley   Options Database Keys:
332045480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids
332145480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components
332245480ffeSMatthew G. Knepley 
332345480ffeSMatthew G. Knepley   Note:
332445480ffeSMatthew G. Knepley   This function should only be used with DMForest currently, since labels cannot be defined before the underlygin Plex is built.
332545480ffeSMatthew G. Knepley 
332645480ffeSMatthew G. Knepley   Both bcFunc abd bcFunc_t will depend on the boundary condition type. If the type if DM_BC_ESSENTIAL, Then the calling sequence is:
332745480ffeSMatthew G. Knepley 
332845480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
332945480ffeSMatthew G. Knepley 
333045480ffeSMatthew G. Knepley   If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is:
333145480ffeSMatthew G. Knepley 
333245480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
333345480ffeSMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
333445480ffeSMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
333545480ffeSMatthew G. Knepley $        PetscReal time, const PetscReal x[], PetscScalar bcval[])
333645480ffeSMatthew G. Knepley 
333745480ffeSMatthew G. Knepley + dim - the spatial dimension
333845480ffeSMatthew G. Knepley . Nf - the number of fields
333945480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
334045480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
334145480ffeSMatthew G. Knepley . u - each field evaluated at the current point
334245480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
334345480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
334445480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
334545480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
334645480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
334745480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
334845480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
334945480ffeSMatthew G. Knepley . t - current time
335045480ffeSMatthew G. Knepley . x - coordinates of the current point
335145480ffeSMatthew G. Knepley . numConstants - number of constant parameters
335245480ffeSMatthew G. Knepley . constants - constant parameters
335345480ffeSMatthew G. Knepley - bcval - output values at the current point
335445480ffeSMatthew G. Knepley 
335545480ffeSMatthew G. Knepley   Level: developer
335645480ffeSMatthew G. Knepley 
3357db781477SPatrick Sanan .seealso: `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()`
335845480ffeSMatthew G. Knepley @*/
3359*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSAddBoundaryByName(PetscDS ds, DMBoundaryConditionType type, const char name[], const char lname[], PetscInt Nv, const PetscInt values[], PetscInt field, PetscInt Nc, const PetscInt comps[], void (*bcFunc)(void), void (*bcFunc_t)(void), void *ctx, PetscInt *bd)
3360*d71ae5a4SJacob Faibussowitsch {
336145480ffeSMatthew G. Knepley   DSBoundary head = ds->boundary, b;
336245480ffeSMatthew G. Knepley   PetscInt   n    = 0;
336345480ffeSMatthew G. Knepley 
336445480ffeSMatthew G. Knepley   PetscFunctionBegin;
336545480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
336645480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
336745480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
336845480ffeSMatthew G. Knepley   PetscValidCharPointer(lname, 4);
336945480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
337045480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
337145480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
33729566063dSJacob Faibussowitsch   PetscCall(PetscNew(&b));
33739566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(name, (char **)&b->name));
33749566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf));
33759566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf));
33769566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nv, &b->values));
33779566063dSJacob Faibussowitsch   if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv));
33789566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nc, &b->comps));
33799566063dSJacob Faibussowitsch   if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc));
33809566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(lname, (char **)&b->lname));
338145480ffeSMatthew G. Knepley   b->type   = type;
338245480ffeSMatthew G. Knepley   b->label  = NULL;
338345480ffeSMatthew G. Knepley   b->Nv     = Nv;
338445480ffeSMatthew G. Knepley   b->field  = field;
338545480ffeSMatthew G. Knepley   b->Nc     = Nc;
338645480ffeSMatthew G. Knepley   b->func   = bcFunc;
338745480ffeSMatthew G. Knepley   b->func_t = bcFunc_t;
338845480ffeSMatthew G. Knepley   b->ctx    = ctx;
338945480ffeSMatthew G. Knepley   b->next   = NULL;
339045480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
339145480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
339245480ffeSMatthew G. Knepley   while (head) {
339345480ffeSMatthew G. Knepley     if (!head->next) {
339445480ffeSMatthew G. Knepley       head->next = b;
339545480ffeSMatthew G. Knepley       head       = b;
339645480ffeSMatthew G. Knepley     }
339745480ffeSMatthew G. Knepley     head = head->next;
339845480ffeSMatthew G. Knepley     ++n;
339945480ffeSMatthew G. Knepley   }
34009371c9d4SSatish Balay   if (bd) {
34019371c9d4SSatish Balay     PetscValidIntPointer(bd, 13);
34029371c9d4SSatish Balay     *bd = n;
34039371c9d4SSatish Balay   }
340458ebd649SToby Isaac   PetscFunctionReturn(0);
340558ebd649SToby Isaac }
340658ebd649SToby Isaac 
3407b67eacb3SMatthew G. Knepley /*@C
34086aad120cSJose E. Roman   PetscDSUpdateBoundary - Change a boundary condition for the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performed, using the kernels from PetscDSSetBdResidual().
3409b67eacb3SMatthew G. Knepley 
3410b67eacb3SMatthew G. Knepley   Input Parameters:
3411b67eacb3SMatthew G. Knepley + ds       - The PetscDS object
3412b67eacb3SMatthew G. Knepley . bd       - The boundary condition number
3413b67eacb3SMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
3414b67eacb3SMatthew G. Knepley . name     - The BC name
341545480ffeSMatthew G. Knepley . label    - The label defining constrained points
341645480ffeSMatthew G. Knepley . Nv       - The number of DMLabel ids for constrained points
341745480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
3418b67eacb3SMatthew G. Knepley . field    - The field to constrain
341945480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
3420b67eacb3SMatthew G. Knepley . comps    - An array of constrained component numbers
3421b67eacb3SMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3422a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
3423b67eacb3SMatthew G. Knepley - ctx      - An optional user context for bcFunc
3424b67eacb3SMatthew G. Knepley 
342556cf3b9cSMatthew G. Knepley   Note:
342656cf3b9cSMatthew G. Knepley   The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from PetscDSGetNumBoundary(). See PetscDSAddBoundary() for a description of the calling sequences for the callbacks.
34279a6efb6aSMatthew G. Knepley 
3428b67eacb3SMatthew G. Knepley   Level: developer
3429b67eacb3SMatthew G. Knepley 
3430db781477SPatrick Sanan .seealso: `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSGetNumBoundary()`
3431b67eacb3SMatthew G. Knepley @*/
3432*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSUpdateBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType type, const char name[], DMLabel label, PetscInt Nv, const PetscInt values[], PetscInt field, PetscInt Nc, const PetscInt comps[], void (*bcFunc)(void), void (*bcFunc_t)(void), void *ctx)
3433*d71ae5a4SJacob Faibussowitsch {
3434b67eacb3SMatthew G. Knepley   DSBoundary b = ds->boundary;
3435b67eacb3SMatthew G. Knepley   PetscInt   n = 0;
3436b67eacb3SMatthew G. Knepley 
3437b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
3438b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3439b67eacb3SMatthew G. Knepley   while (b) {
3440b67eacb3SMatthew G. Knepley     if (n == bd) break;
3441b67eacb3SMatthew G. Knepley     b = b->next;
3442b67eacb3SMatthew G. Knepley     ++n;
3443b67eacb3SMatthew G. Knepley   }
344463a3b9bcSJacob Faibussowitsch   PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n);
3445b67eacb3SMatthew G. Knepley   if (name) {
34469566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->name));
34479566063dSJacob Faibussowitsch     PetscCall(PetscStrallocpy(name, (char **)&b->name));
3448b67eacb3SMatthew G. Knepley   }
3449b67eacb3SMatthew G. Knepley   b->type = type;
345045480ffeSMatthew G. Knepley   if (label) {
345145480ffeSMatthew G. Knepley     const char *name;
345245480ffeSMatthew G. Knepley 
345345480ffeSMatthew G. Knepley     b->label = label;
34549566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->lname));
34559566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetName((PetscObject)label, &name));
34569566063dSJacob Faibussowitsch     PetscCall(PetscStrallocpy(name, (char **)&b->lname));
345745480ffeSMatthew G. Knepley   }
345845480ffeSMatthew G. Knepley   if (Nv >= 0) {
345945480ffeSMatthew G. Knepley     b->Nv = Nv;
34609566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->values));
34619566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(Nv, &b->values));
34629566063dSJacob Faibussowitsch     if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv));
346345480ffeSMatthew G. Knepley   }
346445480ffeSMatthew G. Knepley   if (field >= 0) b->field = field;
346545480ffeSMatthew G. Knepley   if (Nc >= 0) {
346645480ffeSMatthew G. Knepley     b->Nc = Nc;
34679566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->comps));
34689566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(Nc, &b->comps));
34699566063dSJacob Faibussowitsch     if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc));
347045480ffeSMatthew G. Knepley   }
347145480ffeSMatthew G. Knepley   if (bcFunc) b->func = bcFunc;
347245480ffeSMatthew G. Knepley   if (bcFunc_t) b->func_t = bcFunc_t;
347345480ffeSMatthew G. Knepley   if (ctx) b->ctx = ctx;
3474b67eacb3SMatthew G. Knepley   PetscFunctionReturn(0);
3475b67eacb3SMatthew G. Knepley }
3476b67eacb3SMatthew G. Knepley 
347758ebd649SToby Isaac /*@
347858ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
347958ebd649SToby Isaac 
348058ebd649SToby Isaac   Input Parameters:
348158ebd649SToby Isaac . ds - The PetscDS object
348258ebd649SToby Isaac 
348358ebd649SToby Isaac   Output Parameters:
348458ebd649SToby Isaac . numBd - The number of BC
348558ebd649SToby Isaac 
348658ebd649SToby Isaac   Level: intermediate
348758ebd649SToby Isaac 
3488db781477SPatrick Sanan .seealso: `PetscDSAddBoundary()`, `PetscDSGetBoundary()`
348958ebd649SToby Isaac @*/
3490*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
3491*d71ae5a4SJacob Faibussowitsch {
349258ebd649SToby Isaac   DSBoundary b = ds->boundary;
349358ebd649SToby Isaac 
349458ebd649SToby Isaac   PetscFunctionBegin;
349558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3496dadcf809SJacob Faibussowitsch   PetscValidIntPointer(numBd, 2);
349758ebd649SToby Isaac   *numBd = 0;
34989371c9d4SSatish Balay   while (b) {
34999371c9d4SSatish Balay     ++(*numBd);
35009371c9d4SSatish Balay     b = b->next;
35019371c9d4SSatish Balay   }
350258ebd649SToby Isaac   PetscFunctionReturn(0);
350358ebd649SToby Isaac }
350458ebd649SToby Isaac 
350558ebd649SToby Isaac /*@C
35069a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
350758ebd649SToby Isaac 
350858ebd649SToby Isaac   Input Parameters:
350958ebd649SToby Isaac + ds          - The PetscDS object
351058ebd649SToby Isaac - bd          - The BC number
351158ebd649SToby Isaac 
351258ebd649SToby Isaac   Output Parameters:
351345480ffeSMatthew G. Knepley + wf       - The PetscWeakForm holding the pointwise functions
351445480ffeSMatthew G. Knepley . type     - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
351558ebd649SToby Isaac . name     - The BC name
351645480ffeSMatthew G. Knepley . label    - The label defining constrained points
351745480ffeSMatthew G. Knepley . Nv       - The number of DMLabel ids for constrained points
351845480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
351958ebd649SToby Isaac . field    - The field to constrain
352045480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
352158ebd649SToby Isaac . comps    - An array of constrained component numbers
352258ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3523a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values
352458ebd649SToby Isaac - ctx      - An optional user context for bcFunc
352558ebd649SToby Isaac 
352658ebd649SToby Isaac   Options Database Keys:
352758ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
352858ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
352958ebd649SToby Isaac 
353058ebd649SToby Isaac   Level: developer
353158ebd649SToby Isaac 
3532db781477SPatrick Sanan .seealso: `PetscDSAddBoundary()`
353358ebd649SToby Isaac @*/
3534*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, PetscWeakForm *wf, DMBoundaryConditionType *type, const char *name[], DMLabel *label, PetscInt *Nv, const PetscInt *values[], PetscInt *field, PetscInt *Nc, const PetscInt *comps[], void (**func)(void), void (**func_t)(void), void **ctx)
3535*d71ae5a4SJacob Faibussowitsch {
353658ebd649SToby Isaac   DSBoundary b = ds->boundary;
353758ebd649SToby Isaac   PetscInt   n = 0;
353858ebd649SToby Isaac 
353958ebd649SToby Isaac   PetscFunctionBegin;
354058ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
354158ebd649SToby Isaac   while (b) {
354258ebd649SToby Isaac     if (n == bd) break;
354358ebd649SToby Isaac     b = b->next;
354458ebd649SToby Isaac     ++n;
354558ebd649SToby Isaac   }
354663a3b9bcSJacob Faibussowitsch   PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n);
354745480ffeSMatthew G. Knepley   if (wf) {
354845480ffeSMatthew G. Knepley     PetscValidPointer(wf, 3);
354945480ffeSMatthew G. Knepley     *wf = b->wf;
355045480ffeSMatthew G. Knepley   }
3551f971fd6bSMatthew G. Knepley   if (type) {
355245480ffeSMatthew G. Knepley     PetscValidPointer(type, 4);
3553f971fd6bSMatthew G. Knepley     *type = b->type;
355458ebd649SToby Isaac   }
355558ebd649SToby Isaac   if (name) {
355645480ffeSMatthew G. Knepley     PetscValidPointer(name, 5);
355758ebd649SToby Isaac     *name = b->name;
355858ebd649SToby Isaac   }
355945480ffeSMatthew G. Knepley   if (label) {
356045480ffeSMatthew G. Knepley     PetscValidPointer(label, 6);
356145480ffeSMatthew G. Knepley     *label = b->label;
356245480ffeSMatthew G. Knepley   }
356345480ffeSMatthew G. Knepley   if (Nv) {
356445480ffeSMatthew G. Knepley     PetscValidIntPointer(Nv, 7);
356545480ffeSMatthew G. Knepley     *Nv = b->Nv;
356645480ffeSMatthew G. Knepley   }
356745480ffeSMatthew G. Knepley   if (values) {
356845480ffeSMatthew G. Knepley     PetscValidPointer(values, 8);
356945480ffeSMatthew G. Knepley     *values = b->values;
357058ebd649SToby Isaac   }
357158ebd649SToby Isaac   if (field) {
357245480ffeSMatthew G. Knepley     PetscValidIntPointer(field, 9);
357358ebd649SToby Isaac     *field = b->field;
357458ebd649SToby Isaac   }
357545480ffeSMatthew G. Knepley   if (Nc) {
357645480ffeSMatthew G. Knepley     PetscValidIntPointer(Nc, 10);
357745480ffeSMatthew G. Knepley     *Nc = b->Nc;
357858ebd649SToby Isaac   }
357958ebd649SToby Isaac   if (comps) {
358045480ffeSMatthew G. Knepley     PetscValidPointer(comps, 11);
358158ebd649SToby Isaac     *comps = b->comps;
358258ebd649SToby Isaac   }
358358ebd649SToby Isaac   if (func) {
358445480ffeSMatthew G. Knepley     PetscValidPointer(func, 12);
358558ebd649SToby Isaac     *func = b->func;
358658ebd649SToby Isaac   }
358756cf3b9cSMatthew G. Knepley   if (func_t) {
358845480ffeSMatthew G. Knepley     PetscValidPointer(func_t, 13);
358956cf3b9cSMatthew G. Knepley     *func_t = b->func_t;
359056cf3b9cSMatthew G. Knepley   }
359158ebd649SToby Isaac   if (ctx) {
359245480ffeSMatthew G. Knepley     PetscValidPointer(ctx, 14);
359358ebd649SToby Isaac     *ctx = b->ctx;
359458ebd649SToby Isaac   }
359558ebd649SToby Isaac   PetscFunctionReturn(0);
359658ebd649SToby Isaac }
359758ebd649SToby Isaac 
3598*d71ae5a4SJacob Faibussowitsch static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew)
3599*d71ae5a4SJacob Faibussowitsch {
360045480ffeSMatthew G. Knepley   PetscFunctionBegin;
36019566063dSJacob Faibussowitsch   PetscCall(PetscNew(bNew));
36029566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf));
36039566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCopy(b->wf, (*bNew)->wf));
36049566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(b->name, (char **)&((*bNew)->name)));
36059566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(b->lname, (char **)&((*bNew)->lname)));
360645480ffeSMatthew G. Knepley   (*bNew)->type  = b->type;
360745480ffeSMatthew G. Knepley   (*bNew)->label = b->label;
360845480ffeSMatthew G. Knepley   (*bNew)->Nv    = b->Nv;
36099566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(b->Nv, &(*bNew)->values));
36109566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy((*bNew)->values, b->values, b->Nv));
361145480ffeSMatthew G. Knepley   (*bNew)->field = b->field;
361245480ffeSMatthew G. Knepley   (*bNew)->Nc    = b->Nc;
36139566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(b->Nc, &(*bNew)->comps));
36149566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy((*bNew)->comps, b->comps, b->Nc));
361545480ffeSMatthew G. Knepley   (*bNew)->func   = b->func;
361645480ffeSMatthew G. Knepley   (*bNew)->func_t = b->func_t;
361745480ffeSMatthew G. Knepley   (*bNew)->ctx    = b->ctx;
361845480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
361945480ffeSMatthew G. Knepley }
362045480ffeSMatthew G. Knepley 
36219252d075SMatthew G. Knepley /*@
36229252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
36239252d075SMatthew G. Knepley 
36249252d075SMatthew G. Knepley   Not collective
36259252d075SMatthew G. Knepley 
362636951cb5SMatthew G. Knepley   Input Parameters:
362736951cb5SMatthew G. Knepley + ds        - The source PetscDS object
362836951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields
362936951cb5SMatthew G. Knepley - fields    - The selected fields, or NULL for all fields
36309252d075SMatthew G. Knepley 
36319252d075SMatthew G. Knepley   Output Parameter:
363236951cb5SMatthew G. Knepley . newds     - The target PetscDS, now with a copy of the boundary conditions
36339252d075SMatthew G. Knepley 
36349252d075SMatthew G. Knepley   Level: intermediate
36359252d075SMatthew G. Knepley 
3636db781477SPatrick Sanan .seealso: `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
36379252d075SMatthew G. Knepley @*/
3638*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds)
3639*d71ae5a4SJacob Faibussowitsch {
364045480ffeSMatthew G. Knepley   DSBoundary b, *lastnext;
3641dff059c6SToby Isaac 
3642dff059c6SToby Isaac   PetscFunctionBegin;
364336951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
364436951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4);
364536951cb5SMatthew G. Knepley   if (ds == newds) PetscFunctionReturn(0);
36469566063dSJacob Faibussowitsch   PetscCall(PetscDSDestroyBoundary(newds));
364736951cb5SMatthew G. Knepley   lastnext = &(newds->boundary);
364836951cb5SMatthew G. Knepley   for (b = ds->boundary; b; b = b->next) {
3649dff059c6SToby Isaac     DSBoundary bNew;
365036951cb5SMatthew G. Knepley     PetscInt   fieldNew = -1;
3651dff059c6SToby Isaac 
365236951cb5SMatthew G. Knepley     if (numFields > 0 && fields) {
365336951cb5SMatthew G. Knepley       PetscInt f;
365436951cb5SMatthew G. Knepley 
36559371c9d4SSatish Balay       for (f = 0; f < numFields; ++f)
36569371c9d4SSatish Balay         if (b->field == fields[f]) break;
365736951cb5SMatthew G. Knepley       if (f == numFields) continue;
365836951cb5SMatthew G. Knepley       fieldNew = f;
365936951cb5SMatthew G. Knepley     }
36609566063dSJacob Faibussowitsch     PetscCall(DSBoundaryDuplicate_Internal(b, &bNew));
366136951cb5SMatthew G. Knepley     bNew->field = fieldNew < 0 ? b->field : fieldNew;
3662dff059c6SToby Isaac     *lastnext   = bNew;
3663dff059c6SToby Isaac     lastnext    = &(bNew->next);
3664dff059c6SToby Isaac   }
3665dff059c6SToby Isaac   PetscFunctionReturn(0);
3666dff059c6SToby Isaac }
3667dff059c6SToby Isaac 
36686c1eb96dSMatthew G. Knepley /*@
366945480ffeSMatthew G. Knepley   PetscDSDestroyBoundary - Remove all DMBoundary objects from the PetscDS
367045480ffeSMatthew G. Knepley 
367145480ffeSMatthew G. Knepley   Not collective
367245480ffeSMatthew G. Knepley 
367345480ffeSMatthew G. Knepley   Input Parameter:
367445480ffeSMatthew G. Knepley . ds - The PetscDS object
367545480ffeSMatthew G. Knepley 
367645480ffeSMatthew G. Knepley   Level: intermediate
367745480ffeSMatthew G. Knepley 
3678db781477SPatrick Sanan .seealso: `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`
367945480ffeSMatthew G. Knepley @*/
3680*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSDestroyBoundary(PetscDS ds)
3681*d71ae5a4SJacob Faibussowitsch {
368245480ffeSMatthew G. Knepley   DSBoundary next = ds->boundary;
368345480ffeSMatthew G. Knepley 
368445480ffeSMatthew G. Knepley   PetscFunctionBegin;
368545480ffeSMatthew G. Knepley   while (next) {
368645480ffeSMatthew G. Knepley     DSBoundary b = next;
368745480ffeSMatthew G. Knepley 
368845480ffeSMatthew G. Knepley     next = b->next;
36899566063dSJacob Faibussowitsch     PetscCall(PetscWeakFormDestroy(&b->wf));
36909566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->name));
36919566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->lname));
36929566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->values));
36939566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->comps));
36949566063dSJacob Faibussowitsch     PetscCall(PetscFree(b));
369545480ffeSMatthew G. Knepley   }
369645480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
369745480ffeSMatthew G. Knepley }
369845480ffeSMatthew G. Knepley 
369945480ffeSMatthew G. Knepley /*@
37006c1eb96dSMatthew G. Knepley   PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout
37016c1eb96dSMatthew G. Knepley 
37026c1eb96dSMatthew G. Knepley   Not collective
37036c1eb96dSMatthew G. Knepley 
3704d8d19677SJose E. Roman   Input Parameters:
37056c1eb96dSMatthew G. Knepley + prob - The PetscDS object
37066c1eb96dSMatthew G. Knepley . numFields - Number of new fields
37076c1eb96dSMatthew G. Knepley - fields - Old field number for each new field
37086c1eb96dSMatthew G. Knepley 
37096c1eb96dSMatthew G. Knepley   Output Parameter:
37106c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy
37116c1eb96dSMatthew G. Knepley 
37126c1eb96dSMatthew G. Knepley   Level: intermediate
37136c1eb96dSMatthew G. Knepley 
3714db781477SPatrick Sanan .seealso: `PetscDSSelectEquations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
37156c1eb96dSMatthew G. Knepley @*/
3716*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
3717*d71ae5a4SJacob Faibussowitsch {
37186c1eb96dSMatthew G. Knepley   PetscInt Nf, Nfn, fn;
37196c1eb96dSMatthew G. Knepley 
37206c1eb96dSMatthew G. Knepley   PetscFunctionBegin;
37216c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3722dadcf809SJacob Faibussowitsch   if (fields) PetscValidIntPointer(fields, 3);
37236c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
37249566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
37259566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(newprob, &Nfn));
372645480ffeSMatthew G. Knepley   numFields = numFields < 0 ? Nf : numFields;
37276c1eb96dSMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
37286c1eb96dSMatthew G. Knepley     const PetscInt f = fields ? fields[fn] : fn;
37296c1eb96dSMatthew G. Knepley     PetscObject    disc;
37306c1eb96dSMatthew G. Knepley 
37316c1eb96dSMatthew G. Knepley     if (f >= Nf) continue;
37329566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(prob, f, &disc));
37339566063dSJacob Faibussowitsch     PetscCall(PetscDSSetDiscretization(newprob, fn, disc));
37346c1eb96dSMatthew G. Knepley   }
37356c1eb96dSMatthew G. Knepley   PetscFunctionReturn(0);
37366c1eb96dSMatthew G. Knepley }
37376c1eb96dSMatthew G. Knepley 
37386c1eb96dSMatthew G. Knepley /*@
37399252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
37409252d075SMatthew G. Knepley 
37419252d075SMatthew G. Knepley   Not collective
37429252d075SMatthew G. Knepley 
3743d8d19677SJose E. Roman   Input Parameters:
37449252d075SMatthew G. Knepley + prob - The PetscDS object
37459252d075SMatthew G. Knepley . numFields - Number of new fields
37469252d075SMatthew G. Knepley - fields - Old field number for each new field
37479252d075SMatthew G. Knepley 
37489252d075SMatthew G. Knepley   Output Parameter:
37499252d075SMatthew G. Knepley . newprob - The PetscDS copy
37509252d075SMatthew G. Knepley 
37519252d075SMatthew G. Knepley   Level: intermediate
37529252d075SMatthew G. Knepley 
3753db781477SPatrick Sanan .seealso: `PetscDSSelectDiscretizations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
37549252d075SMatthew G. Knepley @*/
3755*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
3756*d71ae5a4SJacob Faibussowitsch {
37579252d075SMatthew G. Knepley   PetscInt Nf, Nfn, fn, gn;
37589252d075SMatthew G. Knepley 
37599252d075SMatthew G. Knepley   PetscFunctionBegin;
37609252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3761dadcf809SJacob Faibussowitsch   if (fields) PetscValidIntPointer(fields, 3);
37629252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
37639566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
37649566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(newprob, &Nfn));
376563a3b9bcSJacob Faibussowitsch   PetscCheck(numFields <= Nfn, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_SIZ, "Number of fields %" PetscInt_FMT " to transfer must not be greater then the total number of fields %" PetscInt_FMT, numFields, Nfn);
37669252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
37679252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
37689252d075SMatthew G. Knepley     PetscPointFunc   obj;
37699252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
37709252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
37719252d075SMatthew G. Knepley     PetscRiemannFunc r;
37729252d075SMatthew G. Knepley 
3773c52f1e13SMatthew G. Knepley     if (f >= Nf) continue;
37749566063dSJacob Faibussowitsch     PetscCall(PetscDSGetObjective(prob, f, &obj));
37759566063dSJacob Faibussowitsch     PetscCall(PetscDSGetResidual(prob, f, &f0, &f1));
37769566063dSJacob Faibussowitsch     PetscCall(PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd));
37779566063dSJacob Faibussowitsch     PetscCall(PetscDSGetRiemannSolver(prob, f, &r));
37789566063dSJacob Faibussowitsch     PetscCall(PetscDSSetObjective(newprob, fn, obj));
37799566063dSJacob Faibussowitsch     PetscCall(PetscDSSetResidual(newprob, fn, f0, f1));
37809566063dSJacob Faibussowitsch     PetscCall(PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd));
37819566063dSJacob Faibussowitsch     PetscCall(PetscDSSetRiemannSolver(newprob, fn, r));
37829252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
37839252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
37849252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
37859252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
37869252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
37879252d075SMatthew G. Knepley 
3788c52f1e13SMatthew G. Knepley       if (g >= Nf) continue;
37899566063dSJacob Faibussowitsch       PetscCall(PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3));
37909566063dSJacob Faibussowitsch       PetscCall(PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p));
37919566063dSJacob Faibussowitsch       PetscCall(PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd));
37929566063dSJacob Faibussowitsch       PetscCall(PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3));
37939566063dSJacob Faibussowitsch       PetscCall(PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p));
37949566063dSJacob Faibussowitsch       PetscCall(PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd));
37959252d075SMatthew G. Knepley     }
37969252d075SMatthew G. Knepley   }
37979252d075SMatthew G. Knepley   PetscFunctionReturn(0);
37989252d075SMatthew G. Knepley }
37999252d075SMatthew G. Knepley 
3800da51fcedSMatthew G. Knepley /*@
3801da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
3802da51fcedSMatthew G. Knepley 
3803da51fcedSMatthew G. Knepley   Not collective
3804da51fcedSMatthew G. Knepley 
3805da51fcedSMatthew G. Knepley   Input Parameter:
3806da51fcedSMatthew G. Knepley . prob - The PetscDS object
3807da51fcedSMatthew G. Knepley 
3808da51fcedSMatthew G. Knepley   Output Parameter:
3809da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
3810da51fcedSMatthew G. Knepley 
3811da51fcedSMatthew G. Knepley   Level: intermediate
3812da51fcedSMatthew G. Knepley 
3813db781477SPatrick Sanan .seealso: `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
3814da51fcedSMatthew G. Knepley @*/
3815*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
3816*d71ae5a4SJacob Faibussowitsch {
3817b8025e53SMatthew G. Knepley   PetscWeakForm wf, newwf;
38189252d075SMatthew G. Knepley   PetscInt      Nf, Ng;
3819da51fcedSMatthew G. Knepley 
3820da51fcedSMatthew G. Knepley   PetscFunctionBegin;
3821da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3822da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
38239566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
38249566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(newprob, &Ng));
382563a3b9bcSJacob Faibussowitsch   PetscCheck(Nf == Ng, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %" PetscInt_FMT " != %" PetscInt_FMT, Nf, Ng);
38269566063dSJacob Faibussowitsch   PetscCall(PetscDSGetWeakForm(prob, &wf));
38279566063dSJacob Faibussowitsch   PetscCall(PetscDSGetWeakForm(newprob, &newwf));
38289566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCopy(wf, newwf));
38299252d075SMatthew G. Knepley   PetscFunctionReturn(0);
38309252d075SMatthew G. Knepley }
383145480ffeSMatthew G. Knepley 
38329252d075SMatthew G. Knepley /*@
38339252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
3834da51fcedSMatthew G. Knepley 
38359252d075SMatthew G. Knepley   Not collective
38369252d075SMatthew G. Knepley 
38379252d075SMatthew G. Knepley   Input Parameter:
38389252d075SMatthew G. Knepley . prob - The PetscDS object
38399252d075SMatthew G. Knepley 
38409252d075SMatthew G. Knepley   Output Parameter:
38419252d075SMatthew G. Knepley . newprob - The PetscDS copy
38429252d075SMatthew G. Knepley 
38439252d075SMatthew G. Knepley   Level: intermediate
38449252d075SMatthew G. Knepley 
3845db781477SPatrick Sanan .seealso: `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
38469252d075SMatthew G. Knepley @*/
3847*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
3848*d71ae5a4SJacob Faibussowitsch {
38499252d075SMatthew G. Knepley   PetscInt           Nc;
38509252d075SMatthew G. Knepley   const PetscScalar *constants;
38519252d075SMatthew G. Knepley 
38529252d075SMatthew G. Knepley   PetscFunctionBegin;
38539252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
38549252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
38559566063dSJacob Faibussowitsch   PetscCall(PetscDSGetConstants(prob, &Nc, &constants));
38569566063dSJacob Faibussowitsch   PetscCall(PetscDSSetConstants(newprob, Nc, (PetscScalar *)constants));
3857da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
3858da51fcedSMatthew G. Knepley }
3859da51fcedSMatthew G. Knepley 
386045480ffeSMatthew G. Knepley /*@
386145480ffeSMatthew G. Knepley   PetscDSCopyExactSolutions - Copy all exact solutions to the new problem
386245480ffeSMatthew G. Knepley 
386345480ffeSMatthew G. Knepley   Not collective
386445480ffeSMatthew G. Knepley 
386545480ffeSMatthew G. Knepley   Input Parameter:
386645480ffeSMatthew G. Knepley . ds - The PetscDS object
386745480ffeSMatthew G. Knepley 
386845480ffeSMatthew G. Knepley   Output Parameter:
386945480ffeSMatthew G. Knepley . newds - The PetscDS copy
387045480ffeSMatthew G. Knepley 
387145480ffeSMatthew G. Knepley   Level: intermediate
387245480ffeSMatthew G. Knepley 
3873db781477SPatrick Sanan .seealso: `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
387445480ffeSMatthew G. Knepley @*/
3875*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds)
3876*d71ae5a4SJacob Faibussowitsch {
387745480ffeSMatthew G. Knepley   PetscSimplePointFunc sol;
387845480ffeSMatthew G. Knepley   void                *ctx;
387945480ffeSMatthew G. Knepley   PetscInt             Nf, f;
388045480ffeSMatthew G. Knepley 
388145480ffeSMatthew G. Knepley   PetscFunctionBegin;
388245480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
388345480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2);
38849566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(ds, &Nf));
388545480ffeSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
38869566063dSJacob Faibussowitsch     PetscCall(PetscDSGetExactSolution(ds, f, &sol, &ctx));
38879566063dSJacob Faibussowitsch     PetscCall(PetscDSSetExactSolution(newds, f, sol, ctx));
38889566063dSJacob Faibussowitsch     PetscCall(PetscDSGetExactSolutionTimeDerivative(ds, f, &sol, &ctx));
38899566063dSJacob Faibussowitsch     PetscCall(PetscDSSetExactSolutionTimeDerivative(newds, f, sol, ctx));
389045480ffeSMatthew G. Knepley   }
389145480ffeSMatthew G. Knepley   PetscFunctionReturn(0);
389245480ffeSMatthew G. Knepley }
389345480ffeSMatthew G. Knepley 
3894*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
3895*d71ae5a4SJacob Faibussowitsch {
3896df3a45bdSMatthew G. Knepley   PetscInt dim, Nf, f;
3897b1353e8eSMatthew G. Knepley 
3898b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
3899b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3900b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
39019371c9d4SSatish Balay   if (height == 0) {
39029371c9d4SSatish Balay     *subprob = prob;
39039371c9d4SSatish Balay     PetscFunctionReturn(0);
39049371c9d4SSatish Balay   }
39059566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
39069566063dSJacob Faibussowitsch   PetscCall(PetscDSGetSpatialDimension(prob, &dim));
390763a3b9bcSJacob Faibussowitsch   PetscCheck(height <= dim, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_OUTOFRANGE, "DS can only handle height in [0, %" PetscInt_FMT "], not %" PetscInt_FMT, dim, height);
39089566063dSJacob Faibussowitsch   if (!prob->subprobs) PetscCall(PetscCalloc1(dim, &prob->subprobs));
3909df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height - 1]) {
3910b1353e8eSMatthew G. Knepley     PetscInt cdim;
3911b1353e8eSMatthew G. Knepley 
39129566063dSJacob Faibussowitsch     PetscCall(PetscDSCreate(PetscObjectComm((PetscObject)prob), &prob->subprobs[height - 1]));
39139566063dSJacob Faibussowitsch     PetscCall(PetscDSGetCoordinateDimension(prob, &cdim));
39149566063dSJacob Faibussowitsch     PetscCall(PetscDSSetCoordinateDimension(prob->subprobs[height - 1], cdim));
3915b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
3916b1353e8eSMatthew G. Knepley       PetscFE      subfe;
3917b1353e8eSMatthew G. Knepley       PetscObject  obj;
3918b1353e8eSMatthew G. Knepley       PetscClassId id;
3919b1353e8eSMatthew G. Knepley 
39209566063dSJacob Faibussowitsch       PetscCall(PetscDSGetDiscretization(prob, f, &obj));
39219566063dSJacob Faibussowitsch       PetscCall(PetscObjectGetClassId(obj, &id));
39229566063dSJacob Faibussowitsch       if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetHeightSubspace((PetscFE)obj, height, &subfe));
392363a3b9bcSJacob Faibussowitsch       else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %" PetscInt_FMT, f);
39249566063dSJacob Faibussowitsch       PetscCall(PetscDSSetDiscretization(prob->subprobs[height - 1], f, (PetscObject)subfe));
3925b1353e8eSMatthew G. Knepley     }
3926b1353e8eSMatthew G. Knepley   }
3927df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height - 1];
3928b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
3929b1353e8eSMatthew G. Knepley }
3930b1353e8eSMatthew G. Knepley 
3931*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype)
3932*d71ae5a4SJacob Faibussowitsch {
3933c7bd5f0bSMatthew G. Knepley   PetscObject  obj;
3934c7bd5f0bSMatthew G. Knepley   PetscClassId id;
3935c7bd5f0bSMatthew G. Knepley   PetscInt     Nf;
3936c7bd5f0bSMatthew G. Knepley 
3937c7bd5f0bSMatthew G. Knepley   PetscFunctionBegin;
3938c7bd5f0bSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3939665f567fSMatthew G. Knepley   PetscValidPointer(disctype, 3);
3940665f567fSMatthew G. Knepley   *disctype = PETSC_DISC_NONE;
39419566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(ds, &Nf));
394263a3b9bcSJacob Faibussowitsch   PetscCheck(f < Nf, PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_SIZ, "Field %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, Nf);
39439566063dSJacob Faibussowitsch   PetscCall(PetscDSGetDiscretization(ds, f, &obj));
3944665f567fSMatthew G. Knepley   if (obj) {
39459566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetClassId(obj, &id));
3946665f567fSMatthew G. Knepley     if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE;
3947665f567fSMatthew G. Knepley     else *disctype = PETSC_DISC_FV;
3948665f567fSMatthew G. Knepley   }
3949c7bd5f0bSMatthew G. Knepley   PetscFunctionReturn(0);
3950c7bd5f0bSMatthew G. Knepley }
3951c7bd5f0bSMatthew G. Knepley 
3952*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds)
3953*d71ae5a4SJacob Faibussowitsch {
39542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
39559566063dSJacob Faibussowitsch   PetscCall(PetscFree(ds->data));
39562764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
39572764a2aaSMatthew G. Knepley }
39582764a2aaSMatthew G. Knepley 
3959*d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds)
3960*d71ae5a4SJacob Faibussowitsch {
39612764a2aaSMatthew G. Knepley   PetscFunctionBegin;
39626528b96dSMatthew G. Knepley   ds->ops->setfromoptions = NULL;
39636528b96dSMatthew G. Knepley   ds->ops->setup          = NULL;
39646528b96dSMatthew G. Knepley   ds->ops->view           = NULL;
39656528b96dSMatthew G. Knepley   ds->ops->destroy        = PetscDSDestroy_Basic;
39662764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
39672764a2aaSMatthew G. Knepley }
39682764a2aaSMatthew G. Knepley 
39692764a2aaSMatthew G. Knepley /*MC
39702764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
39712764a2aaSMatthew G. Knepley 
39722764a2aaSMatthew G. Knepley   Level: intermediate
39732764a2aaSMatthew G. Knepley 
3974db781477SPatrick Sanan .seealso: `PetscDSType`, `PetscDSCreate()`, `PetscDSSetType()`
39752764a2aaSMatthew G. Knepley M*/
39762764a2aaSMatthew G. Knepley 
3977*d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds)
3978*d71ae5a4SJacob Faibussowitsch {
39792764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
39802764a2aaSMatthew G. Knepley 
39812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
39826528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
39834dfa11a4SJacob Faibussowitsch   PetscCall(PetscNew(&b));
39846528b96dSMatthew G. Knepley   ds->data = b;
39852764a2aaSMatthew G. Knepley 
39869566063dSJacob Faibussowitsch   PetscCall(PetscDSInitialize_Basic(ds));
39872764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
39882764a2aaSMatthew G. Knepley }
3989