xref: /petsc/src/dm/dt/interface/dtds.c (revision c894370662bbe17849383e651b447b48a45de8d9)
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
22dce8aebaSBarry Smith   PetscDSRegister - Adds a new `PetscDS` implementation
232764a2aaSMatthew G. Knepley 
2420f4b53cSBarry Smith   Not Collective; No Fortran Support
252764a2aaSMatthew G. Knepley 
262764a2aaSMatthew G. Knepley   Input Parameters:
2720f4b53cSBarry Smith + sname        - The name of a new user-defined creation routine
2820f4b53cSBarry Smith - function - The creation routine itself
292764a2aaSMatthew G. Knepley 
302764a2aaSMatthew G. Knepley   Sample usage:
312764a2aaSMatthew G. Knepley .vb
322764a2aaSMatthew G. Knepley     PetscDSRegister("my_ds", MyPetscDSCreate);
332764a2aaSMatthew G. Knepley .ve
342764a2aaSMatthew G. Knepley 
352764a2aaSMatthew G. Knepley   Then, your PetscDS type can be chosen with the procedural interface via
362764a2aaSMatthew G. Knepley .vb
372764a2aaSMatthew G. Knepley     PetscDSCreate(MPI_Comm, PetscDS *);
382764a2aaSMatthew G. Knepley     PetscDSSetType(PetscDS, "my_ds");
392764a2aaSMatthew G. Knepley .ve
402764a2aaSMatthew G. Knepley    or at runtime via the option
412764a2aaSMatthew G. Knepley .vb
422764a2aaSMatthew G. Knepley     -petscds_type my_ds
432764a2aaSMatthew G. Knepley .ve
442764a2aaSMatthew G. Knepley 
452764a2aaSMatthew G. Knepley   Level: advanced
462764a2aaSMatthew G. Knepley 
47dce8aebaSBarry Smith   Note:
48dce8aebaSBarry Smith   `PetscDSRegister()` may be called multiple times to add several user-defined `PetscDSs`
49dce8aebaSBarry Smith 
50dce8aebaSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscDSRegisterAll()`, `PetscDSRegisterDestroy()`
512764a2aaSMatthew G. Knepley @*/
52d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
53d71ae5a4SJacob Faibussowitsch {
542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
559566063dSJacob Faibussowitsch   PetscCall(PetscFunctionListAdd(&PetscDSList, sname, function));
563ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
572764a2aaSMatthew G. Knepley }
582764a2aaSMatthew G. Knepley 
592764a2aaSMatthew G. Knepley /*@C
60dce8aebaSBarry Smith   PetscDSSetType - Builds a particular `PetscDS`
612764a2aaSMatthew G. Knepley 
6220f4b53cSBarry Smith   Collective; No Fortran Support
632764a2aaSMatthew G. Knepley 
642764a2aaSMatthew G. Knepley   Input Parameters:
65dce8aebaSBarry Smith + prob - The `PetscDS` object
66dce8aebaSBarry Smith - name - The `PetscDSType`
672764a2aaSMatthew G. Knepley 
682764a2aaSMatthew G. Knepley   Options Database Key:
692764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
702764a2aaSMatthew G. Knepley 
712764a2aaSMatthew G. Knepley   Level: intermediate
722764a2aaSMatthew G. Knepley 
73dce8aebaSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscDSGetType()`, `PetscDSCreate()`
742764a2aaSMatthew G. Knepley @*/
75d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
76d71ae5a4SJacob Faibussowitsch {
772764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
782764a2aaSMatthew G. Knepley   PetscBool match;
792764a2aaSMatthew G. Knepley 
802764a2aaSMatthew G. Knepley   PetscFunctionBegin;
812764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
829566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject)prob, name, &match));
833ba16761SJacob Faibussowitsch   if (match) PetscFunctionReturn(PETSC_SUCCESS);
842764a2aaSMatthew G. Knepley 
859566063dSJacob Faibussowitsch   PetscCall(PetscDSRegisterAll());
869566063dSJacob Faibussowitsch   PetscCall(PetscFunctionListFind(PetscDSList, name, &r));
8728b400f6SJacob Faibussowitsch   PetscCheck(r, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
882764a2aaSMatthew G. Knepley 
89dbbe0bcdSBarry Smith   PetscTryTypeMethod(prob, destroy);
902764a2aaSMatthew G. Knepley   prob->ops->destroy = NULL;
91dbbe0bcdSBarry Smith 
929566063dSJacob Faibussowitsch   PetscCall((*r)(prob));
939566063dSJacob Faibussowitsch   PetscCall(PetscObjectChangeTypeName((PetscObject)prob, name));
943ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
952764a2aaSMatthew G. Knepley }
962764a2aaSMatthew G. Knepley 
972764a2aaSMatthew G. Knepley /*@C
98dce8aebaSBarry Smith   PetscDSGetType - Gets the `PetscDSType` name (as a string) from the `PetscDS`
992764a2aaSMatthew G. Knepley 
10020f4b53cSBarry Smith   Not Collective; No Fortran Support
1012764a2aaSMatthew G. Knepley 
1022764a2aaSMatthew G. Knepley   Input Parameter:
103dce8aebaSBarry Smith . prob  - The `PetscDS`
1042764a2aaSMatthew G. Knepley 
1052764a2aaSMatthew G. Knepley   Output Parameter:
106dce8aebaSBarry Smith . name - The `PetscDSType` name
1072764a2aaSMatthew G. Knepley 
1082764a2aaSMatthew G. Knepley   Level: intermediate
1092764a2aaSMatthew G. Knepley 
110dce8aebaSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscDSSetType()`, `PetscDSCreate()`
1112764a2aaSMatthew G. Knepley @*/
112d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
113d71ae5a4SJacob Faibussowitsch {
1142764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1152764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
116c959eef4SJed Brown   PetscValidPointer(name, 2);
1179566063dSJacob Faibussowitsch   PetscCall(PetscDSRegisterAll());
1182764a2aaSMatthew G. Knepley   *name = ((PetscObject)prob)->type_name;
1193ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1202764a2aaSMatthew G. Knepley }
1212764a2aaSMatthew G. Knepley 
122d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSView_Ascii(PetscDS ds, PetscViewer viewer)
123d71ae5a4SJacob Faibussowitsch {
1247d8a60eaSMatthew G. Knepley   PetscViewerFormat  format;
12597b6e6e8SMatthew G. Knepley   const PetscScalar *constants;
1265fedec97SMatthew G. Knepley   PetscInt           Nf, numConstants, f;
1277d8a60eaSMatthew G. Knepley 
1287d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1299566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(ds, &Nf));
1309566063dSJacob Faibussowitsch   PetscCall(PetscViewerGetFormat(viewer, &format));
13163a3b9bcSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPrintf(viewer, "Discrete System with %" PetscInt_FMT " fields\n", Nf));
1329566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPushTab(viewer));
13363a3b9bcSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPrintf(viewer, "  cell total dim %" PetscInt_FMT " total comp %" PetscInt_FMT "\n", ds->totDim, ds->totComp));
1349566063dSJacob Faibussowitsch   if (ds->isCohesive) PetscCall(PetscViewerASCIIPrintf(viewer, "  cohesive cell\n"));
1355fedec97SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
13640967b3bSMatthew G. Knepley     DSBoundary      b;
1377d8a60eaSMatthew G. Knepley     PetscObject     obj;
1387d8a60eaSMatthew G. Knepley     PetscClassId    id;
139f35450b9SMatthew G. Knepley     PetscQuadrature q;
1407d8a60eaSMatthew G. Knepley     const char     *name;
141f35450b9SMatthew G. Knepley     PetscInt        Nc, Nq, Nqc;
1427d8a60eaSMatthew G. Knepley 
1439566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(ds, f, &obj));
1449566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetClassId(obj, &id));
1459566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetName(obj, &name));
1469566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>"));
1479566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE));
1487d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
1499566063dSJacob Faibussowitsch       PetscCall(PetscFEGetNumComponents((PetscFE)obj, &Nc));
1509566063dSJacob Faibussowitsch       PetscCall(PetscFEGetQuadrature((PetscFE)obj, &q));
1519566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, " FEM"));
1527d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1539566063dSJacob Faibussowitsch       PetscCall(PetscFVGetNumComponents((PetscFV)obj, &Nc));
1549566063dSJacob Faibussowitsch       PetscCall(PetscFVGetQuadrature((PetscFV)obj, &q));
1559566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, " FVM"));
1569371c9d4SSatish Balay     } else SETERRQ(PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %" PetscInt_FMT, f);
15763a3b9bcSJacob Faibussowitsch     if (Nc > 1) PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT " components", Nc));
15863a3b9bcSJacob Faibussowitsch     else PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT " component ", Nc));
1599566063dSJacob Faibussowitsch     if (ds->implicit[f]) PetscCall(PetscViewerASCIIPrintf(viewer, " (implicit)"));
1609566063dSJacob Faibussowitsch     else PetscCall(PetscViewerASCIIPrintf(viewer, " (explicit)"));
1613e60c2a6SMatthew G. Knepley     if (q) {
1629566063dSJacob Faibussowitsch       PetscCall(PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL));
16363a3b9bcSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, " (Nq %" PetscInt_FMT " Nqc %" PetscInt_FMT ")", Nq, Nqc));
1643e60c2a6SMatthew G. Knepley     }
16563a3b9bcSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT "-jet", ds->jetDegree[f]));
1669566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, "\n"));
1679566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE));
1689566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPushTab(viewer));
1699566063dSJacob Faibussowitsch     if (id == PETSCFE_CLASSID) PetscCall(PetscFEView((PetscFE)obj, viewer));
1709566063dSJacob Faibussowitsch     else if (id == PETSCFV_CLASSID) PetscCall(PetscFVView((PetscFV)obj, viewer));
1719566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPopTab(viewer));
17240967b3bSMatthew G. Knepley 
1735fedec97SMatthew G. Knepley     for (b = ds->boundary; b; b = b->next) {
17406ad1575SMatthew G. Knepley       char    *name;
17540967b3bSMatthew G. Knepley       PetscInt c, i;
17640967b3bSMatthew G. Knepley 
17740967b3bSMatthew G. Knepley       if (b->field != f) continue;
1789566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPushTab(viewer));
1799566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->lname, DMBoundaryConditionTypes[b->type]));
18045480ffeSMatthew G. Knepley       if (!b->Nc) {
1819566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIPrintf(viewer, "  all components\n"));
18240967b3bSMatthew G. Knepley       } else {
1839566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIPrintf(viewer, "  components: "));
1849566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE));
18545480ffeSMatthew G. Knepley         for (c = 0; c < b->Nc; ++c) {
1869566063dSJacob Faibussowitsch           if (c > 0) PetscCall(PetscViewerASCIIPrintf(viewer, ", "));
18763a3b9bcSJacob Faibussowitsch           PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT, b->comps[c]));
18840967b3bSMatthew G. Knepley         }
1899566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIPrintf(viewer, "\n"));
1909566063dSJacob Faibussowitsch         PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE));
19140967b3bSMatthew G. Knepley       }
1929566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, "  values: "));
1939566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE));
19445480ffeSMatthew G. Knepley       for (i = 0; i < b->Nv; ++i) {
1959566063dSJacob Faibussowitsch         if (i > 0) PetscCall(PetscViewerASCIIPrintf(viewer, ", "));
19663a3b9bcSJacob Faibussowitsch         PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT, b->values[i]));
19740967b3bSMatthew G. Knepley       }
1989566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, "\n"));
1999566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE));
20015943bb8SPierre Jolivet #if defined(__clang__)
2011c7e414eSJacob Faibussowitsch       PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN("-Wformat-pedantic");
20215943bb8SPierre Jolivet #elif defined(__GNUC__) || defined(__GNUG__)
2031c7e414eSJacob Faibussowitsch       PETSC_PRAGMA_DIAGNOSTIC_IGNORED_BEGIN("-Wformat");
20415943bb8SPierre Jolivet #endif
2058e0d8d9cSMatthew G. Knepley       if (b->func) {
2069566063dSJacob Faibussowitsch         PetscCall(PetscDLAddr(b->func, &name));
2079566063dSJacob Faibussowitsch         if (name) PetscCall(PetscViewerASCIIPrintf(viewer, "  func: %s\n", name));
2089566063dSJacob Faibussowitsch         else PetscCall(PetscViewerASCIIPrintf(viewer, "  func: %p\n", b->func));
2099566063dSJacob Faibussowitsch         PetscCall(PetscFree(name));
2108e0d8d9cSMatthew G. Knepley       }
2118e0d8d9cSMatthew G. Knepley       if (b->func_t) {
2129566063dSJacob Faibussowitsch         PetscCall(PetscDLAddr(b->func_t, &name));
2139566063dSJacob Faibussowitsch         if (name) PetscCall(PetscViewerASCIIPrintf(viewer, "  func_t: %s\n", name));
2149566063dSJacob Faibussowitsch         else PetscCall(PetscViewerASCIIPrintf(viewer, "  func_t: %p\n", b->func_t));
2159566063dSJacob Faibussowitsch         PetscCall(PetscFree(name));
2168e0d8d9cSMatthew G. Knepley       }
2171c7e414eSJacob Faibussowitsch       PETSC_PRAGMA_DIAGNOSTIC_IGNORED_END();
2189566063dSJacob Faibussowitsch       PetscCall(PetscWeakFormView(b->wf, viewer));
2199566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPopTab(viewer));
22040967b3bSMatthew G. Knepley     }
2217d8a60eaSMatthew G. Knepley   }
2229566063dSJacob Faibussowitsch   PetscCall(PetscDSGetConstants(ds, &numConstants, &constants));
22397b6e6e8SMatthew G. Knepley   if (numConstants) {
22463a3b9bcSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " constants\n", numConstants));
2259566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPushTab(viewer));
2269566063dSJacob Faibussowitsch     for (f = 0; f < numConstants; ++f) PetscCall(PetscViewerASCIIPrintf(viewer, "%g\n", (double)PetscRealPart(constants[f])));
2279566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPopTab(viewer));
22897b6e6e8SMatthew G. Knepley   }
2299566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormView(ds->wf, viewer));
2309566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPopTab(viewer));
2313ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2327d8a60eaSMatthew G. Knepley }
2337d8a60eaSMatthew G. Knepley 
2342764a2aaSMatthew G. Knepley /*@C
235dce8aebaSBarry Smith    PetscDSViewFromOptions - View a `PetscDS` based on values in the options database
236fe2efc57SMark 
23720f4b53cSBarry Smith    Collective
238fe2efc57SMark 
239fe2efc57SMark    Input Parameters:
240dce8aebaSBarry Smith +  A - the `PetscDS` object
24120f4b53cSBarry Smith .  obj - Optional object that provides the options prefix used in the search
242736c3998SJose E. Roman -  name - command line option
243fe2efc57SMark 
244fe2efc57SMark    Level: intermediate
245dce8aebaSBarry Smith 
246dce8aebaSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscDSView()`, `PetscObjectViewFromOptions()`, `PetscDSCreate()`
247fe2efc57SMark @*/
248d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSViewFromOptions(PetscDS A, PetscObject obj, const char name[])
249d71ae5a4SJacob Faibussowitsch {
250fe2efc57SMark   PetscFunctionBegin;
251fe2efc57SMark   PetscValidHeaderSpecific(A, PETSCDS_CLASSID, 1);
2529566063dSJacob Faibussowitsch   PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name));
2533ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
254fe2efc57SMark }
255fe2efc57SMark 
256fe2efc57SMark /*@C
257dce8aebaSBarry Smith   PetscDSView - Views a `PetscDS`
2582764a2aaSMatthew G. Knepley 
25920f4b53cSBarry Smith   Collective
2602764a2aaSMatthew G. Knepley 
261d8d19677SJose E. Roman   Input Parameters:
262dce8aebaSBarry Smith + prob - the `PetscDS` object to view
2632764a2aaSMatthew G. Knepley - v  - the viewer
2642764a2aaSMatthew G. Knepley 
2652764a2aaSMatthew G. Knepley   Level: developer
2662764a2aaSMatthew G. Knepley 
26720f4b53cSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscViewer`, `PetscDSDestroy()`, `PetscDSViewFromOptions()`
2682764a2aaSMatthew G. Knepley @*/
269d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
270d71ae5a4SJacob 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);
2803ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2812764a2aaSMatthew G. Knepley }
2822764a2aaSMatthew G. Knepley 
2832764a2aaSMatthew G. Knepley /*@
284dce8aebaSBarry Smith   PetscDSSetFromOptions - sets parameters in a `PetscDS` from the options database
2852764a2aaSMatthew G. Knepley 
28620f4b53cSBarry Smith   Collective
2872764a2aaSMatthew G. Knepley 
2882764a2aaSMatthew G. Knepley   Input Parameter:
289dce8aebaSBarry Smith . prob - the `PetscDS` object to set options for
2902764a2aaSMatthew G. Knepley 
291dce8aebaSBarry Smith   Options Database Keys:
292dce8aebaSBarry Smith + -petscds_type <type>     - Set the `PetscDS` type
293dce8aebaSBarry Smith . -petscds_view <view opt> - View the `PetscDS`
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 
298dce8aebaSBarry Smith   Level: intermediate
2992764a2aaSMatthew G. Knepley 
300dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSView()`
3012764a2aaSMatthew G. Knepley @*/
302d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
303d71ae5a4SJacob 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));
35212fc5b22SMatthew G. Knepley   PetscCall(PetscOptionsBool("-petscds_force_quad", "Discrete System", "PetscDSSetForceQuad", prob->forceQuad, &prob->forceQuad, &flg));
353dbbe0bcdSBarry Smith   PetscTryTypeMethod(prob, setfromoptions);
3542764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
355dbbe0bcdSBarry Smith   PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)prob, PetscOptionsObject));
356d0609cedSBarry Smith   PetscOptionsEnd();
3579566063dSJacob Faibussowitsch   if (prob->Nf) PetscCall(PetscDSViewFromOptions(prob, NULL, "-petscds_view"));
3583ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3592764a2aaSMatthew G. Knepley }
3602764a2aaSMatthew G. Knepley 
3612764a2aaSMatthew G. Knepley /*@C
362dce8aebaSBarry Smith   PetscDSSetUp - Construct data structures for the `PetscDS`
3632764a2aaSMatthew G. Knepley 
36420f4b53cSBarry Smith   Collective
3652764a2aaSMatthew G. Knepley 
3662764a2aaSMatthew G. Knepley   Input Parameter:
367dce8aebaSBarry Smith . prob - the `PetscDS` object to setup
3682764a2aaSMatthew G. Knepley 
3692764a2aaSMatthew G. Knepley   Level: developer
3702764a2aaSMatthew G. Knepley 
371dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSView()`, `PetscDSDestroy()`
3722764a2aaSMatthew G. Knepley @*/
373d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetUp(PetscDS prob)
374d71ae5a4SJacob Faibussowitsch {
3752764a2aaSMatthew G. Knepley   const PetscInt Nf          = prob->Nf;
376f9244615SMatthew G. Knepley   PetscBool      hasH        = PETSC_FALSE;
37707218a29SMatthew G. Knepley   PetscInt       maxOrder[4] = {-1, -1, -1, -1};
3784bee2e38SMatthew G. Knepley   PetscInt       dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f;
3792764a2aaSMatthew G. Knepley 
3802764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3812764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3823ba16761SJacob Faibussowitsch   if (prob->setup) PetscFunctionReturn(PETSC_SUCCESS);
3832764a2aaSMatthew G. Knepley   /* Calculate sizes */
3849566063dSJacob Faibussowitsch   PetscCall(PetscDSGetSpatialDimension(prob, &dim));
3859566063dSJacob Faibussowitsch   PetscCall(PetscDSGetCoordinateDimension(prob, &dimEmbed));
386f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
3879566063dSJacob Faibussowitsch   PetscCall(PetscMalloc2(Nf, &prob->Nc, Nf, &prob->Nb));
3889566063dSJacob Faibussowitsch   PetscCall(PetscCalloc2(Nf + 1, &prob->off, Nf + 1, &prob->offDer));
3899566063dSJacob 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]));
3909566063dSJacob Faibussowitsch   PetscCall(PetscMalloc2(Nf, &prob->T, Nf, &prob->Tf));
39112fc5b22SMatthew G. Knepley   if (prob->forceQuad) {
39207218a29SMatthew G. Knepley     // Note: This assumes we have one kind of cell at each dimension.
39307218a29SMatthew G. Knepley     //       We can fix this by having quadrature hold the celltype
39407218a29SMatthew G. Knepley     PetscQuadrature maxQuad[4] = {NULL, NULL, NULL, NULL};
39512fc5b22SMatthew G. Knepley 
39612fc5b22SMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
39712fc5b22SMatthew G. Knepley       PetscObject     obj;
39812fc5b22SMatthew G. Knepley       PetscClassId    id;
39912fc5b22SMatthew G. Knepley       PetscQuadrature q = NULL, fq = NULL;
40007218a29SMatthew G. Knepley       PetscInt        dim = -1, order = -1, forder = -1;
40112fc5b22SMatthew G. Knepley 
40212fc5b22SMatthew G. Knepley       PetscCall(PetscDSGetDiscretization(prob, f, &obj));
40312fc5b22SMatthew G. Knepley       if (!obj) continue;
40412fc5b22SMatthew G. Knepley       PetscCall(PetscObjectGetClassId(obj, &id));
40512fc5b22SMatthew G. Knepley       if (id == PETSCFE_CLASSID) {
40612fc5b22SMatthew G. Knepley         PetscFE fe = (PetscFE)obj;
40712fc5b22SMatthew G. Knepley 
40812fc5b22SMatthew G. Knepley         PetscCall(PetscFEGetQuadrature(fe, &q));
40912fc5b22SMatthew G. Knepley         PetscCall(PetscFEGetFaceQuadrature(fe, &fq));
41012fc5b22SMatthew G. Knepley       } else if (id == PETSCFV_CLASSID) {
41112fc5b22SMatthew G. Knepley         PetscFV fv = (PetscFV)obj;
41212fc5b22SMatthew G. Knepley 
41312fc5b22SMatthew G. Knepley         PetscCall(PetscFVGetQuadrature(fv, &q));
41412fc5b22SMatthew G. Knepley       }
41507218a29SMatthew G. Knepley       if (q) {
41607218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetData(q, &dim, NULL, NULL, NULL, NULL));
41707218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetOrder(q, &order));
41807218a29SMatthew G. Knepley         if (order > maxOrder[dim]) {
41907218a29SMatthew G. Knepley           maxOrder[dim] = order;
42007218a29SMatthew G. Knepley           maxQuad[dim]  = q;
42112fc5b22SMatthew G. Knepley         }
42207218a29SMatthew G. Knepley       }
42307218a29SMatthew G. Knepley       if (fq) {
42407218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetData(fq, &dim, NULL, NULL, NULL, NULL));
42507218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetOrder(fq, &forder));
42607218a29SMatthew G. Knepley         if (forder > maxOrder[dim]) {
42707218a29SMatthew G. Knepley           maxOrder[dim] = forder;
42807218a29SMatthew G. Knepley           maxQuad[dim]  = fq;
42907218a29SMatthew G. Knepley         }
43012fc5b22SMatthew G. Knepley       }
43112fc5b22SMatthew G. Knepley     }
43212fc5b22SMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
43312fc5b22SMatthew G. Knepley       PetscObject     obj;
43412fc5b22SMatthew G. Knepley       PetscClassId    id;
43507218a29SMatthew G. Knepley       PetscQuadrature q;
43607218a29SMatthew G. Knepley       PetscInt        dim;
43712fc5b22SMatthew G. Knepley 
43812fc5b22SMatthew G. Knepley       PetscCall(PetscDSGetDiscretization(prob, f, &obj));
43912fc5b22SMatthew G. Knepley       if (!obj) continue;
44012fc5b22SMatthew G. Knepley       PetscCall(PetscObjectGetClassId(obj, &id));
44112fc5b22SMatthew G. Knepley       if (id == PETSCFE_CLASSID) {
44212fc5b22SMatthew G. Knepley         PetscFE fe = (PetscFE)obj;
44312fc5b22SMatthew G. Knepley 
44407218a29SMatthew G. Knepley         PetscCall(PetscFEGetQuadrature(fe, &q));
44507218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetData(q, &dim, NULL, NULL, NULL, NULL));
44607218a29SMatthew G. Knepley         PetscCall(PetscFESetQuadrature(fe, maxQuad[dim]));
44707218a29SMatthew G. Knepley         PetscCall(PetscFESetFaceQuadrature(fe, maxQuad[dim - 1]));
44812fc5b22SMatthew G. Knepley       } else if (id == PETSCFV_CLASSID) {
44912fc5b22SMatthew G. Knepley         PetscFV fv = (PetscFV)obj;
45012fc5b22SMatthew G. Knepley 
45107218a29SMatthew G. Knepley         PetscCall(PetscFVGetQuadrature(fv, &q));
45207218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetData(q, &dim, NULL, NULL, NULL, NULL));
45307218a29SMatthew G. Knepley         PetscCall(PetscFVSetQuadrature(fv, maxQuad[dim]));
45412fc5b22SMatthew G. Knepley       }
45512fc5b22SMatthew G. Knepley     }
45612fc5b22SMatthew G. Knepley   }
4572764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
4589de99aefSMatthew G. Knepley     PetscObject     obj;
4599de99aefSMatthew G. Knepley     PetscClassId    id;
460665f567fSMatthew G. Knepley     PetscQuadrature q  = NULL;
4619de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
4622764a2aaSMatthew G. Knepley 
4639566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(prob, f, &obj));
464f9244615SMatthew G. Knepley     if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE;
465665f567fSMatthew G. Knepley     if (!obj) {
466665f567fSMatthew G. Knepley       /* Empty mesh */
467665f567fSMatthew G. Knepley       Nb = Nc    = 0;
468665f567fSMatthew G. Knepley       prob->T[f] = prob->Tf[f] = NULL;
469665f567fSMatthew G. Knepley     } else {
4709566063dSJacob Faibussowitsch       PetscCall(PetscObjectGetClassId(obj, &id));
4719de99aefSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {
4729de99aefSMatthew G. Knepley         PetscFE fe = (PetscFE)obj;
4739de99aefSMatthew G. Knepley 
4749566063dSJacob Faibussowitsch         PetscCall(PetscFEGetQuadrature(fe, &q));
47549ae0b56SMatthew G. Knepley         {
47649ae0b56SMatthew G. Knepley           PetscQuadrature fq;
47707218a29SMatthew G. Knepley           PetscInt        dim, order;
47849ae0b56SMatthew G. Knepley 
47907218a29SMatthew G. Knepley           PetscCall(PetscQuadratureGetData(q, &dim, NULL, NULL, NULL, NULL));
48049ae0b56SMatthew G. Knepley           PetscCall(PetscQuadratureGetOrder(q, &order));
48107218a29SMatthew G. Knepley           if (maxOrder[dim] < 0) maxOrder[dim] = order;
48207218a29SMatthew G. Knepley           PetscCheck(order == maxOrder[dim], PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Field %" PetscInt_FMT " cell quadrature order %" PetscInt_FMT " != %" PetscInt_FMT " DS cell quadrature order", f, order, maxOrder[dim]);
48349ae0b56SMatthew G. Knepley           PetscCall(PetscFEGetFaceQuadrature(fe, &fq));
48449ae0b56SMatthew G. Knepley           if (fq) {
48507218a29SMatthew G. Knepley             PetscCall(PetscQuadratureGetData(fq, &dim, NULL, NULL, NULL, NULL));
48607218a29SMatthew G. Knepley             PetscCall(PetscQuadratureGetOrder(fq, &order));
48707218a29SMatthew G. Knepley             if (maxOrder[dim] < 0) maxOrder[dim] = order;
48807218a29SMatthew G. Knepley             PetscCheck(order == maxOrder[dim], PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Field %" PetscInt_FMT " face quadrature order %" PetscInt_FMT " != %" PetscInt_FMT " DS face quadrature order", f, order, maxOrder[dim]);
48949ae0b56SMatthew G. Knepley           }
49049ae0b56SMatthew G. Knepley         }
4919566063dSJacob Faibussowitsch         PetscCall(PetscFEGetDimension(fe, &Nb));
4929566063dSJacob Faibussowitsch         PetscCall(PetscFEGetNumComponents(fe, &Nc));
4939566063dSJacob Faibussowitsch         PetscCall(PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f]));
4949566063dSJacob Faibussowitsch         PetscCall(PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f]));
4959de99aefSMatthew G. Knepley       } else if (id == PETSCFV_CLASSID) {
4969de99aefSMatthew G. Knepley         PetscFV fv = (PetscFV)obj;
4979de99aefSMatthew G. Knepley 
4989566063dSJacob Faibussowitsch         PetscCall(PetscFVGetQuadrature(fv, &q));
4999566063dSJacob Faibussowitsch         PetscCall(PetscFVGetNumComponents(fv, &Nc));
5009c3cf19fSMatthew G. Knepley         Nb = Nc;
5019566063dSJacob Faibussowitsch         PetscCall(PetscFVGetCellTabulation(fv, &prob->T[f]));
5024d0b9603SSander Arens         /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
50363a3b9bcSJacob Faibussowitsch       } else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %" PetscInt_FMT, f);
504665f567fSMatthew G. Knepley     }
50547e57110SSander Arens     prob->Nc[f]                    = Nc;
50647e57110SSander Arens     prob->Nb[f]                    = Nb;
507194d53e6SMatthew G. Knepley     prob->off[f + 1]               = Nc + prob->off[f];
508194d53e6SMatthew G. Knepley     prob->offDer[f + 1]            = Nc * dim + prob->offDer[f];
5099ee2af8cSMatthew G. Knepley     prob->offCohesive[0][f + 1]    = (prob->cohesive[f] ? Nc : Nc * 2) + prob->offCohesive[0][f];
5109ee2af8cSMatthew G. Knepley     prob->offDerCohesive[0][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) * dimEmbed + prob->offDerCohesive[0][f];
5119ee2af8cSMatthew G. Knepley     prob->offCohesive[1][f]        = (prob->cohesive[f] ? 0 : Nc) + prob->offCohesive[0][f];
5129ee2af8cSMatthew G. Knepley     prob->offDerCohesive[1][f]     = (prob->cohesive[f] ? 0 : Nc) * dimEmbed + prob->offDerCohesive[0][f];
5139ee2af8cSMatthew G. Knepley     prob->offCohesive[2][f + 1]    = (prob->cohesive[f] ? Nc : Nc * 2) + prob->offCohesive[2][f];
5149ee2af8cSMatthew G. Knepley     prob->offDerCohesive[2][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) * dimEmbed + prob->offDerCohesive[2][f];
5159566063dSJacob Faibussowitsch     if (q) PetscCall(PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL));
5162764a2aaSMatthew G. Knepley     NqMax = PetscMax(NqMax, Nq);
5174bee2e38SMatthew G. Knepley     NbMax = PetscMax(NbMax, Nb);
5182764a2aaSMatthew G. Knepley     NcMax = PetscMax(NcMax, Nc);
5199c3cf19fSMatthew G. Knepley     prob->totDim += Nb;
5202764a2aaSMatthew G. Knepley     prob->totComp += Nc;
5215fedec97SMatthew G. Knepley     /* There are two faces for all fields on a cohesive cell, except for cohesive fields */
5225fedec97SMatthew G. Knepley     if (prob->isCohesive && !prob->cohesive[f]) prob->totDim += Nb;
5232764a2aaSMatthew G. Knepley   }
5249ee2af8cSMatthew G. Knepley   prob->offCohesive[1][Nf]    = prob->offCohesive[0][Nf];
5259ee2af8cSMatthew G. Knepley   prob->offDerCohesive[1][Nf] = prob->offDerCohesive[0][Nf];
5262764a2aaSMatthew G. Knepley   /* Allocate works space */
5275fedec97SMatthew G. Knepley   NsMax = 2; /* A non-cohesive discretizations can be used on a cohesive cell, so we need this extra workspace for all DS */
5289566063dSJacob 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));
5299566063dSJacob Faibussowitsch   PetscCall(PetscMalloc5(dimEmbed, &prob->x, NbMax * NcMax, &prob->basisReal, NbMax * NcMax * dimEmbed, &prob->basisDerReal, NbMax * NcMax, &prob->testReal, NbMax * NcMax * dimEmbed, &prob->testDerReal));
5309371c9d4SSatish 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,
5319371c9d4SSatish Balay                          &prob->g2, NsMax * NsMax * NqMax * NcMax * NcMax * dimEmbed * dimEmbed, &prob->g3));
532dbbe0bcdSBarry Smith   PetscTryTypeMethod(prob, setup);
5332764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
5343ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
5352764a2aaSMatthew G. Knepley }
5362764a2aaSMatthew G. Knepley 
537d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
538d71ae5a4SJacob Faibussowitsch {
5392764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5409566063dSJacob Faibussowitsch   PetscCall(PetscFree2(prob->Nc, prob->Nb));
5419566063dSJacob Faibussowitsch   PetscCall(PetscFree2(prob->off, prob->offDer));
5429566063dSJacob Faibussowitsch   PetscCall(PetscFree6(prob->offCohesive[0], prob->offCohesive[1], prob->offCohesive[2], prob->offDerCohesive[0], prob->offDerCohesive[1], prob->offDerCohesive[2]));
5439566063dSJacob Faibussowitsch   PetscCall(PetscFree2(prob->T, prob->Tf));
5449566063dSJacob Faibussowitsch   PetscCall(PetscFree3(prob->u, prob->u_t, prob->u_x));
5459566063dSJacob Faibussowitsch   PetscCall(PetscFree5(prob->x, prob->basisReal, prob->basisDerReal, prob->testReal, prob->testDerReal));
5469566063dSJacob Faibussowitsch   PetscCall(PetscFree6(prob->f0, prob->f1, prob->g0, prob->g1, prob->g2, prob->g3));
5473ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
5482764a2aaSMatthew G. Knepley }
5492764a2aaSMatthew G. Knepley 
550d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
551d71ae5a4SJacob Faibussowitsch {
552f744cafaSSander Arens   PetscObject          *tmpd;
55334aa8a36SMatthew G. Knepley   PetscBool            *tmpi;
554f9244615SMatthew G. Knepley   PetscInt             *tmpk;
5555fedec97SMatthew G. Knepley   PetscBool            *tmpc;
5566528b96dSMatthew G. Knepley   PetscPointFunc       *tmpup;
557f2cacb80SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol, *tmpexactSol_t;
558f2cacb80SMatthew G. Knepley   void                **tmpexactCtx, **tmpexactCtx_t;
5590c2f2876SMatthew G. Knepley   void                **tmpctx;
56034aa8a36SMatthew G. Knepley   PetscInt              Nf = prob->Nf, f;
5612764a2aaSMatthew G. Knepley 
5622764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5633ba16761SJacob Faibussowitsch   if (Nf >= NfNew) PetscFunctionReturn(PETSC_SUCCESS);
5642764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
5659566063dSJacob Faibussowitsch   PetscCall(PetscDSDestroyStructs_Static(prob));
5669566063dSJacob Faibussowitsch   PetscCall(PetscMalloc4(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpc, NfNew, &tmpk));
5679371c9d4SSatish Balay   for (f = 0; f < Nf; ++f) {
5689371c9d4SSatish Balay     tmpd[f] = prob->disc[f];
5699371c9d4SSatish Balay     tmpi[f] = prob->implicit[f];
5709371c9d4SSatish Balay     tmpc[f] = prob->cohesive[f];
5719371c9d4SSatish Balay     tmpk[f] = prob->jetDegree[f];
5729371c9d4SSatish Balay   }
5739371c9d4SSatish Balay   for (f = Nf; f < NfNew; ++f) {
5749371c9d4SSatish Balay     tmpd[f] = NULL;
5759371c9d4SSatish Balay     tmpi[f] = PETSC_TRUE, tmpc[f] = PETSC_FALSE;
5769371c9d4SSatish Balay     tmpk[f] = 1;
5779371c9d4SSatish Balay   }
5789566063dSJacob Faibussowitsch   PetscCall(PetscFree4(prob->disc, prob->implicit, prob->cohesive, prob->jetDegree));
5799566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(prob->wf, NfNew));
5802764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
5812764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
582249df284SMatthew G. Knepley   prob->implicit  = tmpi;
5835fedec97SMatthew G. Knepley   prob->cohesive  = tmpc;
584f9244615SMatthew G. Knepley   prob->jetDegree = tmpk;
5859566063dSJacob Faibussowitsch   PetscCall(PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx));
58632d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
5870c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
58832d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
5890c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
5909566063dSJacob Faibussowitsch   PetscCall(PetscFree2(prob->update, prob->ctx));
59132d2bbc9SMatthew G. Knepley   prob->update = tmpup;
5920c2f2876SMatthew G. Knepley   prob->ctx    = tmpctx;
5939566063dSJacob Faibussowitsch   PetscCall(PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t));
594c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
59595cbbfd3SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f];
596f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f];
597f2cacb80SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f];
598c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
59995cbbfd3SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL;
600f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL;
601f2cacb80SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL;
6029566063dSJacob Faibussowitsch   PetscCall(PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t));
603c371a6d1SMatthew G. Knepley   prob->exactSol   = tmpexactSol;
60495cbbfd3SMatthew G. Knepley   prob->exactCtx   = tmpexactCtx;
605f2cacb80SMatthew G. Knepley   prob->exactSol_t = tmpexactSol_t;
606f2cacb80SMatthew G. Knepley   prob->exactCtx_t = tmpexactCtx_t;
6073ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
6082764a2aaSMatthew G. Knepley }
6092764a2aaSMatthew G. Knepley 
6102764a2aaSMatthew G. Knepley /*@
61120f4b53cSBarry Smith   PetscDSDestroy - Destroys a `PetscDS` object
6122764a2aaSMatthew G. Knepley 
61320f4b53cSBarry Smith   Collective
6142764a2aaSMatthew G. Knepley 
6152764a2aaSMatthew G. Knepley   Input Parameter:
61620f4b53cSBarry Smith . prob - the `PetscDS` object to destroy
6172764a2aaSMatthew G. Knepley 
6182764a2aaSMatthew G. Knepley   Level: developer
6192764a2aaSMatthew G. Knepley 
620dce8aebaSBarry Smith .seealso: `PetscDSView()`
6212764a2aaSMatthew G. Knepley @*/
622d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSDestroy(PetscDS *ds)
623d71ae5a4SJacob Faibussowitsch {
6242764a2aaSMatthew G. Knepley   PetscInt f;
6252764a2aaSMatthew G. Knepley 
6262764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6273ba16761SJacob Faibussowitsch   if (!*ds) PetscFunctionReturn(PETSC_SUCCESS);
6286528b96dSMatthew G. Knepley   PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1);
6292764a2aaSMatthew G. Knepley 
6309371c9d4SSatish Balay   if (--((PetscObject)(*ds))->refct > 0) {
6319371c9d4SSatish Balay     *ds = NULL;
6323ba16761SJacob Faibussowitsch     PetscFunctionReturn(PETSC_SUCCESS);
6339371c9d4SSatish Balay   }
6346528b96dSMatthew G. Knepley   ((PetscObject)(*ds))->refct = 0;
6356528b96dSMatthew G. Knepley   if ((*ds)->subprobs) {
636df3a45bdSMatthew G. Knepley     PetscInt dim, d;
637df3a45bdSMatthew G. Knepley 
6389566063dSJacob Faibussowitsch     PetscCall(PetscDSGetSpatialDimension(*ds, &dim));
6399566063dSJacob Faibussowitsch     for (d = 0; d < dim; ++d) PetscCall(PetscDSDestroy(&(*ds)->subprobs[d]));
640df3a45bdSMatthew G. Knepley   }
6419566063dSJacob Faibussowitsch   PetscCall(PetscFree((*ds)->subprobs));
6429566063dSJacob Faibussowitsch   PetscCall(PetscDSDestroyStructs_Static(*ds));
64348a46eb9SPierre Jolivet   for (f = 0; f < (*ds)->Nf; ++f) PetscCall(PetscObjectDereference((*ds)->disc[f]));
6449566063dSJacob Faibussowitsch   PetscCall(PetscFree4((*ds)->disc, (*ds)->implicit, (*ds)->cohesive, (*ds)->jetDegree));
6459566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormDestroy(&(*ds)->wf));
6469566063dSJacob Faibussowitsch   PetscCall(PetscFree2((*ds)->update, (*ds)->ctx));
6479566063dSJacob Faibussowitsch   PetscCall(PetscFree4((*ds)->exactSol, (*ds)->exactCtx, (*ds)->exactSol_t, (*ds)->exactCtx_t));
648dbbe0bcdSBarry Smith   PetscTryTypeMethod((*ds), destroy);
6499566063dSJacob Faibussowitsch   PetscCall(PetscDSDestroyBoundary(*ds));
6509566063dSJacob Faibussowitsch   PetscCall(PetscFree((*ds)->constants));
6514366bac7SMatthew G. Knepley   for (PetscInt c = 0; c < DM_NUM_POLYTOPES; ++c) {
6524366bac7SMatthew G. Knepley     const PetscInt Na = DMPolytopeTypeGetNumArrangments((DMPolytopeType)c);
6534366bac7SMatthew G. Knepley     if ((*ds)->quadPerm[c])
6544366bac7SMatthew G. Knepley       for (PetscInt o = 0; o < Na; ++o) PetscCall(ISDestroy(&(*ds)->quadPerm[c][o]));
6554366bac7SMatthew G. Knepley     PetscCall(PetscFree((*ds)->quadPerm[c]));
6564366bac7SMatthew G. Knepley     (*ds)->quadPerm[c] = NULL;
6574366bac7SMatthew G. Knepley   }
6589566063dSJacob Faibussowitsch   PetscCall(PetscHeaderDestroy(ds));
6593ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
6602764a2aaSMatthew G. Knepley }
6612764a2aaSMatthew G. Knepley 
6622764a2aaSMatthew G. Knepley /*@
663dce8aebaSBarry Smith   PetscDSCreate - Creates an empty `PetscDS` object. The type can then be set with `PetscDSSetType()`.
6642764a2aaSMatthew G. Knepley 
665d083f849SBarry Smith   Collective
6662764a2aaSMatthew G. Knepley 
6672764a2aaSMatthew G. Knepley   Input Parameter:
668dce8aebaSBarry Smith . comm - The communicator for the `PetscDS` object
6692764a2aaSMatthew G. Knepley 
6702764a2aaSMatthew G. Knepley   Output Parameter:
671dce8aebaSBarry Smith . ds   - The `PetscDS` object
6722764a2aaSMatthew G. Knepley 
6732764a2aaSMatthew G. Knepley   Level: beginner
6742764a2aaSMatthew G. Knepley 
675dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetType()`, `PETSCDSBASIC`, `PetscDSType`
6762764a2aaSMatthew G. Knepley @*/
677d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds)
678d71ae5a4SJacob Faibussowitsch {
6792764a2aaSMatthew G. Knepley   PetscDS p;
6802764a2aaSMatthew G. Knepley 
6812764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6826528b96dSMatthew G. Knepley   PetscValidPointer(ds, 2);
6836528b96dSMatthew G. Knepley   *ds = NULL;
6849566063dSJacob Faibussowitsch   PetscCall(PetscDSInitializePackage());
6852764a2aaSMatthew G. Knepley 
6869566063dSJacob Faibussowitsch   PetscCall(PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView));
6872764a2aaSMatthew G. Knepley 
6882764a2aaSMatthew G. Knepley   p->Nf           = 0;
6892764a2aaSMatthew G. Knepley   p->setup        = PETSC_FALSE;
69097b6e6e8SMatthew G. Knepley   p->numConstants = 0;
69197b6e6e8SMatthew G. Knepley   p->constants    = NULL;
692a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
69355c1f793SMatthew G. Knepley   p->useJacPre    = PETSC_TRUE;
69412fc5b22SMatthew G. Knepley   p->forceQuad    = PETSC_TRUE;
6959566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(comm, &p->wf));
6964366bac7SMatthew G. Knepley   PetscCall(PetscArrayzero(p->quadPerm, DM_NUM_POLYTOPES));
6972764a2aaSMatthew G. Knepley 
6986528b96dSMatthew G. Knepley   *ds = p;
6993ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
7002764a2aaSMatthew G. Knepley }
7012764a2aaSMatthew G. Knepley 
702bc4ae4beSMatthew G. Knepley /*@
703dce8aebaSBarry Smith   PetscDSGetNumFields - Returns the number of fields in the `PetscDS`
704bc4ae4beSMatthew G. Knepley 
70520f4b53cSBarry Smith   Not Collective
706bc4ae4beSMatthew G. Knepley 
707bc4ae4beSMatthew G. Knepley   Input Parameter:
70820f4b53cSBarry Smith . prob - The `PetscDS` object
709bc4ae4beSMatthew G. Knepley 
710bc4ae4beSMatthew G. Knepley   Output Parameter:
711bc4ae4beSMatthew G. Knepley . Nf - The number of fields
712bc4ae4beSMatthew G. Knepley 
713bc4ae4beSMatthew G. Knepley   Level: beginner
714bc4ae4beSMatthew G. Knepley 
715dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetSpatialDimension()`, `PetscDSCreate()`
716bc4ae4beSMatthew G. Knepley @*/
717d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
718d71ae5a4SJacob Faibussowitsch {
7192764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7202764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
721dadcf809SJacob Faibussowitsch   PetscValidIntPointer(Nf, 2);
7222764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
7233ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
7242764a2aaSMatthew G. Knepley }
7252764a2aaSMatthew G. Knepley 
726bc4ae4beSMatthew G. Knepley /*@
727dce8aebaSBarry Smith   PetscDSGetSpatialDimension - Returns the spatial dimension of the `PetscDS`, meaning the topological dimension of the discretizations
728bc4ae4beSMatthew G. Knepley 
72920f4b53cSBarry Smith   Not Collective
730bc4ae4beSMatthew G. Knepley 
731bc4ae4beSMatthew G. Knepley   Input Parameter:
732dce8aebaSBarry Smith . prob - The `PetscDS` object
733bc4ae4beSMatthew G. Knepley 
734bc4ae4beSMatthew G. Knepley   Output Parameter:
735bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
736bc4ae4beSMatthew G. Knepley 
737bc4ae4beSMatthew G. Knepley   Level: beginner
738bc4ae4beSMatthew G. Knepley 
739dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetCoordinateDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
740bc4ae4beSMatthew G. Knepley @*/
741d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
742d71ae5a4SJacob Faibussowitsch {
7432764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7442764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
745dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dim, 2);
7462764a2aaSMatthew G. Knepley   *dim = 0;
7479de99aefSMatthew G. Knepley   if (prob->Nf) {
7489de99aefSMatthew G. Knepley     PetscObject  obj;
7499de99aefSMatthew G. Knepley     PetscClassId id;
7509de99aefSMatthew G. Knepley 
7519566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(prob, 0, &obj));
752665f567fSMatthew G. Knepley     if (obj) {
7539566063dSJacob Faibussowitsch       PetscCall(PetscObjectGetClassId(obj, &id));
7549566063dSJacob Faibussowitsch       if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetSpatialDimension((PetscFE)obj, dim));
7559566063dSJacob Faibussowitsch       else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetSpatialDimension((PetscFV)obj, dim));
75698921bdaSJacob Faibussowitsch       else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
7579de99aefSMatthew G. Knepley     }
758665f567fSMatthew G. Knepley   }
7593ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
7602764a2aaSMatthew G. Knepley }
7612764a2aaSMatthew G. Knepley 
762bc4ae4beSMatthew G. Knepley /*@
763dce8aebaSBarry Smith   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the `PetscDS`, meaning the dimension of the space into which the discretiaztions are embedded
764a859676bSMatthew G. Knepley 
76520f4b53cSBarry Smith   Not Collective
766a859676bSMatthew G. Knepley 
767a859676bSMatthew G. Knepley   Input Parameter:
768dce8aebaSBarry Smith . prob - The `PetscDS` object
769a859676bSMatthew G. Knepley 
770a859676bSMatthew G. Knepley   Output Parameter:
771a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
772a859676bSMatthew G. Knepley 
773a859676bSMatthew G. Knepley   Level: beginner
774a859676bSMatthew G. Knepley 
775dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
776a859676bSMatthew G. Knepley @*/
777d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
778d71ae5a4SJacob Faibussowitsch {
779a859676bSMatthew G. Knepley   PetscFunctionBegin;
780a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
781dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dimEmbed, 2);
78208401ef6SPierre Jolivet   PetscCheck(prob->dimEmbed >= 0, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
783a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
7843ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
785a859676bSMatthew G. Knepley }
786a859676bSMatthew G. Knepley 
787a859676bSMatthew G. Knepley /*@
788dce8aebaSBarry Smith   PetscDSSetCoordinateDimension - Set the coordinate dimension of the `PetscDS`, meaning the dimension of the space into which the discretiaztions are embedded
789a859676bSMatthew G. Knepley 
79020f4b53cSBarry Smith   Logically Collective
791a859676bSMatthew G. Knepley 
792a859676bSMatthew G. Knepley   Input Parameters:
793dce8aebaSBarry Smith + prob - The `PetscDS` object
794a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
795a859676bSMatthew G. Knepley 
796a859676bSMatthew G. Knepley   Level: beginner
797a859676bSMatthew G. Knepley 
798dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
799a859676bSMatthew G. Knepley @*/
800d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
801d71ae5a4SJacob Faibussowitsch {
802a859676bSMatthew G. Knepley   PetscFunctionBegin;
803a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
80463a3b9bcSJacob Faibussowitsch   PetscCheck(dimEmbed >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %" PetscInt_FMT, dimEmbed);
805a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
8063ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
807a859676bSMatthew G. Knepley }
808a859676bSMatthew G. Knepley 
809a859676bSMatthew G. Knepley /*@
81012fc5b22SMatthew G. Knepley   PetscDSGetForceQuad - Returns the flag to force matching quadratures among the field discretizations
81112fc5b22SMatthew G. Knepley 
81212fc5b22SMatthew G. Knepley   Not collective
81312fc5b22SMatthew G. Knepley 
81412fc5b22SMatthew G. Knepley   Input Parameter:
81512fc5b22SMatthew G. Knepley . prob - The `PetscDS` object
81612fc5b22SMatthew G. Knepley 
81712fc5b22SMatthew G. Knepley   Output Parameter:
81812fc5b22SMatthew G. Knepley . forceQuad - The flag
81912fc5b22SMatthew G. Knepley 
82012fc5b22SMatthew G. Knepley   Level: intermediate
82112fc5b22SMatthew G. Knepley 
82212fc5b22SMatthew G. Knepley .seealso: `PetscDS`, `PetscDSSetForceQuad()`, `PetscDSGetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
82312fc5b22SMatthew G. Knepley @*/
82412fc5b22SMatthew G. Knepley PetscErrorCode PetscDSGetForceQuad(PetscDS ds, PetscBool *forceQuad)
82512fc5b22SMatthew G. Knepley {
82612fc5b22SMatthew G. Knepley   PetscFunctionBegin;
82712fc5b22SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
828f87a0b54SStefano Zampini   PetscValidBoolPointer(forceQuad, 2);
82912fc5b22SMatthew G. Knepley   *forceQuad = ds->forceQuad;
83012fc5b22SMatthew G. Knepley   PetscFunctionReturn(PETSC_SUCCESS);
83112fc5b22SMatthew G. Knepley }
83212fc5b22SMatthew G. Knepley 
83312fc5b22SMatthew G. Knepley /*@
83412fc5b22SMatthew G. Knepley   PetscDSSetForceQuad - Set the flag to force matching quadratures among the field discretizations
83512fc5b22SMatthew G. Knepley 
83612fc5b22SMatthew G. Knepley   Logically collective on ds
83712fc5b22SMatthew G. Knepley 
83812fc5b22SMatthew G. Knepley   Input Parameters:
83912fc5b22SMatthew G. Knepley + ds - The `PetscDS` object
84012fc5b22SMatthew G. Knepley - forceQuad - The flag
84112fc5b22SMatthew G. Knepley 
84212fc5b22SMatthew G. Knepley   Level: intermediate
84312fc5b22SMatthew G. Knepley 
84412fc5b22SMatthew G. Knepley .seealso: `PetscDS`, `PetscDSGetForceQuad()`, `PetscDSGetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
84512fc5b22SMatthew G. Knepley @*/
84612fc5b22SMatthew G. Knepley PetscErrorCode PetscDSSetForceQuad(PetscDS ds, PetscBool forceQuad)
84712fc5b22SMatthew G. Knepley {
84812fc5b22SMatthew G. Knepley   PetscFunctionBegin;
84912fc5b22SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
85012fc5b22SMatthew G. Knepley   ds->forceQuad = forceQuad;
85112fc5b22SMatthew G. Knepley   PetscFunctionReturn(PETSC_SUCCESS);
85212fc5b22SMatthew G. Knepley }
85312fc5b22SMatthew G. Knepley 
85412fc5b22SMatthew G. Knepley /*@
855dce8aebaSBarry Smith   PetscDSIsCohesive - Returns the flag indicating that this `PetscDS` is for a cohesive cell
8568edf6225SMatthew G. Knepley 
85720f4b53cSBarry Smith   Not Collective
8588edf6225SMatthew G. Knepley 
8598edf6225SMatthew G. Knepley   Input Parameter:
860dce8aebaSBarry Smith . ds - The `PetscDS` object
8618edf6225SMatthew G. Knepley 
8628edf6225SMatthew G. Knepley   Output Parameter:
8635fedec97SMatthew G. Knepley . isCohesive - The flag
8648edf6225SMatthew G. Knepley 
8658edf6225SMatthew G. Knepley   Level: developer
8668edf6225SMatthew G. Knepley 
867dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumCohesive()`, `PetscDSGetCohesive()`, `PetscDSSetCohesive()`, `PetscDSCreate()`
8688edf6225SMatthew G. Knepley @*/
869d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSIsCohesive(PetscDS ds, PetscBool *isCohesive)
870d71ae5a4SJacob Faibussowitsch {
8718edf6225SMatthew G. Knepley   PetscFunctionBegin;
8725fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
873dadcf809SJacob Faibussowitsch   PetscValidBoolPointer(isCohesive, 2);
8745fedec97SMatthew G. Knepley   *isCohesive = ds->isCohesive;
8753ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
8768edf6225SMatthew G. Knepley }
8778edf6225SMatthew G. Knepley 
8788edf6225SMatthew G. Knepley /*@
879be87f6c0SPierre Jolivet   PetscDSGetNumCohesive - Returns the number of cohesive fields, meaning those defined on the interior of a cohesive cell
8805fedec97SMatthew G. Knepley 
88120f4b53cSBarry Smith   Not Collective
8825fedec97SMatthew G. Knepley 
8835fedec97SMatthew G. Knepley   Input Parameter:
884dce8aebaSBarry Smith . ds - The `PetscDS` object
8855fedec97SMatthew G. Knepley 
8865fedec97SMatthew G. Knepley   Output Parameter:
8875fedec97SMatthew G. Knepley . numCohesive - The number of cohesive fields
8885fedec97SMatthew G. Knepley 
8895fedec97SMatthew G. Knepley   Level: developer
8905fedec97SMatthew G. Knepley 
891dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetCohesive()`, `PetscDSCreate()`
8925fedec97SMatthew G. Knepley @*/
893d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumCohesive(PetscDS ds, PetscInt *numCohesive)
894d71ae5a4SJacob Faibussowitsch {
8955fedec97SMatthew G. Knepley   PetscInt f;
8965fedec97SMatthew G. Knepley 
8975fedec97SMatthew G. Knepley   PetscFunctionBegin;
8985fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
899dadcf809SJacob Faibussowitsch   PetscValidIntPointer(numCohesive, 2);
9005fedec97SMatthew G. Knepley   *numCohesive = 0;
9015fedec97SMatthew G. Knepley   for (f = 0; f < ds->Nf; ++f) *numCohesive += ds->cohesive[f] ? 1 : 0;
9023ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9035fedec97SMatthew G. Knepley }
9045fedec97SMatthew G. Knepley 
9055fedec97SMatthew G. Knepley /*@
9065fedec97SMatthew G. Knepley   PetscDSGetCohesive - Returns the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell
9075fedec97SMatthew G. Knepley 
90820f4b53cSBarry Smith   Not Collective
9095fedec97SMatthew G. Knepley 
910f1a722f8SMatthew G. Knepley   Input Parameters:
911dce8aebaSBarry Smith + ds - The `PetscDS` object
9125fedec97SMatthew G. Knepley - f  - The field index
9135fedec97SMatthew G. Knepley 
9145fedec97SMatthew G. Knepley   Output Parameter:
9155fedec97SMatthew G. Knepley . isCohesive - The flag
9165fedec97SMatthew G. Knepley 
9175fedec97SMatthew G. Knepley   Level: developer
9185fedec97SMatthew G. Knepley 
919dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()`
9205fedec97SMatthew G. Knepley @*/
921d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetCohesive(PetscDS ds, PetscInt f, PetscBool *isCohesive)
922d71ae5a4SJacob Faibussowitsch {
9235fedec97SMatthew G. Knepley   PetscFunctionBegin;
9245fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
925dadcf809SJacob Faibussowitsch   PetscValidBoolPointer(isCohesive, 3);
92663a3b9bcSJacob 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);
9275fedec97SMatthew G. Knepley   *isCohesive = ds->cohesive[f];
9283ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9295fedec97SMatthew G. Knepley }
9305fedec97SMatthew G. Knepley 
9315fedec97SMatthew G. Knepley /*@
9325fedec97SMatthew G. Knepley   PetscDSSetCohesive - Set the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell
9338edf6225SMatthew G. Knepley 
93420f4b53cSBarry Smith   Not Collective
9358edf6225SMatthew G. Knepley 
9368edf6225SMatthew G. Knepley   Input Parameters:
937dce8aebaSBarry Smith + ds - The `PetscDS` object
9385fedec97SMatthew G. Knepley . f  - The field index
9395fedec97SMatthew G. Knepley - isCohesive - The flag for a cohesive field
9408edf6225SMatthew G. Knepley 
9418edf6225SMatthew G. Knepley   Level: developer
9428edf6225SMatthew G. Knepley 
943dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()`
9448edf6225SMatthew G. Knepley @*/
945d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetCohesive(PetscDS ds, PetscInt f, PetscBool isCohesive)
946d71ae5a4SJacob Faibussowitsch {
9475fedec97SMatthew G. Knepley   PetscInt i;
9485fedec97SMatthew G. Knepley 
9498edf6225SMatthew G. Knepley   PetscFunctionBegin;
9505fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
95163a3b9bcSJacob 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);
9525fedec97SMatthew G. Knepley   ds->cohesive[f] = isCohesive;
9535fedec97SMatthew G. Knepley   ds->isCohesive  = PETSC_FALSE;
9545fedec97SMatthew G. Knepley   for (i = 0; i < ds->Nf; ++i) ds->isCohesive = ds->isCohesive || ds->cohesive[f] ? PETSC_TRUE : PETSC_FALSE;
9553ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9568edf6225SMatthew G. Knepley }
9578edf6225SMatthew G. Knepley 
9588edf6225SMatthew G. Knepley /*@
959bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
960bc4ae4beSMatthew G. Knepley 
96120f4b53cSBarry Smith   Not Collective
962bc4ae4beSMatthew G. Knepley 
963bc4ae4beSMatthew G. Knepley   Input Parameter:
964dce8aebaSBarry Smith . prob - The `PetscDS` object
965bc4ae4beSMatthew G. Knepley 
966bc4ae4beSMatthew G. Knepley   Output Parameter:
967bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
968bc4ae4beSMatthew G. Knepley 
969bc4ae4beSMatthew G. Knepley   Level: beginner
970bc4ae4beSMatthew G. Knepley 
971dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
972bc4ae4beSMatthew G. Knepley @*/
973d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
974d71ae5a4SJacob Faibussowitsch {
9752764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9762764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9779566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
978dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dim, 2);
9792764a2aaSMatthew G. Knepley   *dim = prob->totDim;
9803ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9812764a2aaSMatthew G. Knepley }
9822764a2aaSMatthew G. Knepley 
983bc4ae4beSMatthew G. Knepley /*@
984bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
985bc4ae4beSMatthew G. Knepley 
98620f4b53cSBarry Smith   Not Collective
987bc4ae4beSMatthew G. Knepley 
988bc4ae4beSMatthew G. Knepley   Input Parameter:
989dce8aebaSBarry Smith . prob - The `PetscDS` object
990bc4ae4beSMatthew G. Knepley 
991bc4ae4beSMatthew G. Knepley   Output Parameter:
992bc4ae4beSMatthew G. Knepley . dim - The total number of components
993bc4ae4beSMatthew G. Knepley 
994bc4ae4beSMatthew G. Knepley   Level: beginner
995bc4ae4beSMatthew G. Knepley 
996dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
997bc4ae4beSMatthew G. Knepley @*/
998d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
999d71ae5a4SJacob Faibussowitsch {
10002764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10012764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10029566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
1003dadcf809SJacob Faibussowitsch   PetscValidIntPointer(Nc, 2);
10042764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
10053ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10062764a2aaSMatthew G. Knepley }
10072764a2aaSMatthew G. Knepley 
1008bc4ae4beSMatthew G. Knepley /*@
1009bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
1010bc4ae4beSMatthew G. Knepley 
101120f4b53cSBarry Smith   Not Collective
1012bc4ae4beSMatthew G. Knepley 
1013bc4ae4beSMatthew G. Knepley   Input Parameters:
1014dce8aebaSBarry Smith + prob - The `PetscDS` object
1015bc4ae4beSMatthew G. Knepley - f - The field number
1016bc4ae4beSMatthew G. Knepley 
1017bc4ae4beSMatthew G. Knepley   Output Parameter:
1018bc4ae4beSMatthew G. Knepley . disc - The discretization object
1019bc4ae4beSMatthew G. Knepley 
1020bc4ae4beSMatthew G. Knepley   Level: beginner
1021bc4ae4beSMatthew G. Knepley 
1022dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscFE`, `PetscFV`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1023bc4ae4beSMatthew G. Knepley @*/
1024d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
1025d71ae5a4SJacob Faibussowitsch {
10266528b96dSMatthew G. Knepley   PetscFunctionBeginHot;
10272764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10282764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
102963a3b9bcSJacob 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);
10302764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
10313ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10322764a2aaSMatthew G. Knepley }
10332764a2aaSMatthew G. Knepley 
1034bc4ae4beSMatthew G. Knepley /*@
1035bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
1036bc4ae4beSMatthew G. Knepley 
103720f4b53cSBarry Smith   Not Collective
1038bc4ae4beSMatthew G. Knepley 
1039bc4ae4beSMatthew G. Knepley   Input Parameters:
1040dce8aebaSBarry Smith + prob - The `PetscDS` object
1041bc4ae4beSMatthew G. Knepley . f - The field number
1042bc4ae4beSMatthew G. Knepley - disc - The discretization object
1043bc4ae4beSMatthew G. Knepley 
1044bc4ae4beSMatthew G. Knepley   Level: beginner
1045bc4ae4beSMatthew G. Knepley 
1046dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscFE`, `PetscFV`, `PetscDSGetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1047bc4ae4beSMatthew G. Knepley @*/
1048d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
1049d71ae5a4SJacob Faibussowitsch {
10502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10512764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1052665f567fSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
105363a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
10549566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(prob, f + 1));
10559566063dSJacob Faibussowitsch   PetscCall(PetscObjectDereference(prob->disc[f]));
10562764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
10579566063dSJacob Faibussowitsch   PetscCall(PetscObjectReference(disc));
1058665f567fSMatthew G. Knepley   if (disc) {
1059249df284SMatthew G. Knepley     PetscClassId id;
1060249df284SMatthew G. Knepley 
10619566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetClassId(disc, &id));
10621cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
10639566063dSJacob Faibussowitsch       PetscCall(PetscDSSetImplicit(prob, f, PETSC_TRUE));
10641cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
10659566063dSJacob Faibussowitsch       PetscCall(PetscDSSetImplicit(prob, f, PETSC_FALSE));
1066a6cbbb48SMatthew G. Knepley     }
10679566063dSJacob Faibussowitsch     PetscCall(PetscDSSetJetDegree(prob, f, 1));
1068249df284SMatthew G. Knepley   }
10693ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10702764a2aaSMatthew G. Knepley }
10712764a2aaSMatthew G. Knepley 
1072bc4ae4beSMatthew G. Knepley /*@
10736528b96dSMatthew G. Knepley   PetscDSGetWeakForm - Returns the weak form object
10746528b96dSMatthew G. Knepley 
107520f4b53cSBarry Smith   Not Collective
10766528b96dSMatthew G. Knepley 
10776528b96dSMatthew G. Knepley   Input Parameter:
1078dce8aebaSBarry Smith . ds - The `PetscDS` object
10796528b96dSMatthew G. Knepley 
10806528b96dSMatthew G. Knepley   Output Parameter:
10816528b96dSMatthew G. Knepley . wf - The weak form object
10826528b96dSMatthew G. Knepley 
10836528b96dSMatthew G. Knepley   Level: beginner
10846528b96dSMatthew G. Knepley 
1085dce8aebaSBarry Smith .seealso: `PetscWeakForm`, `PetscDSSetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
10866528b96dSMatthew G. Knepley @*/
1087d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf)
1088d71ae5a4SJacob Faibussowitsch {
10896528b96dSMatthew G. Knepley   PetscFunctionBegin;
10906528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
10916528b96dSMatthew G. Knepley   PetscValidPointer(wf, 2);
10926528b96dSMatthew G. Knepley   *wf = ds->wf;
10933ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10946528b96dSMatthew G. Knepley }
10956528b96dSMatthew G. Knepley 
10966528b96dSMatthew G. Knepley /*@
10976528b96dSMatthew G. Knepley   PetscDSSetWeakForm - Sets the weak form object
10986528b96dSMatthew G. Knepley 
109920f4b53cSBarry Smith   Not Collective
11006528b96dSMatthew G. Knepley 
11016528b96dSMatthew G. Knepley   Input Parameters:
1102dce8aebaSBarry Smith + ds - The `PetscDS` object
11036528b96dSMatthew G. Knepley - wf - The weak form object
11046528b96dSMatthew G. Knepley 
11056528b96dSMatthew G. Knepley   Level: beginner
11066528b96dSMatthew G. Knepley 
1107dce8aebaSBarry Smith .seealso: `PetscWeakForm`, `PetscDSGetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
11086528b96dSMatthew G. Knepley @*/
1109d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf)
1110d71ae5a4SJacob Faibussowitsch {
11116528b96dSMatthew G. Knepley   PetscFunctionBegin;
11126528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11136528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2);
11149566063dSJacob Faibussowitsch   PetscCall(PetscObjectDereference((PetscObject)ds->wf));
11156528b96dSMatthew G. Knepley   ds->wf = wf;
11169566063dSJacob Faibussowitsch   PetscCall(PetscObjectReference((PetscObject)wf));
11179566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(wf, ds->Nf));
11183ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
11196528b96dSMatthew G. Knepley }
11206528b96dSMatthew G. Knepley 
11216528b96dSMatthew G. Knepley /*@
1122bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
1123bc4ae4beSMatthew G. Knepley 
112420f4b53cSBarry Smith   Not Collective
1125bc4ae4beSMatthew G. Knepley 
1126bc4ae4beSMatthew G. Knepley   Input Parameters:
1127dce8aebaSBarry Smith + prob - The `PetscDS` object
1128bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
1129bc4ae4beSMatthew G. Knepley 
1130bc4ae4beSMatthew G. Knepley   Level: beginner
1131bc4ae4beSMatthew G. Knepley 
1132dce8aebaSBarry Smith .seealso: `PetscWeakForm`, `PetscDSGetDiscretization()`, `PetscDSSetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1133bc4ae4beSMatthew G. Knepley @*/
1134d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
1135d71ae5a4SJacob Faibussowitsch {
11362764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11379566063dSJacob Faibussowitsch   PetscCall(PetscDSSetDiscretization(prob, prob->Nf, disc));
11383ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
11392764a2aaSMatthew G. Knepley }
11402764a2aaSMatthew G. Knepley 
1141249df284SMatthew G. Knepley /*@
1142dce8aebaSBarry Smith   PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the `PetscDS`
1143083401c6SMatthew G. Knepley 
114420f4b53cSBarry Smith   Not Collective
1145083401c6SMatthew G. Knepley 
1146083401c6SMatthew G. Knepley   Input Parameter:
1147dce8aebaSBarry Smith . prob - The `PetscDS` object
1148083401c6SMatthew G. Knepley 
1149083401c6SMatthew G. Knepley   Output Parameter:
1150083401c6SMatthew G. Knepley . q - The quadrature object
1151083401c6SMatthew G. Knepley 
1152083401c6SMatthew G. Knepley   Level: intermediate
1153083401c6SMatthew G. Knepley 
1154dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscQuadrature`, `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1155083401c6SMatthew G. Knepley @*/
1156d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q)
1157d71ae5a4SJacob Faibussowitsch {
1158083401c6SMatthew G. Knepley   PetscObject  obj;
1159083401c6SMatthew G. Knepley   PetscClassId id;
1160083401c6SMatthew G. Knepley 
1161083401c6SMatthew G. Knepley   PetscFunctionBegin;
1162083401c6SMatthew G. Knepley   *q = NULL;
11633ba16761SJacob Faibussowitsch   if (!prob->Nf) PetscFunctionReturn(PETSC_SUCCESS);
11649566063dSJacob Faibussowitsch   PetscCall(PetscDSGetDiscretization(prob, 0, &obj));
11659566063dSJacob Faibussowitsch   PetscCall(PetscObjectGetClassId(obj, &id));
11669566063dSJacob Faibussowitsch   if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetQuadrature((PetscFE)obj, q));
11679566063dSJacob Faibussowitsch   else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetQuadrature((PetscFV)obj, q));
116898921bdaSJacob Faibussowitsch   else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
11693ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1170083401c6SMatthew G. Knepley }
1171083401c6SMatthew G. Knepley 
1172083401c6SMatthew G. Knepley /*@
1173dce8aebaSBarry Smith   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for `TSIMEX`
1174249df284SMatthew G. Knepley 
117520f4b53cSBarry Smith   Not Collective
1176249df284SMatthew G. Knepley 
1177249df284SMatthew G. Knepley   Input Parameters:
1178dce8aebaSBarry Smith + prob - The `PetscDS` object
1179249df284SMatthew G. Knepley - f - The field number
1180249df284SMatthew G. Knepley 
1181249df284SMatthew G. Knepley   Output Parameter:
1182249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
1183249df284SMatthew G. Knepley 
1184249df284SMatthew G. Knepley   Level: developer
1185249df284SMatthew G. Knepley 
1186dce8aebaSBarry Smith .seealso: `TSIMEX`, `PetscDS`, `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1187249df284SMatthew G. Knepley @*/
1188d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
1189d71ae5a4SJacob Faibussowitsch {
1190249df284SMatthew G. Knepley   PetscFunctionBegin;
1191249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1192dadcf809SJacob Faibussowitsch   PetscValidBoolPointer(implicit, 3);
119363a3b9bcSJacob 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);
1194249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
11953ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1196249df284SMatthew G. Knepley }
1197249df284SMatthew G. Knepley 
1198249df284SMatthew G. Knepley /*@
1199dce8aebaSBarry Smith   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for `TSIMEX`
1200249df284SMatthew G. Knepley 
120120f4b53cSBarry Smith   Not Collective
1202249df284SMatthew G. Knepley 
1203249df284SMatthew G. Knepley   Input Parameters:
1204dce8aebaSBarry Smith + prob - The `PetscDS` object
1205249df284SMatthew G. Knepley . f - The field number
1206249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
1207249df284SMatthew G. Knepley 
1208249df284SMatthew G. Knepley   Level: developer
1209249df284SMatthew G. Knepley 
1210dce8aebaSBarry Smith .seealso: `TSIMEX`, `PetscDSGetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1211249df284SMatthew G. Knepley @*/
1212d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
1213d71ae5a4SJacob Faibussowitsch {
1214249df284SMatthew G. Knepley   PetscFunctionBegin;
1215249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
121663a3b9bcSJacob 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);
1217249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
12183ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1219249df284SMatthew G. Knepley }
1220249df284SMatthew G. Knepley 
1221f9244615SMatthew G. Knepley /*@
1222f9244615SMatthew G. Knepley   PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1223f9244615SMatthew G. Knepley 
122420f4b53cSBarry Smith   Not Collective
1225f9244615SMatthew G. Knepley 
1226f9244615SMatthew G. Knepley   Input Parameters:
1227dce8aebaSBarry Smith + ds - The `PetscDS` object
1228f9244615SMatthew G. Knepley - f  - The field number
1229f9244615SMatthew G. Knepley 
1230f9244615SMatthew G. Knepley   Output Parameter:
1231f9244615SMatthew G. Knepley . k  - The highest derivative we need to tabulate
1232f9244615SMatthew G. Knepley 
1233f9244615SMatthew G. Knepley   Level: developer
1234f9244615SMatthew G. Knepley 
1235dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1236f9244615SMatthew G. Knepley @*/
1237d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k)
1238d71ae5a4SJacob Faibussowitsch {
1239f9244615SMatthew G. Knepley   PetscFunctionBegin;
1240f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1241dadcf809SJacob Faibussowitsch   PetscValidIntPointer(k, 3);
124263a3b9bcSJacob 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);
1243f9244615SMatthew G. Knepley   *k = ds->jetDegree[f];
12443ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1245f9244615SMatthew G. Knepley }
1246f9244615SMatthew G. Knepley 
1247f9244615SMatthew G. Knepley /*@
1248f9244615SMatthew G. Knepley   PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1249f9244615SMatthew G. Knepley 
125020f4b53cSBarry Smith   Not Collective
1251f9244615SMatthew G. Knepley 
1252f9244615SMatthew G. Knepley   Input Parameters:
1253dce8aebaSBarry Smith + ds - The `PetscDS` object
1254f9244615SMatthew G. Knepley . f  - The field number
1255f9244615SMatthew G. Knepley - k  - The highest derivative we need to tabulate
1256f9244615SMatthew G. Knepley 
1257f9244615SMatthew G. Knepley   Level: developer
1258f9244615SMatthew G. Knepley 
1259dce8aebaSBarry Smith .seealso: ``PetscDS`, PetscDSGetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1260f9244615SMatthew G. Knepley @*/
1261d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k)
1262d71ae5a4SJacob Faibussowitsch {
1263f9244615SMatthew G. Knepley   PetscFunctionBegin;
1264f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
126563a3b9bcSJacob 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);
1266f9244615SMatthew G. Knepley   ds->jetDegree[f] = k;
12673ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1268f9244615SMatthew G. Knepley }
1269f9244615SMatthew G. Knepley 
1270*c8943706SMatthew G. Knepley /*@C
1271*c8943706SMatthew G. Knepley   PetscDSGetObjective - Get the pointwise objective function for a given test field
1272*c8943706SMatthew G. Knepley 
1273*c8943706SMatthew G. Knepley   Not Collective
1274*c8943706SMatthew G. Knepley 
1275*c8943706SMatthew G. Knepley   Input Parameters:
1276*c8943706SMatthew G. Knepley + ds - The `PetscDS`
1277*c8943706SMatthew G. Knepley - f  - The test field number
1278*c8943706SMatthew G. Knepley 
1279*c8943706SMatthew G. Knepley   Output Parameters:
1280*c8943706SMatthew G. Knepley . obj - integrand for the test function term
1281*c8943706SMatthew G. Knepley 
1282*c8943706SMatthew G. Knepley   Calling sequence of `obj`:
1283*c8943706SMatthew G. Knepley .vb
1284*c8943706SMatthew G. Knepley   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1285*c8943706SMatthew G. Knepley           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1286*c8943706SMatthew G. Knepley           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1287*c8943706SMatthew G. Knepley           PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])
1288*c8943706SMatthew G. Knepley .ve
1289*c8943706SMatthew G. Knepley + dim - the spatial dimension
1290*c8943706SMatthew G. Knepley . Nf - the number of fields
1291*c8943706SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1292*c8943706SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1293*c8943706SMatthew G. Knepley . u - each field evaluated at the current point
1294*c8943706SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1295*c8943706SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1296*c8943706SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1297*c8943706SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1298*c8943706SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1299*c8943706SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1300*c8943706SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1301*c8943706SMatthew G. Knepley . t - current time
1302*c8943706SMatthew G. Knepley . x - coordinates of the current point
1303*c8943706SMatthew G. Knepley . numConstants - number of constant parameters
1304*c8943706SMatthew G. Knepley . constants - constant parameters
1305*c8943706SMatthew G. Knepley - obj - output values at the current point
1306*c8943706SMatthew G. Knepley 
1307*c8943706SMatthew G. Knepley   Level: intermediate
1308*c8943706SMatthew G. Knepley 
1309*c8943706SMatthew G. Knepley   Note:
1310*c8943706SMatthew G. Knepley   We are using a first order FEM model for the weak form:  \int_\Omega \phi obj(u, u_t, \nabla u, x, t)
1311*c8943706SMatthew G. Knepley 
1312*c8943706SMatthew G. Knepley .seealso: `PetscDS`, `PetscDSSetObjective()`, `PetscDSGetResidual()`
1313*c8943706SMatthew G. Knepley @*/
1314d71ae5a4SJacob 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[]))
1315d71ae5a4SJacob Faibussowitsch {
13166528b96dSMatthew G. Knepley   PetscPointFunc *tmp;
13176528b96dSMatthew G. Knepley   PetscInt        n;
13186528b96dSMatthew G. Knepley 
13192764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13206528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
13216528b96dSMatthew G. Knepley   PetscValidPointer(obj, 3);
132263a3b9bcSJacob 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);
13239566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetObjective(ds->wf, NULL, 0, f, 0, &n, &tmp));
13246528b96dSMatthew G. Knepley   *obj = tmp ? tmp[0] : NULL;
13253ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
13262764a2aaSMatthew G. Knepley }
13272764a2aaSMatthew G. Knepley 
1328*c8943706SMatthew G. Knepley /*@C
1329*c8943706SMatthew G. Knepley   PetscDSSetObjective - Set the pointwise objective function for a given test field
1330*c8943706SMatthew G. Knepley 
1331*c8943706SMatthew G. Knepley   Not Collective
1332*c8943706SMatthew G. Knepley 
1333*c8943706SMatthew G. Knepley   Input Parameters:
1334*c8943706SMatthew G. Knepley + ds  - The `PetscDS`
1335*c8943706SMatthew G. Knepley . f   - The test field number
1336*c8943706SMatthew G. Knepley - obj - integrand for the test function term
1337*c8943706SMatthew G. Knepley 
1338*c8943706SMatthew G. Knepley   Calling sequence of `obj`:
1339*c8943706SMatthew G. Knepley .vb
1340*c8943706SMatthew G. Knepley   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1341*c8943706SMatthew G. Knepley           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1342*c8943706SMatthew G. Knepley           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1343*c8943706SMatthew G. Knepley           PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])
1344*c8943706SMatthew G. Knepley .ve
1345*c8943706SMatthew G. Knepley + dim - the spatial dimension
1346*c8943706SMatthew G. Knepley . Nf - the number of fields
1347*c8943706SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1348*c8943706SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1349*c8943706SMatthew G. Knepley . u - each field evaluated at the current point
1350*c8943706SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1351*c8943706SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1352*c8943706SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1353*c8943706SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1354*c8943706SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1355*c8943706SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1356*c8943706SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1357*c8943706SMatthew G. Knepley . t - current time
1358*c8943706SMatthew G. Knepley . x - coordinates of the current point
1359*c8943706SMatthew G. Knepley . numConstants - number of constant parameters
1360*c8943706SMatthew G. Knepley . constants - constant parameters
1361*c8943706SMatthew G. Knepley - obj - output values at the current point
1362*c8943706SMatthew G. Knepley 
1363*c8943706SMatthew G. Knepley   Level: intermediate
1364*c8943706SMatthew G. Knepley 
1365*c8943706SMatthew G. Knepley   Note:
1366*c8943706SMatthew G. Knepley   We are using a first order FEM model for the weak form:  \int_\Omega \phi obj(u, u_t, \nabla u, x, t)
1367*c8943706SMatthew G. Knepley 
1368*c8943706SMatthew G. Knepley .seealso: `PetscDS`, `PetscDSGetObjective()`, `PetscDSSetResidual()`
1369*c8943706SMatthew G. Knepley @*/
1370d71ae5a4SJacob 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[]))
1371d71ae5a4SJacob Faibussowitsch {
13722764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13736528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
13746528b96dSMatthew G. Knepley   if (obj) PetscValidFunction(obj, 3);
137563a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
13769566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, 0, obj));
13773ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
13782764a2aaSMatthew G. Knepley }
13792764a2aaSMatthew G. Knepley 
1380194d53e6SMatthew G. Knepley /*@C
1381194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1382194d53e6SMatthew G. Knepley 
138320f4b53cSBarry Smith   Not Collective
1384194d53e6SMatthew G. Knepley 
1385194d53e6SMatthew G. Knepley   Input Parameters:
1386dce8aebaSBarry Smith + ds - The `PetscDS`
1387194d53e6SMatthew G. Knepley - f  - The test field number
1388194d53e6SMatthew G. Knepley 
1389194d53e6SMatthew G. Knepley   Output Parameters:
1390194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1391194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1392194d53e6SMatthew G. Knepley 
139320f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
1394dce8aebaSBarry Smith .vb
139520f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1396dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1397dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1398*c8943706SMatthew G. Knepley           PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
1399dce8aebaSBarry Smith .ve
1400194d53e6SMatthew G. Knepley + dim - the spatial dimension
1401194d53e6SMatthew G. Knepley . Nf - the number of fields
1402194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1403194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1404194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1405194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1406194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1407194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1408194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1409194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1410194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1411194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1412194d53e6SMatthew G. Knepley . t - current time
1413194d53e6SMatthew G. Knepley . x - coordinates of the current point
141497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
141597b6e6e8SMatthew G. Knepley . constants - constant parameters
1416194d53e6SMatthew G. Knepley - f0 - output values at the current point
1417194d53e6SMatthew G. Knepley 
1418194d53e6SMatthew G. Knepley   Level: intermediate
1419194d53e6SMatthew G. Knepley 
1420dce8aebaSBarry Smith   Note:
1421dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:  \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)
1422dce8aebaSBarry Smith 
1423dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetResidual()`
1424194d53e6SMatthew G. Knepley @*/
1425d71ae5a4SJacob 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[]))
1426d71ae5a4SJacob Faibussowitsch {
14276528b96dSMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
14286528b96dSMatthew G. Knepley   PetscInt        n0, n1;
14296528b96dSMatthew G. Knepley 
14302764a2aaSMatthew G. Knepley   PetscFunctionBegin;
14316528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
143263a3b9bcSJacob 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);
14339566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1));
14346528b96dSMatthew G. Knepley   *f0 = tmp0 ? tmp0[0] : NULL;
14356528b96dSMatthew G. Knepley   *f1 = tmp1 ? tmp1[0] : NULL;
14363ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
14372764a2aaSMatthew G. Knepley }
14382764a2aaSMatthew G. Knepley 
1439194d53e6SMatthew G. Knepley /*@C
1440194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1441194d53e6SMatthew G. Knepley 
144220f4b53cSBarry Smith   Not Collective
1443194d53e6SMatthew G. Knepley 
1444194d53e6SMatthew G. Knepley   Input Parameters:
1445dce8aebaSBarry Smith + ds - The `PetscDS`
1446194d53e6SMatthew G. Knepley . f  - The test field number
1447194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1448194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1449194d53e6SMatthew G. Knepley 
145020f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
1451dce8aebaSBarry Smith .vb
145220f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1453dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1454dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1455dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], PetscScalar f0[])
1456dce8aebaSBarry Smith .ve
1457194d53e6SMatthew G. Knepley + dim - the spatial dimension
1458194d53e6SMatthew G. Knepley . Nf - the number of fields
1459194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1460194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1461194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1462194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1463194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1464194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1465194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1466194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1467194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1468194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1469194d53e6SMatthew G. Knepley . t - current time
1470194d53e6SMatthew G. Knepley . x - coordinates of the current point
147197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
147297b6e6e8SMatthew G. Knepley . constants - constant parameters
1473194d53e6SMatthew G. Knepley - f0 - output values at the current point
1474194d53e6SMatthew G. Knepley 
1475194d53e6SMatthew G. Knepley   Level: intermediate
1476194d53e6SMatthew G. Knepley 
1477dce8aebaSBarry Smith   Note:
1478dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:  \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)
1479dce8aebaSBarry Smith 
1480dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetResidual()`
1481194d53e6SMatthew G. Knepley @*/
1482d71ae5a4SJacob 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[]))
1483d71ae5a4SJacob Faibussowitsch {
14842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
14856528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1486f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1487f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
148863a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
14899566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1));
14903ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
14912764a2aaSMatthew G. Knepley }
14922764a2aaSMatthew G. Knepley 
14933e75805dSMatthew G. Knepley /*@C
1494cb36c0f9SMatthew G. Knepley   PetscDSGetRHSResidual - Get the pointwise RHS residual function for explicit timestepping for a given test field
1495cb36c0f9SMatthew G. Knepley 
149620f4b53cSBarry Smith   Not Collective
1497cb36c0f9SMatthew G. Knepley 
1498cb36c0f9SMatthew G. Knepley   Input Parameters:
1499dce8aebaSBarry Smith + ds - The `PetscDS`
1500cb36c0f9SMatthew G. Knepley - f  - The test field number
1501cb36c0f9SMatthew G. Knepley 
1502cb36c0f9SMatthew G. Knepley   Output Parameters:
1503cb36c0f9SMatthew G. Knepley + f0 - integrand for the test function term
1504cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term
1505cb36c0f9SMatthew G. Knepley 
150620f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
1507dce8aebaSBarry Smith .vb
150820f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1509dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1510dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1511dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], PetscScalar f0[])
1512dce8aebaSBarry Smith .ve
1513cb36c0f9SMatthew G. Knepley + dim - the spatial dimension
1514cb36c0f9SMatthew G. Knepley . Nf - the number of fields
1515cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1516cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1517cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point
1518cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1519cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1520cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1521cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1522cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1523cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1524cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1525cb36c0f9SMatthew G. Knepley . t - current time
1526cb36c0f9SMatthew G. Knepley . x - coordinates of the current point
1527cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters
1528cb36c0f9SMatthew G. Knepley . constants - constant parameters
1529cb36c0f9SMatthew G. Knepley - f0 - output values at the current point
1530cb36c0f9SMatthew G. Knepley 
1531cb36c0f9SMatthew G. Knepley   Level: intermediate
1532cb36c0f9SMatthew G. Knepley 
1533dce8aebaSBarry Smith   Note:
1534dce8aebaSBarry Smith   We are using a first order FEM model for the weak form: \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)
1535dce8aebaSBarry Smith 
1536dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetRHSResidual()`
1537cb36c0f9SMatthew G. Knepley @*/
1538d71ae5a4SJacob 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[]))
1539d71ae5a4SJacob Faibussowitsch {
1540cb36c0f9SMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
1541cb36c0f9SMatthew G. Knepley   PetscInt        n0, n1;
1542cb36c0f9SMatthew G. Knepley 
1543cb36c0f9SMatthew G. Knepley   PetscFunctionBegin;
1544cb36c0f9SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
154563a3b9bcSJacob 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);
15469566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 100, &n0, &tmp0, &n1, &tmp1));
1547cb36c0f9SMatthew G. Knepley   *f0 = tmp0 ? tmp0[0] : NULL;
1548cb36c0f9SMatthew G. Knepley   *f1 = tmp1 ? tmp1[0] : NULL;
15493ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1550cb36c0f9SMatthew G. Knepley }
1551cb36c0f9SMatthew G. Knepley 
1552cb36c0f9SMatthew G. Knepley /*@C
1553cb36c0f9SMatthew G. Knepley   PetscDSSetRHSResidual - Set the pointwise residual function for explicit timestepping for a given test field
1554cb36c0f9SMatthew G. Knepley 
155520f4b53cSBarry Smith   Not Collective
1556cb36c0f9SMatthew G. Knepley 
1557cb36c0f9SMatthew G. Knepley   Input Parameters:
1558dce8aebaSBarry Smith + ds - The `PetscDS`
1559cb36c0f9SMatthew G. Knepley . f  - The test field number
1560cb36c0f9SMatthew G. Knepley . f0 - integrand for the test function term
1561cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term
1562cb36c0f9SMatthew G. Knepley 
1563dce8aebaSBarry Smith   Clling sequence for the callbacks f0 and f1:
1564dce8aebaSBarry Smith .vb
1565dce8aebaSBarry Smith   f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1566dce8aebaSBarry Smith      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1567dce8aebaSBarry Smith      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1568dce8aebaSBarry Smith      PetscReal t, const PetscReal x[], PetscScalar f0[])
1569dce8aebaSBarry Smith .ve
1570cb36c0f9SMatthew G. Knepley + dim - the spatial dimension
1571cb36c0f9SMatthew G. Knepley . Nf - the number of fields
1572cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1573cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1574cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point
1575cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1576cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1577cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1578cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1579cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1580cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1581cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1582cb36c0f9SMatthew G. Knepley . t - current time
1583cb36c0f9SMatthew G. Knepley . x - coordinates of the current point
1584cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters
1585cb36c0f9SMatthew G. Knepley . constants - constant parameters
1586cb36c0f9SMatthew G. Knepley - f0 - output values at the current point
1587cb36c0f9SMatthew G. Knepley 
1588cb36c0f9SMatthew G. Knepley   Level: intermediate
1589cb36c0f9SMatthew G. Knepley 
1590dce8aebaSBarry Smith   Note:
1591dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:  \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)
1592dce8aebaSBarry Smith 
1593dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetResidual()`
1594cb36c0f9SMatthew G. Knepley @*/
1595d71ae5a4SJacob 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[]))
1596d71ae5a4SJacob Faibussowitsch {
1597cb36c0f9SMatthew G. Knepley   PetscFunctionBegin;
1598cb36c0f9SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1599cb36c0f9SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1600cb36c0f9SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
160163a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
16029566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 100, 0, f0, 0, f1));
16033ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1604cb36c0f9SMatthew G. Knepley }
1605cb36c0f9SMatthew G. Knepley 
1606cb36c0f9SMatthew G. Knepley /*@C
1607dce8aebaSBarry Smith   PetscDSHasJacobian - Checks that the Jacobian functions have been set
16083e75805dSMatthew G. Knepley 
160920f4b53cSBarry Smith   Not Collective
16103e75805dSMatthew G. Knepley 
16113e75805dSMatthew G. Knepley   Input Parameter:
1612dce8aebaSBarry Smith . prob - The `PetscDS`
16133e75805dSMatthew G. Knepley 
16143e75805dSMatthew G. Knepley   Output Parameter:
16153e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
16163e75805dSMatthew G. Knepley 
16173e75805dSMatthew G. Knepley   Level: intermediate
16183e75805dSMatthew G. Knepley 
1619dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
16203e75805dSMatthew G. Knepley @*/
1621d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac)
1622d71ae5a4SJacob Faibussowitsch {
16233e75805dSMatthew G. Knepley   PetscFunctionBegin;
16246528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
16259566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasJacobian(ds->wf, hasJac));
16263ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
16273e75805dSMatthew G. Knepley }
16283e75805dSMatthew G. Knepley 
1629194d53e6SMatthew G. Knepley /*@C
1630194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1631194d53e6SMatthew G. Knepley 
163220f4b53cSBarry Smith   Not Collective
1633194d53e6SMatthew G. Knepley 
1634194d53e6SMatthew G. Knepley   Input Parameters:
1635dce8aebaSBarry Smith + ds - The `PetscDS`
1636194d53e6SMatthew G. Knepley . f  - The test field number
1637194d53e6SMatthew G. Knepley - g  - The field number
1638194d53e6SMatthew G. Knepley 
1639194d53e6SMatthew G. Knepley   Output Parameters:
1640194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1641194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1642194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1643194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1644194d53e6SMatthew G. Knepley 
164520f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
1646dce8aebaSBarry Smith .vb
164720f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1648dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1649dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1650dce8aebaSBarry Smith           PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1651dce8aebaSBarry Smith .ve
1652194d53e6SMatthew G. Knepley + dim - the spatial dimension
1653194d53e6SMatthew G. Knepley . Nf - the number of fields
1654194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1655194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1656194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1657194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1658194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1659194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1660194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1661194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1662194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1663194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1664194d53e6SMatthew G. Knepley . t - current time
16652aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1666194d53e6SMatthew G. Knepley . x - coordinates of the current point
166797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
166897b6e6e8SMatthew G. Knepley . constants - constant parameters
1669194d53e6SMatthew G. Knepley - g0 - output values at the current point
1670194d53e6SMatthew G. Knepley 
1671194d53e6SMatthew G. Knepley   Level: intermediate
1672194d53e6SMatthew G. Knepley 
1673dce8aebaSBarry Smith   Note:
1674dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
1675dce8aebaSBarry Smith   \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
1676dce8aebaSBarry Smith 
1677dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJacobian()`
1678194d53e6SMatthew G. Knepley @*/
1679d71ae5a4SJacob 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[]))
1680d71ae5a4SJacob Faibussowitsch {
16816528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
16826528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
16836528b96dSMatthew G. Knepley 
16842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
16856528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
168663a3b9bcSJacob 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);
168763a3b9bcSJacob 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);
16889566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
16896528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
16906528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
16916528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
16926528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
16933ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
16942764a2aaSMatthew G. Knepley }
16952764a2aaSMatthew G. Knepley 
1696194d53e6SMatthew G. Knepley /*@C
1697194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1698194d53e6SMatthew G. Knepley 
169920f4b53cSBarry Smith   Not Collective
1700194d53e6SMatthew G. Knepley 
1701194d53e6SMatthew G. Knepley   Input Parameters:
1702dce8aebaSBarry Smith + ds - The `PetscDS`
1703194d53e6SMatthew G. Knepley . f  - The test field number
1704194d53e6SMatthew G. Knepley . g  - The field number
1705194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1706194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1707194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1708194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1709194d53e6SMatthew G. Knepley 
171020f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
1711dce8aebaSBarry Smith .vb
171220f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1713dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1714dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1715dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], PetscScalar g0[])
1716dce8aebaSBarry Smith .ve
1717194d53e6SMatthew G. Knepley + dim - the spatial dimension
1718194d53e6SMatthew G. Knepley . Nf - the number of fields
1719194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1720194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1721194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1722194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1723194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1724194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1725194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1726194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1727194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1728194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1729194d53e6SMatthew G. Knepley . t - current time
17302aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1731194d53e6SMatthew G. Knepley . x - coordinates of the current point
173297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
173397b6e6e8SMatthew G. Knepley . constants - constant parameters
1734194d53e6SMatthew G. Knepley - g0 - output values at the current point
1735194d53e6SMatthew G. Knepley 
1736194d53e6SMatthew G. Knepley   Level: intermediate
1737194d53e6SMatthew G. Knepley 
1738dce8aebaSBarry Smith   Note:
1739dce8aebaSBarry Smith    We are using a first order FEM model for the weak form:
1740dce8aebaSBarry Smith   \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
1741dce8aebaSBarry Smith 
1742dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobian()`
1743194d53e6SMatthew G. Knepley @*/
1744d71ae5a4SJacob 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[]))
1745d71ae5a4SJacob Faibussowitsch {
17462764a2aaSMatthew G. Knepley   PetscFunctionBegin;
17476528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
17482764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
17492764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
17502764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
17512764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
175263a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
175363a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
17549566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
17553ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
17562764a2aaSMatthew G. Knepley }
17572764a2aaSMatthew G. Knepley 
1758475e0ac9SMatthew G. Knepley /*@C
1759dce8aebaSBarry Smith   PetscDSUseJacobianPreconditioner - Set whether to construct a Jacobian preconditioner
176055c1f793SMatthew G. Knepley 
176120f4b53cSBarry Smith   Not Collective
176255c1f793SMatthew G. Knepley 
176355c1f793SMatthew G. Knepley   Input Parameters:
1764dce8aebaSBarry Smith + prob - The `PetscDS`
176555c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
176655c1f793SMatthew G. Knepley 
176755c1f793SMatthew G. Knepley   Level: intermediate
176855c1f793SMatthew G. Knepley 
1769dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
177055c1f793SMatthew G. Knepley @*/
1771d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
1772d71ae5a4SJacob Faibussowitsch {
177355c1f793SMatthew G. Knepley   PetscFunctionBegin;
177455c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
177555c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
17763ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
177755c1f793SMatthew G. Knepley }
177855c1f793SMatthew G. Knepley 
177955c1f793SMatthew G. Knepley /*@C
1780dce8aebaSBarry Smith   PetscDSHasJacobianPreconditioner - Checks if a Jacobian preconditioner matrix has been set
1781475e0ac9SMatthew G. Knepley 
178220f4b53cSBarry Smith   Not Collective
1783475e0ac9SMatthew G. Knepley 
1784475e0ac9SMatthew G. Knepley   Input Parameter:
1785dce8aebaSBarry Smith . prob - The `PetscDS`
1786475e0ac9SMatthew G. Knepley 
1787475e0ac9SMatthew G. Knepley   Output Parameter:
1788475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1789475e0ac9SMatthew G. Knepley 
1790475e0ac9SMatthew G. Knepley   Level: intermediate
1791475e0ac9SMatthew G. Knepley 
1792dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
1793475e0ac9SMatthew G. Knepley @*/
1794d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre)
1795d71ae5a4SJacob Faibussowitsch {
1796475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
17976528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1798475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
17993ba16761SJacob Faibussowitsch   if (!ds->useJacPre) PetscFunctionReturn(PETSC_SUCCESS);
18009566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre));
18013ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1802475e0ac9SMatthew G. Knepley }
1803475e0ac9SMatthew G. Knepley 
1804475e0ac9SMatthew G. Knepley /*@C
1805dce8aebaSBarry Smith   PetscDSGetJacobianPreconditioner - Get the pointwise Jacobian preconditioner function for given test and basis field. If this is missing,
1806dce8aebaSBarry Smith    the system matrix is used to build the preconditioner.
1807475e0ac9SMatthew G. Knepley 
180820f4b53cSBarry Smith   Not Collective
1809475e0ac9SMatthew G. Knepley 
1810475e0ac9SMatthew G. Knepley   Input Parameters:
1811dce8aebaSBarry Smith + ds - The `PetscDS`
1812475e0ac9SMatthew G. Knepley . f  - The test field number
1813475e0ac9SMatthew G. Knepley - g  - The field number
1814475e0ac9SMatthew G. Knepley 
1815475e0ac9SMatthew G. Knepley   Output Parameters:
1816475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1817475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1818475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1819475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1820475e0ac9SMatthew G. Knepley 
182120f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
1822dce8aebaSBarry Smith .vb
182320f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1824dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1825dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1826dce8aebaSBarry Smith           PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1827dce8aebaSBarry Smith .ve
1828475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1829475e0ac9SMatthew G. Knepley . Nf - the number of fields
1830475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1831475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1832475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1833475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1834475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1835475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1836475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1837475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1838475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1839475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1840475e0ac9SMatthew G. Knepley . t - current time
1841475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1842475e0ac9SMatthew G. Knepley . x - coordinates of the current point
184397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
184497b6e6e8SMatthew G. Knepley . constants - constant parameters
1845475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1846475e0ac9SMatthew G. Knepley 
1847475e0ac9SMatthew G. Knepley   Level: intermediate
1848475e0ac9SMatthew G. Knepley 
1849dce8aebaSBarry Smith   Note:
1850dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
1851dce8aebaSBarry Smith   \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
1852dce8aebaSBarry Smith 
1853dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
1854475e0ac9SMatthew G. Knepley @*/
1855d71ae5a4SJacob 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[]))
1856d71ae5a4SJacob Faibussowitsch {
18576528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
18586528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
18596528b96dSMatthew G. Knepley 
1860475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
18616528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
186263a3b9bcSJacob 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);
186363a3b9bcSJacob 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);
18649566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
18656528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
18666528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
18676528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
18686528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
18693ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1870475e0ac9SMatthew G. Knepley }
1871475e0ac9SMatthew G. Knepley 
1872475e0ac9SMatthew G. Knepley /*@C
1873dce8aebaSBarry Smith   PetscDSSetJacobianPreconditioner - Set the pointwise Jacobian preconditioner function for given test and basis fields.
1874dce8aebaSBarry Smith   If this is missing, the system matrix is used to build the preconditioner.
1875475e0ac9SMatthew G. Knepley 
187620f4b53cSBarry Smith   Not Collective
1877475e0ac9SMatthew G. Knepley 
1878475e0ac9SMatthew G. Knepley   Input Parameters:
1879dce8aebaSBarry Smith + ds - The `PetscDS`
1880475e0ac9SMatthew G. Knepley . f  - The test field number
1881475e0ac9SMatthew G. Knepley . g  - The field number
1882475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1883475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1884475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1885475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1886475e0ac9SMatthew G. Knepley 
188720f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
1888dce8aebaSBarry Smith .vb
188920f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1890dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1891dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1892dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], PetscScalar g0[])
1893dce8aebaSBarry Smith .ve
1894475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1895475e0ac9SMatthew G. Knepley . Nf - the number of fields
1896475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1897475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1898475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1899475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1900475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1901475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1902475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1903475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1904475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1905475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1906475e0ac9SMatthew G. Knepley . t - current time
1907475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1908475e0ac9SMatthew G. Knepley . x - coordinates of the current point
190997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
191097b6e6e8SMatthew G. Knepley . constants - constant parameters
1911475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1912475e0ac9SMatthew G. Knepley 
1913475e0ac9SMatthew G. Knepley   Level: intermediate
1914475e0ac9SMatthew G. Knepley 
1915dce8aebaSBarry Smith   Note:
1916dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
1917dce8aebaSBarry Smith   \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
1918dce8aebaSBarry Smith 
1919dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobian()`
1920475e0ac9SMatthew G. Knepley @*/
1921d71ae5a4SJacob 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[]))
1922d71ae5a4SJacob Faibussowitsch {
1923475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
19246528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1925475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1926475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1927475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1928475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
192963a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
193063a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
19319566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
19323ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1933475e0ac9SMatthew G. Knepley }
1934475e0ac9SMatthew G. Knepley 
1935b7e05686SMatthew G. Knepley /*@C
1936b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1937b7e05686SMatthew G. Knepley 
193820f4b53cSBarry Smith   Not Collective
1939b7e05686SMatthew G. Knepley 
1940b7e05686SMatthew G. Knepley   Input Parameter:
1941dce8aebaSBarry Smith . ds - The `PetscDS`
1942b7e05686SMatthew G. Knepley 
1943b7e05686SMatthew G. Knepley   Output Parameter:
1944b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1945b7e05686SMatthew G. Knepley 
1946b7e05686SMatthew G. Knepley   Level: intermediate
1947b7e05686SMatthew G. Knepley 
1948dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetDynamicJacobian()`, `PetscDSSetDynamicJacobian()`, `PetscDSGetJacobian()`
1949b7e05686SMatthew G. Knepley @*/
1950d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac)
1951d71ae5a4SJacob Faibussowitsch {
1952b7e05686SMatthew G. Knepley   PetscFunctionBegin;
19536528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
19549566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac));
19553ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1956b7e05686SMatthew G. Knepley }
1957b7e05686SMatthew G. Knepley 
1958b7e05686SMatthew G. Knepley /*@C
1959b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1960b7e05686SMatthew G. Knepley 
196120f4b53cSBarry Smith   Not Collective
1962b7e05686SMatthew G. Knepley 
1963b7e05686SMatthew G. Knepley   Input Parameters:
1964dce8aebaSBarry Smith + ds - The `PetscDS`
1965b7e05686SMatthew G. Knepley . f  - The test field number
1966b7e05686SMatthew G. Knepley - g  - The field number
1967b7e05686SMatthew G. Knepley 
1968b7e05686SMatthew G. Knepley   Output Parameters:
1969b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1970b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1971b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1972b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1973b7e05686SMatthew G. Knepley 
197420f4b53cSBarry Smith    Calling sequence of `g0`, `g1`, `g2` and `g3`:
1975dce8aebaSBarry Smith .vb
197620f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1977dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1978dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1979dce8aebaSBarry Smith           PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1980dce8aebaSBarry Smith .ve
1981b7e05686SMatthew G. Knepley + dim - the spatial dimension
1982b7e05686SMatthew G. Knepley . Nf - the number of fields
1983b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1984b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1985b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1986b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1987b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1988b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1989b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1990b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1991b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1992b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1993b7e05686SMatthew G. Knepley . t - current time
1994b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1995b7e05686SMatthew G. Knepley . x - coordinates of the current point
199697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
199797b6e6e8SMatthew G. Knepley . constants - constant parameters
1998b7e05686SMatthew G. Knepley - g0 - output values at the current point
1999b7e05686SMatthew G. Knepley 
2000b7e05686SMatthew G. Knepley   Level: intermediate
2001b7e05686SMatthew G. Knepley 
2002dce8aebaSBarry Smith   Note:
2003dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2004dce8aebaSBarry Smith   \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
2005dce8aebaSBarry Smith 
2006dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJacobian()`
2007b7e05686SMatthew G. Knepley @*/
2008d71ae5a4SJacob 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[]))
2009d71ae5a4SJacob Faibussowitsch {
20106528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
20116528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
20126528b96dSMatthew G. Knepley 
2013b7e05686SMatthew G. Knepley   PetscFunctionBegin;
20146528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
201563a3b9bcSJacob 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);
201663a3b9bcSJacob 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);
20179566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
20186528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
20196528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
20206528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
20216528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
20223ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2023b7e05686SMatthew G. Knepley }
2024b7e05686SMatthew G. Knepley 
2025b7e05686SMatthew G. Knepley /*@C
2026b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
2027b7e05686SMatthew G. Knepley 
202820f4b53cSBarry Smith   Not Collective
2029b7e05686SMatthew G. Knepley 
2030b7e05686SMatthew G. Knepley   Input Parameters:
2031dce8aebaSBarry Smith + ds - The `PetscDS`
2032b7e05686SMatthew G. Knepley . f  - The test field number
2033b7e05686SMatthew G. Knepley . g  - The field number
2034b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
2035b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2036b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2037b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2038b7e05686SMatthew G. Knepley 
203920f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
2040dce8aebaSBarry Smith .vb
204120f4b53cSBarry Smith    void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2042dce8aebaSBarry Smith            const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2043dce8aebaSBarry Smith            const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2044dce8aebaSBarry Smith            PetscReal t, const PetscReal x[], PetscScalar g0[])
2045dce8aebaSBarry Smith .ve
2046b7e05686SMatthew G. Knepley + dim - the spatial dimension
2047b7e05686SMatthew G. Knepley . Nf - the number of fields
2048b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2049b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2050b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
2051b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2052b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2053b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2054b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2055b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2056b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2057b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2058b7e05686SMatthew G. Knepley . t - current time
2059b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2060b7e05686SMatthew G. Knepley . x - coordinates of the current point
206197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
206297b6e6e8SMatthew G. Knepley . constants - constant parameters
2063b7e05686SMatthew G. Knepley - g0 - output values at the current point
2064b7e05686SMatthew G. Knepley 
2065b7e05686SMatthew G. Knepley   Level: intermediate
2066b7e05686SMatthew G. Knepley 
2067dce8aebaSBarry Smith   Note:
2068dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2069dce8aebaSBarry Smith   \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
2070dce8aebaSBarry Smith 
2071dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobian()`
2072b7e05686SMatthew G. Knepley @*/
2073d71ae5a4SJacob 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[]))
2074d71ae5a4SJacob Faibussowitsch {
2075b7e05686SMatthew G. Knepley   PetscFunctionBegin;
20766528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2077b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
2078b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
2079b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
2080b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
208163a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
208263a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
20839566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
20843ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2085b7e05686SMatthew G. Knepley }
2086b7e05686SMatthew G. Knepley 
20870c2f2876SMatthew G. Knepley /*@C
20880c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
20890c2f2876SMatthew G. Knepley 
209020f4b53cSBarry Smith   Not Collective
20910c2f2876SMatthew G. Knepley 
20924165533cSJose E. Roman   Input Parameters:
2093dce8aebaSBarry Smith + ds - The `PetscDS` object
20940c2f2876SMatthew G. Knepley - f  - The field number
20950c2f2876SMatthew G. Knepley 
20964165533cSJose E. Roman   Output Parameter:
20970c2f2876SMatthew G. Knepley . r    - Riemann solver
20980c2f2876SMatthew G. Knepley 
209920f4b53cSBarry Smith   Calling sequence of `r`:
2100dce8aebaSBarry Smith .vb
210120f4b53cSBarry Smith   void r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
2102dce8aebaSBarry Smith .ve
21035db36cf9SMatthew G. Knepley + dim  - The spatial dimension
21045db36cf9SMatthew G. Knepley . Nf   - The number of fields
21055db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
21060c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
21070c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
21080c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
21090c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
211097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
211197b6e6e8SMatthew G. Knepley . constants - constant parameters
21120c2f2876SMatthew G. Knepley - ctx  - optional user context
21130c2f2876SMatthew G. Knepley 
21140c2f2876SMatthew G. Knepley   Level: intermediate
21150c2f2876SMatthew G. Knepley 
2116dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetRiemannSolver()`
21170c2f2876SMatthew G. Knepley @*/
2118d71ae5a4SJacob 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))
2119d71ae5a4SJacob Faibussowitsch {
21206528b96dSMatthew G. Knepley   PetscRiemannFunc *tmp;
21216528b96dSMatthew G. Knepley   PetscInt          n;
21226528b96dSMatthew G. Knepley 
21230c2f2876SMatthew G. Knepley   PetscFunctionBegin;
21246528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
21250c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
212663a3b9bcSJacob 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);
21279566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, 0, &n, &tmp));
21286528b96dSMatthew G. Knepley   *r = tmp ? tmp[0] : NULL;
21293ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
21300c2f2876SMatthew G. Knepley }
21310c2f2876SMatthew G. Knepley 
21320c2f2876SMatthew G. Knepley /*@C
21330c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
21340c2f2876SMatthew G. Knepley 
213520f4b53cSBarry Smith   Not Collective
21360c2f2876SMatthew G. Knepley 
21374165533cSJose E. Roman   Input Parameters:
2138dce8aebaSBarry Smith + ds - The `PetscDS` object
21390c2f2876SMatthew G. Knepley . f  - The field number
21400c2f2876SMatthew G. Knepley - r  - Riemann solver
21410c2f2876SMatthew G. Knepley 
214220f4b53cSBarry Smith   Calling sequence of `r`:
2143dce8aebaSBarry Smith .vb
214420f4b53cSBarry Smith    void r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
2145dce8aebaSBarry Smith .ve
21465db36cf9SMatthew G. Knepley + dim  - The spatial dimension
21475db36cf9SMatthew G. Knepley . Nf   - The number of fields
21485db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
21490c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
21500c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
21510c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
21520c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
215397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
215497b6e6e8SMatthew G. Knepley . constants - constant parameters
21550c2f2876SMatthew G. Knepley - ctx  - optional user context
21560c2f2876SMatthew G. Knepley 
21570c2f2876SMatthew G. Knepley   Level: intermediate
21580c2f2876SMatthew G. Knepley 
2159dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetRiemannSolver()`
21600c2f2876SMatthew G. Knepley @*/
2161d71ae5a4SJacob 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))
2162d71ae5a4SJacob Faibussowitsch {
21630c2f2876SMatthew G. Knepley   PetscFunctionBegin;
21646528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2165de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
216663a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
21679566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, 0, r));
21683ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
21690c2f2876SMatthew G. Knepley }
21700c2f2876SMatthew G. Knepley 
217132d2bbc9SMatthew G. Knepley /*@C
217232d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
217332d2bbc9SMatthew G. Knepley 
217420f4b53cSBarry Smith   Not Collective
217532d2bbc9SMatthew G. Knepley 
217632d2bbc9SMatthew G. Knepley   Input Parameters:
2177dce8aebaSBarry Smith + ds - The `PetscDS`
217832d2bbc9SMatthew G. Knepley - f  - The field number
217932d2bbc9SMatthew G. Knepley 
2180f899ff85SJose E. Roman   Output Parameter:
2181a2b725a8SWilliam Gropp . update - update function
218232d2bbc9SMatthew G. Knepley 
218320f4b53cSBarry Smith   Calling sequence of `update`:
2184dce8aebaSBarry Smith .vb
218520f4b53cSBarry Smith   void update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2186dce8aebaSBarry Smith               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2187dce8aebaSBarry Smith               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2188dce8aebaSBarry Smith               PetscReal t, const PetscReal x[], PetscScalar uNew[])
2189dce8aebaSBarry Smith .ve
219032d2bbc9SMatthew G. Knepley + dim - the spatial dimension
219132d2bbc9SMatthew G. Knepley . Nf - the number of fields
219232d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
219332d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
219432d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
219532d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
219632d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
219732d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
219832d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
219932d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
220032d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
220132d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
220232d2bbc9SMatthew G. Knepley . t - current time
220332d2bbc9SMatthew G. Knepley . x - coordinates of the current point
220432d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
220532d2bbc9SMatthew G. Knepley 
220632d2bbc9SMatthew G. Knepley   Level: intermediate
220732d2bbc9SMatthew G. Knepley 
2208dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetUpdate()`, `PetscDSSetResidual()`
220932d2bbc9SMatthew G. Knepley @*/
2210d71ae5a4SJacob 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[]))
2211d71ae5a4SJacob Faibussowitsch {
221232d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
22136528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
221463a3b9bcSJacob 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);
22159371c9d4SSatish Balay   if (update) {
22169371c9d4SSatish Balay     PetscValidPointer(update, 3);
22179371c9d4SSatish Balay     *update = ds->update[f];
22189371c9d4SSatish Balay   }
22193ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
222032d2bbc9SMatthew G. Knepley }
222132d2bbc9SMatthew G. Knepley 
222232d2bbc9SMatthew G. Knepley /*@C
22233fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
222432d2bbc9SMatthew G. Knepley 
222520f4b53cSBarry Smith   Not Collective
222632d2bbc9SMatthew G. Knepley 
222732d2bbc9SMatthew G. Knepley   Input Parameters:
2228dce8aebaSBarry Smith + ds     - The `PetscDS`
222932d2bbc9SMatthew G. Knepley . f      - The field number
223032d2bbc9SMatthew G. Knepley - update - update function
223132d2bbc9SMatthew G. Knepley 
223220f4b53cSBarry Smith   Calling sequence of `update`:
2233dce8aebaSBarry Smith .vb
223420f4b53cSBarry Smith   void update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2235dce8aebaSBarry Smith               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2236dce8aebaSBarry Smith               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2237dce8aebaSBarry Smith               PetscReal t, const PetscReal x[], PetscScalar uNew[])
2238dce8aebaSBarry Smith .ve
223932d2bbc9SMatthew G. Knepley + dim - the spatial dimension
224032d2bbc9SMatthew G. Knepley . Nf - the number of fields
224132d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
224232d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
224332d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
224432d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
224532d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
224632d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
224732d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
224832d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
224932d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
225032d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
225132d2bbc9SMatthew G. Knepley . t - current time
225232d2bbc9SMatthew G. Knepley . x - coordinates of the current point
225332d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
225432d2bbc9SMatthew G. Knepley 
225532d2bbc9SMatthew G. Knepley   Level: intermediate
225632d2bbc9SMatthew G. Knepley 
2257dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetResidual()`
225832d2bbc9SMatthew G. Knepley @*/
2259d71ae5a4SJacob 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[]))
2260d71ae5a4SJacob Faibussowitsch {
226132d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
22626528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
226332d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
226463a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
22659566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(ds, f + 1));
22666528b96dSMatthew G. Knepley   ds->update[f] = update;
22673ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
226832d2bbc9SMatthew G. Knepley }
226932d2bbc9SMatthew G. Knepley 
2270d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void *ctx)
2271d71ae5a4SJacob Faibussowitsch {
22720c2f2876SMatthew G. Knepley   PetscFunctionBegin;
22736528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
227463a3b9bcSJacob 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);
22750c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
22763ec1f749SStefano Zampini   *(void **)ctx = ds->ctx[f];
22773ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
22780c2f2876SMatthew G. Knepley }
22790c2f2876SMatthew G. Knepley 
2280d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx)
2281d71ae5a4SJacob Faibussowitsch {
22820c2f2876SMatthew G. Knepley   PetscFunctionBegin;
22836528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
228463a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
22859566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(ds, f + 1));
22866528b96dSMatthew G. Knepley   ds->ctx[f] = ctx;
22873ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
22880c2f2876SMatthew G. Knepley }
22890c2f2876SMatthew G. Knepley 
2290194d53e6SMatthew G. Knepley /*@C
2291194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
2292194d53e6SMatthew G. Knepley 
229320f4b53cSBarry Smith   Not Collective
2294194d53e6SMatthew G. Knepley 
2295194d53e6SMatthew G. Knepley   Input Parameters:
22966528b96dSMatthew G. Knepley + ds - The PetscDS
2297194d53e6SMatthew G. Knepley - f  - The test field number
2298194d53e6SMatthew G. Knepley 
2299194d53e6SMatthew G. Knepley   Output Parameters:
2300194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
2301194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2302194d53e6SMatthew G. Knepley 
230320f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
2304dce8aebaSBarry Smith .vb
230520f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2306dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2307dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2308dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2309dce8aebaSBarry Smith .ve
2310194d53e6SMatthew G. Knepley + dim - the spatial dimension
2311194d53e6SMatthew G. Knepley . Nf - the number of fields
2312194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2313194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2314194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2315194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2316194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2317194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2318194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2319194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2320194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2321194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2322194d53e6SMatthew G. Knepley . t - current time
2323194d53e6SMatthew G. Knepley . x - coordinates of the current point
2324194d53e6SMatthew G. Knepley . n - unit normal at the current point
232597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
232697b6e6e8SMatthew G. Knepley . constants - constant parameters
2327194d53e6SMatthew G. Knepley - f0 - output values at the current point
2328194d53e6SMatthew G. Knepley 
2329194d53e6SMatthew G. Knepley   Level: intermediate
2330194d53e6SMatthew G. Knepley 
2331dce8aebaSBarry Smith   Note:
2332dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2333dce8aebaSBarry Smith   \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
2334dce8aebaSBarry Smith 
2335dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetBdResidual()`
2336194d53e6SMatthew G. Knepley @*/
2337d71ae5a4SJacob 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[]))
2338d71ae5a4SJacob Faibussowitsch {
23396528b96dSMatthew G. Knepley   PetscBdPointFunc *tmp0, *tmp1;
23406528b96dSMatthew G. Knepley   PetscInt          n0, n1;
23416528b96dSMatthew G. Knepley 
23422764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23436528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
234463a3b9bcSJacob 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);
23459566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1));
23466528b96dSMatthew G. Knepley   *f0 = tmp0 ? tmp0[0] : NULL;
23476528b96dSMatthew G. Knepley   *f1 = tmp1 ? tmp1[0] : NULL;
23483ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
23492764a2aaSMatthew G. Knepley }
23502764a2aaSMatthew G. Knepley 
2351194d53e6SMatthew G. Knepley /*@C
2352194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2353194d53e6SMatthew G. Knepley 
235420f4b53cSBarry Smith   Not Collective
2355194d53e6SMatthew G. Knepley 
2356194d53e6SMatthew G. Knepley   Input Parameters:
2357dce8aebaSBarry Smith + ds - The `PetscDS`
2358194d53e6SMatthew G. Knepley . f  - The test field number
2359194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2360194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2361194d53e6SMatthew G. Knepley 
236220f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
2363dce8aebaSBarry Smith .vb
236420f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2365dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2366dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2367dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2368dce8aebaSBarry Smith .ve
2369194d53e6SMatthew G. Knepley + dim - the spatial dimension
2370194d53e6SMatthew G. Knepley . Nf - the number of fields
2371194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2372194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2373194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2374194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2375194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2376194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2377194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2378194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2379194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2380194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2381194d53e6SMatthew G. Knepley . t - current time
2382194d53e6SMatthew G. Knepley . x - coordinates of the current point
2383194d53e6SMatthew G. Knepley . n - unit normal at the current point
238497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
238597b6e6e8SMatthew G. Knepley . constants - constant parameters
2386194d53e6SMatthew G. Knepley - f0 - output values at the current point
2387194d53e6SMatthew G. Knepley 
2388194d53e6SMatthew G. Knepley   Level: intermediate
2389194d53e6SMatthew G. Knepley 
2390dce8aebaSBarry Smith   Note:
2391dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2392dce8aebaSBarry Smith   \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
2393dce8aebaSBarry Smith 
2394dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetBdResidual()`
2395194d53e6SMatthew G. Knepley @*/
2396d71ae5a4SJacob 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[]))
2397d71ae5a4SJacob Faibussowitsch {
23982764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23996528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
240063a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
24019566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1));
24023ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
24032764a2aaSMatthew G. Knepley }
24042764a2aaSMatthew G. Knepley 
240527f02ce8SMatthew G. Knepley /*@
2406dce8aebaSBarry Smith   PetscDSHasBdJacobian - Indicates that boundary Jacobian functions have been set
240727f02ce8SMatthew G. Knepley 
240820f4b53cSBarry Smith   Not Collective
240927f02ce8SMatthew G. Knepley 
241027f02ce8SMatthew G. Knepley   Input Parameter:
2411dce8aebaSBarry Smith . ds - The `PetscDS`
241227f02ce8SMatthew G. Knepley 
241327f02ce8SMatthew G. Knepley   Output Parameter:
241427f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set
241527f02ce8SMatthew G. Knepley 
241627f02ce8SMatthew G. Knepley   Level: intermediate
241727f02ce8SMatthew G. Knepley 
2418dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()`
241927f02ce8SMatthew G. Knepley @*/
2420d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac)
2421d71ae5a4SJacob Faibussowitsch {
242227f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24236528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24246528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJac, 2);
24259566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasBdJacobian(ds->wf, hasBdJac));
24263ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
242727f02ce8SMatthew G. Knepley }
242827f02ce8SMatthew G. Knepley 
2429194d53e6SMatthew G. Knepley /*@C
2430194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2431194d53e6SMatthew G. Knepley 
243220f4b53cSBarry Smith   Not Collective
2433194d53e6SMatthew G. Knepley 
2434194d53e6SMatthew G. Knepley   Input Parameters:
2435dce8aebaSBarry Smith + ds - The `PetscDS`
2436194d53e6SMatthew G. Knepley . f  - The test field number
2437194d53e6SMatthew G. Knepley - g  - The field number
2438194d53e6SMatthew G. Knepley 
2439194d53e6SMatthew G. Knepley   Output Parameters:
2440194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2441194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2442194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2443194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2444194d53e6SMatthew G. Knepley 
244520f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
2446dce8aebaSBarry Smith .vb
244720f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2448dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2449dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2450dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2451dce8aebaSBarry Smith .ve
2452194d53e6SMatthew G. Knepley + dim - the spatial dimension
2453194d53e6SMatthew G. Knepley . Nf - the number of fields
2454194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2455194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2456194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2457194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2458194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2459194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2460194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2461194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2462194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2463194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2464194d53e6SMatthew G. Knepley . t - current time
24652aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2466194d53e6SMatthew G. Knepley . x - coordinates of the current point
2467194d53e6SMatthew G. Knepley . n - normal at the current point
246897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
246997b6e6e8SMatthew G. Knepley . constants - constant parameters
2470194d53e6SMatthew G. Knepley - g0 - output values at the current point
2471194d53e6SMatthew G. Knepley 
2472194d53e6SMatthew G. Knepley   Level: intermediate
2473194d53e6SMatthew G. Knepley 
2474dce8aebaSBarry Smith   Note:
2475dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2476dce8aebaSBarry Smith   \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
2477dce8aebaSBarry Smith 
2478dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetBdJacobian()`
2479194d53e6SMatthew G. Knepley @*/
2480d71ae5a4SJacob 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[]))
2481d71ae5a4SJacob Faibussowitsch {
24826528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
24836528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
24846528b96dSMatthew G. Knepley 
24852764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24866528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
248763a3b9bcSJacob 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);
248863a3b9bcSJacob 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);
24899566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
24906528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
24916528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
24926528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
24936528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
24943ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
24952764a2aaSMatthew G. Knepley }
24962764a2aaSMatthew G. Knepley 
2497194d53e6SMatthew G. Knepley /*@C
2498194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2499194d53e6SMatthew G. Knepley 
250020f4b53cSBarry Smith   Not Collective
2501194d53e6SMatthew G. Knepley 
2502194d53e6SMatthew G. Knepley   Input Parameters:
25036528b96dSMatthew G. Knepley + ds - The PetscDS
2504194d53e6SMatthew G. Knepley . f  - The test field number
2505194d53e6SMatthew G. Knepley . g  - The field number
2506194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2507194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2508194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2509194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2510194d53e6SMatthew G. Knepley 
251120f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
2512dce8aebaSBarry Smith .vb
251320f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2514dce8aebaSBarry Smith        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2515dce8aebaSBarry Smith        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2516dce8aebaSBarry Smith        PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2517dce8aebaSBarry Smith .ve
2518194d53e6SMatthew G. Knepley + dim - the spatial dimension
2519194d53e6SMatthew G. Knepley . Nf - the number of fields
2520194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2521194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2522194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2523194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2524194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2525194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2526194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2527194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2528194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2529194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2530194d53e6SMatthew G. Knepley . t - current time
25312aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2532194d53e6SMatthew G. Knepley . x - coordinates of the current point
2533194d53e6SMatthew G. Knepley . n - normal at the current point
253497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
253597b6e6e8SMatthew G. Knepley . constants - constant parameters
2536194d53e6SMatthew G. Knepley - g0 - output values at the current point
2537194d53e6SMatthew G. Knepley 
2538194d53e6SMatthew G. Knepley   Level: intermediate
2539194d53e6SMatthew G. Knepley 
2540dce8aebaSBarry Smith   Note:
2541dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2542dce8aebaSBarry Smith   \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
2543dce8aebaSBarry Smith 
2544dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetBdJacobian()`
2545194d53e6SMatthew G. Knepley @*/
2546d71ae5a4SJacob 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[]))
2547d71ae5a4SJacob Faibussowitsch {
25482764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25496528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
25502764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
25512764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
25522764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
25532764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
255463a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
255563a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
25569566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
25573ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
25582764a2aaSMatthew G. Knepley }
25592764a2aaSMatthew G. Knepley 
256027f02ce8SMatthew G. Knepley /*@
256127f02ce8SMatthew G. Knepley   PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set
256227f02ce8SMatthew G. Knepley 
256320f4b53cSBarry Smith   Not Collective
256427f02ce8SMatthew G. Knepley 
256527f02ce8SMatthew G. Knepley   Input Parameter:
2566dce8aebaSBarry Smith . ds - The `PetscDS`
256727f02ce8SMatthew G. Knepley 
256827f02ce8SMatthew G. Knepley   Output Parameter:
256927f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set
257027f02ce8SMatthew G. Knepley 
257127f02ce8SMatthew G. Knepley   Level: intermediate
257227f02ce8SMatthew G. Knepley 
2573dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()`
257427f02ce8SMatthew G. Knepley @*/
2575d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre)
2576d71ae5a4SJacob Faibussowitsch {
257727f02ce8SMatthew G. Knepley   PetscFunctionBegin;
25786528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
25796528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJacPre, 2);
25809566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre));
25813ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
258227f02ce8SMatthew G. Knepley }
258327f02ce8SMatthew G. Knepley 
258427f02ce8SMatthew G. Knepley /*@C
258527f02ce8SMatthew G. Knepley   PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field
258627f02ce8SMatthew G. Knepley 
258720f4b53cSBarry Smith   Not Collective; No Fortran Support
258827f02ce8SMatthew G. Knepley 
258927f02ce8SMatthew G. Knepley   Input Parameters:
2590dce8aebaSBarry Smith + ds - The `PetscDS`
259127f02ce8SMatthew G. Knepley . f  - The test field number
259227f02ce8SMatthew G. Knepley - g  - The field number
259327f02ce8SMatthew G. Knepley 
259427f02ce8SMatthew G. Knepley   Output Parameters:
259527f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term
259627f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
259727f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
259827f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
259927f02ce8SMatthew G. Knepley 
260020f4b53cSBarry Smith    Calling sequence of `g0`, `g1`, `g2` and `g3`:
2601dce8aebaSBarry Smith .vb
260220f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2603dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2604dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2605dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
2606dce8aebaSBarry Smith .ve
260727f02ce8SMatthew G. Knepley + dim - the spatial dimension
260827f02ce8SMatthew G. Knepley . Nf - the number of fields
260927f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
261027f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
261127f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
261227f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
261327f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
261427f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
261527f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
261627f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
261727f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
261827f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
261927f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
262027f02ce8SMatthew G. Knepley . t - current time
262127f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
262227f02ce8SMatthew G. Knepley . x - coordinates of the current point
262327f02ce8SMatthew G. Knepley . n - normal at the current point
262427f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
262527f02ce8SMatthew G. Knepley . constants - constant parameters
262627f02ce8SMatthew G. Knepley - g0 - output values at the current point
262727f02ce8SMatthew G. Knepley 
262827f02ce8SMatthew G. Knepley   Level: intermediate
262927f02ce8SMatthew G. Knepley 
2630dce8aebaSBarry Smith   Note:
2631dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2632dce8aebaSBarry Smith   \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
2633dce8aebaSBarry Smith 
2634dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetBdJacobianPreconditioner()`
263527f02ce8SMatthew G. Knepley @*/
2636d71ae5a4SJacob 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[]))
2637d71ae5a4SJacob Faibussowitsch {
26386528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
26396528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
26406528b96dSMatthew G. Knepley 
264127f02ce8SMatthew G. Knepley   PetscFunctionBegin;
26426528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
264363a3b9bcSJacob 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);
264463a3b9bcSJacob 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);
26459566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
26466528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
26476528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
26486528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
26496528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
26503ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
265127f02ce8SMatthew G. Knepley }
265227f02ce8SMatthew G. Knepley 
265327f02ce8SMatthew G. Knepley /*@C
265427f02ce8SMatthew G. Knepley   PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field
265527f02ce8SMatthew G. Knepley 
265620f4b53cSBarry Smith   Not Collective; No Fortran Support
265727f02ce8SMatthew G. Knepley 
265827f02ce8SMatthew G. Knepley   Input Parameters:
2659dce8aebaSBarry Smith + ds - The `PetscDS`
266027f02ce8SMatthew G. Knepley . f  - The test field number
266127f02ce8SMatthew G. Knepley . g  - The field number
266227f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term
266327f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
266427f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
266527f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
266627f02ce8SMatthew G. Knepley 
266720f4b53cSBarry Smith    Calling sequence of `g0`, `g1`, `g2` and `g3`:
2668dce8aebaSBarry Smith .vb
266920f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2670dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2671dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2672dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
2673dce8aebaSBarry Smith .ve
267427f02ce8SMatthew G. Knepley + dim - the spatial dimension
267527f02ce8SMatthew G. Knepley . Nf - the number of fields
267627f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
267727f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
267827f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
267927f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
268027f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
268127f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
268227f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
268327f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
268427f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
268527f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
268627f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
268727f02ce8SMatthew G. Knepley . t - current time
268827f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
268927f02ce8SMatthew G. Knepley . x - coordinates of the current point
269027f02ce8SMatthew G. Knepley . n - normal at the current point
269127f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
269227f02ce8SMatthew G. Knepley . constants - constant parameters
269327f02ce8SMatthew G. Knepley - g0 - output values at the current point
269427f02ce8SMatthew G. Knepley 
269527f02ce8SMatthew G. Knepley   Level: intermediate
269627f02ce8SMatthew G. Knepley 
2697dce8aebaSBarry Smith   Note:
2698dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2699dce8aebaSBarry Smith   \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
2700dce8aebaSBarry Smith 
2701dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetBdJacobianPreconditioner()`
270227f02ce8SMatthew G. Knepley @*/
2703d71ae5a4SJacob 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[]))
2704d71ae5a4SJacob Faibussowitsch {
270527f02ce8SMatthew G. Knepley   PetscFunctionBegin;
27066528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
270727f02ce8SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
270827f02ce8SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
270927f02ce8SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
271027f02ce8SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
271163a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
271263a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
27139566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
27143ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
271527f02ce8SMatthew G. Knepley }
271627f02ce8SMatthew G. Knepley 
27170d3e9b51SMatthew G. Knepley /*@C
2718c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2719c371a6d1SMatthew G. Knepley 
272020f4b53cSBarry Smith   Not Collective
2721c371a6d1SMatthew G. Knepley 
2722c371a6d1SMatthew G. Knepley   Input Parameters:
2723c371a6d1SMatthew G. Knepley + prob - The PetscDS
2724c371a6d1SMatthew G. Knepley - f    - The test field number
2725c371a6d1SMatthew G. Knepley 
2726d8d19677SJose E. Roman   Output Parameters:
272795cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field
272895cbbfd3SMatthew G. Knepley - exactCtx - exact solution context
2729c371a6d1SMatthew G. Knepley 
273020f4b53cSBarry Smith   Calling sequence of `exactSol`:
2731dce8aebaSBarry Smith .vb
273220f4b53cSBarry Smith   PetscErrorCode sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2733dce8aebaSBarry Smith .ve
2734c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2735c371a6d1SMatthew G. Knepley . t - current time
2736c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2737c371a6d1SMatthew G. Knepley . Nc - the number of field components
2738c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2739c371a6d1SMatthew G. Knepley - ctx - a user context
2740c371a6d1SMatthew G. Knepley 
2741c371a6d1SMatthew G. Knepley   Level: intermediate
2742c371a6d1SMatthew G. Knepley 
2743dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetExactSolution()`, `PetscDSGetExactSolutionTimeDerivative()`
2744c371a6d1SMatthew G. Knepley @*/
2745d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2746d71ae5a4SJacob Faibussowitsch {
2747c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2748c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
274963a3b9bcSJacob 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);
27509371c9d4SSatish Balay   if (sol) {
27519371c9d4SSatish Balay     PetscValidPointer(sol, 3);
27529371c9d4SSatish Balay     *sol = prob->exactSol[f];
27539371c9d4SSatish Balay   }
27549371c9d4SSatish Balay   if (ctx) {
27559371c9d4SSatish Balay     PetscValidPointer(ctx, 4);
27569371c9d4SSatish Balay     *ctx = prob->exactCtx[f];
27579371c9d4SSatish Balay   }
27583ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2759c371a6d1SMatthew G. Knepley }
2760c371a6d1SMatthew G. Knepley 
2761c371a6d1SMatthew G. Knepley /*@C
2762578a5ef5SMatthew Knepley   PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field
2763c371a6d1SMatthew G. Knepley 
276420f4b53cSBarry Smith   Not Collective
2765c371a6d1SMatthew G. Knepley 
2766c371a6d1SMatthew G. Knepley   Input Parameters:
2767dce8aebaSBarry Smith + prob - The `PetscDS`
2768c371a6d1SMatthew G. Knepley . f    - The test field number
276995cbbfd3SMatthew G. Knepley . sol  - solution function for the test fields
277020f4b53cSBarry Smith - ctx  - solution context or `NULL`
2771c371a6d1SMatthew G. Knepley 
277220f4b53cSBarry Smith   Calling sequence of `sol`:
2773dce8aebaSBarry Smith .vb
277420f4b53cSBarry Smith   PetscErrorCode sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2775dce8aebaSBarry Smith .ve
2776c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2777c371a6d1SMatthew G. Knepley . t - current time
2778c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2779c371a6d1SMatthew G. Knepley . Nc - the number of field components
2780c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2781c371a6d1SMatthew G. Knepley - ctx - a user context
2782c371a6d1SMatthew G. Knepley 
2783c371a6d1SMatthew G. Knepley   Level: intermediate
2784c371a6d1SMatthew G. Knepley 
2785dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetExactSolution()`
2786c371a6d1SMatthew G. Knepley @*/
2787d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2788d71ae5a4SJacob Faibussowitsch {
2789c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2790c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
279163a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
27929566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(prob, f + 1));
27939371c9d4SSatish Balay   if (sol) {
27949371c9d4SSatish Balay     PetscValidFunction(sol, 3);
27959371c9d4SSatish Balay     prob->exactSol[f] = sol;
27969371c9d4SSatish Balay   }
27979371c9d4SSatish Balay   if (ctx) {
27989371c9d4SSatish Balay     PetscValidFunction(ctx, 4);
27999371c9d4SSatish Balay     prob->exactCtx[f] = ctx;
28009371c9d4SSatish Balay   }
28013ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2802c371a6d1SMatthew G. Knepley }
2803c371a6d1SMatthew G. Knepley 
28045638fd0eSMatthew G. Knepley /*@C
2805f2cacb80SMatthew G. Knepley   PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field
2806f2cacb80SMatthew G. Knepley 
280720f4b53cSBarry Smith   Not Collective
2808f2cacb80SMatthew G. Knepley 
2809f2cacb80SMatthew G. Knepley   Input Parameters:
2810dce8aebaSBarry Smith + prob - The `PetscDS`
2811f2cacb80SMatthew G. Knepley - f    - The test field number
2812f2cacb80SMatthew G. Knepley 
2813d8d19677SJose E. Roman   Output Parameters:
2814f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field
2815f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context
2816f2cacb80SMatthew G. Knepley 
281720f4b53cSBarry Smith   Calling sequence of `exactSol`:
2818dce8aebaSBarry Smith .vb
281920f4b53cSBarry Smith   PetscErrorCode sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2820dce8aebaSBarry Smith .ve
2821f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2822f2cacb80SMatthew G. Knepley . t - current time
2823f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2824f2cacb80SMatthew G. Knepley . Nc - the number of field components
2825f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2826f2cacb80SMatthew G. Knepley - ctx - a user context
2827f2cacb80SMatthew G. Knepley 
2828f2cacb80SMatthew G. Knepley   Level: intermediate
2829f2cacb80SMatthew G. Knepley 
2830dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetExactSolutionTimeDerivative()`, `PetscDSGetExactSolution()`
2831f2cacb80SMatthew G. Knepley @*/
2832d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2833d71ae5a4SJacob Faibussowitsch {
2834f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2835f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
283663a3b9bcSJacob 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);
28379371c9d4SSatish Balay   if (sol) {
28389371c9d4SSatish Balay     PetscValidPointer(sol, 3);
28399371c9d4SSatish Balay     *sol = prob->exactSol_t[f];
28409371c9d4SSatish Balay   }
28419371c9d4SSatish Balay   if (ctx) {
28429371c9d4SSatish Balay     PetscValidPointer(ctx, 4);
28439371c9d4SSatish Balay     *ctx = prob->exactCtx_t[f];
28449371c9d4SSatish Balay   }
28453ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2846f2cacb80SMatthew G. Knepley }
2847f2cacb80SMatthew G. Knepley 
2848f2cacb80SMatthew G. Knepley /*@C
2849f2cacb80SMatthew G. Knepley   PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field
2850f2cacb80SMatthew G. Knepley 
285120f4b53cSBarry Smith   Not Collective
2852f2cacb80SMatthew G. Knepley 
2853f2cacb80SMatthew G. Knepley   Input Parameters:
2854dce8aebaSBarry Smith + prob - The `PetscDS`
2855f2cacb80SMatthew G. Knepley . f    - The test field number
2856f2cacb80SMatthew G. Knepley . sol  - time derivative of the solution function for the test fields
285720f4b53cSBarry Smith - ctx  - time derivative of the solution context or `NULL`
2858f2cacb80SMatthew G. Knepley 
285920f4b53cSBarry Smith   Calling sequence of `sol`:
2860dce8aebaSBarry Smith .vb
286120f4b53cSBarry Smith   PetscErrorCode sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2862dce8aebaSBarry Smith .ve
2863f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2864f2cacb80SMatthew G. Knepley . t - current time
2865f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2866f2cacb80SMatthew G. Knepley . Nc - the number of field components
2867f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2868f2cacb80SMatthew G. Knepley - ctx - a user context
2869f2cacb80SMatthew G. Knepley 
2870f2cacb80SMatthew G. Knepley   Level: intermediate
2871f2cacb80SMatthew G. Knepley 
2872dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetExactSolutionTimeDerivative()`, `PetscDSSetExactSolution()`
2873f2cacb80SMatthew G. Knepley @*/
2874d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2875d71ae5a4SJacob Faibussowitsch {
2876f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2877f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
287863a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
28799566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(prob, f + 1));
28809371c9d4SSatish Balay   if (sol) {
28819371c9d4SSatish Balay     PetscValidFunction(sol, 3);
28829371c9d4SSatish Balay     prob->exactSol_t[f] = sol;
28839371c9d4SSatish Balay   }
28849371c9d4SSatish Balay   if (ctx) {
28859371c9d4SSatish Balay     PetscValidFunction(ctx, 4);
28869371c9d4SSatish Balay     prob->exactCtx_t[f] = ctx;
28879371c9d4SSatish Balay   }
28883ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2889f2cacb80SMatthew G. Knepley }
2890f2cacb80SMatthew G. Knepley 
2891f2cacb80SMatthew G. Knepley /*@C
289297b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
289397b6e6e8SMatthew G. Knepley 
289420f4b53cSBarry Smith   Not Collective
289597b6e6e8SMatthew G. Knepley 
289697b6e6e8SMatthew G. Knepley   Input Parameter:
2897dce8aebaSBarry Smith . prob - The `PetscDS` object
289897b6e6e8SMatthew G. Knepley 
289997b6e6e8SMatthew G. Knepley   Output Parameters:
290097b6e6e8SMatthew G. Knepley + numConstants - The number of constants
290197b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
290297b6e6e8SMatthew G. Knepley 
290397b6e6e8SMatthew G. Knepley   Level: intermediate
290497b6e6e8SMatthew G. Knepley 
2905dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetConstants()`, `PetscDSCreate()`
290697b6e6e8SMatthew G. Knepley @*/
2907d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
2908d71ae5a4SJacob Faibussowitsch {
290997b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
291097b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29119371c9d4SSatish Balay   if (numConstants) {
29129371c9d4SSatish Balay     PetscValidIntPointer(numConstants, 2);
29139371c9d4SSatish Balay     *numConstants = prob->numConstants;
29149371c9d4SSatish Balay   }
29159371c9d4SSatish Balay   if (constants) {
29169371c9d4SSatish Balay     PetscValidPointer(constants, 3);
29179371c9d4SSatish Balay     *constants = prob->constants;
29189371c9d4SSatish Balay   }
29193ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
292097b6e6e8SMatthew G. Knepley }
292197b6e6e8SMatthew G. Knepley 
29220d3e9b51SMatthew G. Knepley /*@C
292397b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
292497b6e6e8SMatthew G. Knepley 
292520f4b53cSBarry Smith   Not Collective
292697b6e6e8SMatthew G. Knepley 
292797b6e6e8SMatthew G. Knepley   Input Parameters:
2928dce8aebaSBarry Smith + prob         - The `PetscDS` object
292997b6e6e8SMatthew G. Knepley . numConstants - The number of constants
293097b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
293197b6e6e8SMatthew G. Knepley 
293297b6e6e8SMatthew G. Knepley   Level: intermediate
293397b6e6e8SMatthew G. Knepley 
2934dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetConstants()`, `PetscDSCreate()`
293597b6e6e8SMatthew G. Knepley @*/
2936d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
2937d71ae5a4SJacob Faibussowitsch {
293897b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
293997b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
294097b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
29419566063dSJacob Faibussowitsch     PetscCall(PetscFree(prob->constants));
294297b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
294397b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
29449566063dSJacob Faibussowitsch       PetscCall(PetscMalloc1(prob->numConstants, &prob->constants));
294520be0f5bSMatthew G. Knepley     } else {
294620be0f5bSMatthew G. Knepley       prob->constants = NULL;
294720be0f5bSMatthew G. Knepley     }
294820be0f5bSMatthew G. Knepley   }
294920be0f5bSMatthew G. Knepley   if (prob->numConstants) {
2950dadcf809SJacob Faibussowitsch     PetscValidScalarPointer(constants, 3);
29519566063dSJacob Faibussowitsch     PetscCall(PetscArraycpy(prob->constants, constants, prob->numConstants));
295297b6e6e8SMatthew G. Knepley   }
29533ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
295497b6e6e8SMatthew G. Knepley }
295597b6e6e8SMatthew G. Knepley 
29564cd1e086SMatthew G. Knepley /*@
29574cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
29584cd1e086SMatthew G. Knepley 
295920f4b53cSBarry Smith   Not Collective
29604cd1e086SMatthew G. Knepley 
29614cd1e086SMatthew G. Knepley   Input Parameters:
2962dce8aebaSBarry Smith + prob - The `PetscDS` object
29634cd1e086SMatthew G. Knepley - disc - The discretization object
29644cd1e086SMatthew G. Knepley 
29654cd1e086SMatthew G. Knepley   Output Parameter:
29664cd1e086SMatthew G. Knepley . f - The field number
29674cd1e086SMatthew G. Knepley 
29684cd1e086SMatthew G. Knepley   Level: beginner
29694cd1e086SMatthew G. Knepley 
2970dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscGetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
29714cd1e086SMatthew G. Knepley @*/
2972d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
2973d71ae5a4SJacob Faibussowitsch {
29744cd1e086SMatthew G. Knepley   PetscInt g;
29754cd1e086SMatthew G. Knepley 
29764cd1e086SMatthew G. Knepley   PetscFunctionBegin;
29774cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2978dadcf809SJacob Faibussowitsch   PetscValidIntPointer(f, 3);
29794cd1e086SMatthew G. Knepley   *f = -1;
29809371c9d4SSatish Balay   for (g = 0; g < prob->Nf; ++g) {
29819371c9d4SSatish Balay     if (disc == prob->disc[g]) break;
29829371c9d4SSatish Balay   }
298308401ef6SPierre Jolivet   PetscCheck(g != prob->Nf, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
29844cd1e086SMatthew G. Knepley   *f = g;
29853ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
29864cd1e086SMatthew G. Knepley }
29874cd1e086SMatthew G. Knepley 
29884cd1e086SMatthew G. Knepley /*@
29894cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
29904cd1e086SMatthew G. Knepley 
299120f4b53cSBarry Smith   Not Collective
29924cd1e086SMatthew G. Knepley 
29934cd1e086SMatthew G. Knepley   Input Parameters:
2994dce8aebaSBarry Smith + prob - The `PetscDS` object
29954cd1e086SMatthew G. Knepley - f - The field number
29964cd1e086SMatthew G. Knepley 
29974cd1e086SMatthew G. Knepley   Output Parameter:
29984cd1e086SMatthew G. Knepley . size - The size
29994cd1e086SMatthew G. Knepley 
30004cd1e086SMatthew G. Knepley   Level: beginner
30014cd1e086SMatthew G. Knepley 
3002dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetFieldOffset()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
30034cd1e086SMatthew G. Knepley @*/
3004d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
3005d71ae5a4SJacob Faibussowitsch {
30064cd1e086SMatthew G. Knepley   PetscFunctionBegin;
30074cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3008dadcf809SJacob Faibussowitsch   PetscValidIntPointer(size, 3);
300963a3b9bcSJacob 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);
30109566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3011d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
30123ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
30134cd1e086SMatthew G. Knepley }
30144cd1e086SMatthew G. Knepley 
3015bc4ae4beSMatthew G. Knepley /*@
3016bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
3017bc4ae4beSMatthew G. Knepley 
301820f4b53cSBarry Smith   Not Collective
3019bc4ae4beSMatthew G. Knepley 
3020bc4ae4beSMatthew G. Knepley   Input Parameters:
3021dce8aebaSBarry Smith + prob - The `PetscDS` object
3022bc4ae4beSMatthew G. Knepley - f - The field number
3023bc4ae4beSMatthew G. Knepley 
3024bc4ae4beSMatthew G. Knepley   Output Parameter:
3025bc4ae4beSMatthew G. Knepley . off - The offset
3026bc4ae4beSMatthew G. Knepley 
3027bc4ae4beSMatthew G. Knepley   Level: beginner
3028bc4ae4beSMatthew G. Knepley 
3029dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
3030bc4ae4beSMatthew G. Knepley @*/
3031d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
3032d71ae5a4SJacob Faibussowitsch {
30334cd1e086SMatthew G. Knepley   PetscInt size, g;
30342764a2aaSMatthew G. Knepley 
30352764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30362764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3037dadcf809SJacob Faibussowitsch   PetscValidIntPointer(off, 3);
303863a3b9bcSJacob 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);
30392764a2aaSMatthew G. Knepley   *off = 0;
30402764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
30419566063dSJacob Faibussowitsch     PetscCall(PetscDSGetFieldSize(prob, g, &size));
30424cd1e086SMatthew G. Knepley     *off += size;
30432764a2aaSMatthew G. Knepley   }
30443ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
30452764a2aaSMatthew G. Knepley }
30462764a2aaSMatthew G. Knepley 
3047bc4ae4beSMatthew G. Knepley /*@
30485fedec97SMatthew G. Knepley   PetscDSGetFieldOffsetCohesive - Returns the offset of the given field in the full space basis on a cohesive cell
30495fedec97SMatthew G. Knepley 
305020f4b53cSBarry Smith   Not Collective
30515fedec97SMatthew G. Knepley 
30525fedec97SMatthew G. Knepley   Input Parameters:
3053dce8aebaSBarry Smith + prob - The `PetscDS` object
30545fedec97SMatthew G. Knepley - f - The field number
30555fedec97SMatthew G. Knepley 
30565fedec97SMatthew G. Knepley   Output Parameter:
30575fedec97SMatthew G. Knepley . off - The offset
30585fedec97SMatthew G. Knepley 
30595fedec97SMatthew G. Knepley   Level: beginner
30605fedec97SMatthew G. Knepley 
3061dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
30625fedec97SMatthew G. Knepley @*/
3063d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldOffsetCohesive(PetscDS ds, PetscInt f, PetscInt *off)
3064d71ae5a4SJacob Faibussowitsch {
30655fedec97SMatthew G. Knepley   PetscInt size, g;
30665fedec97SMatthew G. Knepley 
30675fedec97SMatthew G. Knepley   PetscFunctionBegin;
30685fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3069dadcf809SJacob Faibussowitsch   PetscValidIntPointer(off, 3);
307063a3b9bcSJacob 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);
30715fedec97SMatthew G. Knepley   *off = 0;
30725fedec97SMatthew G. Knepley   for (g = 0; g < f; ++g) {
30735fedec97SMatthew G. Knepley     PetscBool cohesive;
30745fedec97SMatthew G. Knepley 
30759566063dSJacob Faibussowitsch     PetscCall(PetscDSGetCohesive(ds, g, &cohesive));
30769566063dSJacob Faibussowitsch     PetscCall(PetscDSGetFieldSize(ds, g, &size));
30775fedec97SMatthew G. Knepley     *off += cohesive ? size : size * 2;
30785fedec97SMatthew G. Knepley   }
30793ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
30805fedec97SMatthew G. Knepley }
30815fedec97SMatthew G. Knepley 
30825fedec97SMatthew G. Knepley /*@
308347e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
3084bc4ae4beSMatthew G. Knepley 
308520f4b53cSBarry Smith   Not Collective
3086bc4ae4beSMatthew G. Knepley 
308747e57110SSander Arens   Input Parameter:
3088dce8aebaSBarry Smith . prob - The `PetscDS` object
3089bc4ae4beSMatthew G. Knepley 
3090bc4ae4beSMatthew G. Knepley   Output Parameter:
309147e57110SSander Arens . dimensions - The number of dimensions
3092bc4ae4beSMatthew G. Knepley 
3093bc4ae4beSMatthew G. Knepley   Level: beginner
3094bc4ae4beSMatthew G. Knepley 
3095dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
3096bc4ae4beSMatthew G. Knepley @*/
3097d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
3098d71ae5a4SJacob Faibussowitsch {
30992764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31002764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31019566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
310247e57110SSander Arens   PetscValidPointer(dimensions, 2);
310347e57110SSander Arens   *dimensions = prob->Nb;
31043ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
31056ce16762SMatthew G. Knepley }
310647e57110SSander Arens 
310747e57110SSander Arens /*@
310847e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
310947e57110SSander Arens 
311020f4b53cSBarry Smith   Not Collective
311147e57110SSander Arens 
311247e57110SSander Arens   Input Parameter:
3113dce8aebaSBarry Smith . prob - The `PetscDS` object
311447e57110SSander Arens 
311547e57110SSander Arens   Output Parameter:
311647e57110SSander Arens . components - The number of components
311747e57110SSander Arens 
311847e57110SSander Arens   Level: beginner
311947e57110SSander Arens 
3120dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
312147e57110SSander Arens @*/
3122d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
3123d71ae5a4SJacob Faibussowitsch {
312447e57110SSander Arens   PetscFunctionBegin;
312547e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
31269566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
312747e57110SSander Arens   PetscValidPointer(components, 2);
312847e57110SSander Arens   *components = prob->Nc;
31293ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
31306ce16762SMatthew G. Knepley }
31316ce16762SMatthew G. Knepley 
31326ce16762SMatthew G. Knepley /*@
31336ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
31346ce16762SMatthew G. Knepley 
313520f4b53cSBarry Smith   Not Collective
31366ce16762SMatthew G. Knepley 
31376ce16762SMatthew G. Knepley   Input Parameters:
3138dce8aebaSBarry Smith + prob - The `PetscDS` object
31396ce16762SMatthew G. Knepley - f - The field number
31406ce16762SMatthew G. Knepley 
31416ce16762SMatthew G. Knepley   Output Parameter:
31426ce16762SMatthew G. Knepley . off - The offset
31436ce16762SMatthew G. Knepley 
31446ce16762SMatthew G. Knepley   Level: beginner
31456ce16762SMatthew G. Knepley 
3146dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
31476ce16762SMatthew G. Knepley @*/
3148d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
3149d71ae5a4SJacob Faibussowitsch {
31506ce16762SMatthew G. Knepley   PetscFunctionBegin;
31516ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3152dadcf809SJacob Faibussowitsch   PetscValidIntPointer(off, 3);
315363a3b9bcSJacob 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);
31549566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
315547e57110SSander Arens   *off = prob->off[f];
31563ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
31572764a2aaSMatthew G. Knepley }
31582764a2aaSMatthew G. Knepley 
3159194d53e6SMatthew G. Knepley /*@
3160194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
3161194d53e6SMatthew G. Knepley 
316220f4b53cSBarry Smith   Not Collective
3163194d53e6SMatthew G. Knepley 
3164194d53e6SMatthew G. Knepley   Input Parameter:
3165dce8aebaSBarry Smith . prob - The `PetscDS` object
3166194d53e6SMatthew G. Knepley 
3167194d53e6SMatthew G. Knepley   Output Parameter:
3168194d53e6SMatthew G. Knepley . offsets - The offsets
3169194d53e6SMatthew G. Knepley 
3170194d53e6SMatthew G. Knepley   Level: beginner
3171194d53e6SMatthew G. Knepley 
3172dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
3173194d53e6SMatthew G. Knepley @*/
3174d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
3175d71ae5a4SJacob Faibussowitsch {
3176194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3177194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3178194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
31799566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3180194d53e6SMatthew G. Knepley   *offsets = prob->off;
31813ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3182194d53e6SMatthew G. Knepley }
3183194d53e6SMatthew G. Knepley 
3184194d53e6SMatthew G. Knepley /*@
3185194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
3186194d53e6SMatthew G. Knepley 
318720f4b53cSBarry Smith   Not Collective
3188194d53e6SMatthew G. Knepley 
3189194d53e6SMatthew G. Knepley   Input Parameter:
3190dce8aebaSBarry Smith . prob - The `PetscDS` object
3191194d53e6SMatthew G. Knepley 
3192194d53e6SMatthew G. Knepley   Output Parameter:
3193194d53e6SMatthew G. Knepley . offsets - The offsets
3194194d53e6SMatthew G. Knepley 
3195194d53e6SMatthew G. Knepley   Level: beginner
3196194d53e6SMatthew G. Knepley 
3197dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
3198194d53e6SMatthew G. Knepley @*/
3199d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
3200d71ae5a4SJacob Faibussowitsch {
3201194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3202194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3203194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
32049566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3205194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
32063ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3207194d53e6SMatthew G. Knepley }
3208194d53e6SMatthew G. Knepley 
32099ee2af8cSMatthew G. Knepley /*@
32109ee2af8cSMatthew G. Knepley   PetscDSGetComponentOffsetsCohesive - Returns the offset of each field on an evaluation point
32119ee2af8cSMatthew G. Knepley 
321220f4b53cSBarry Smith   Not Collective
32139ee2af8cSMatthew G. Knepley 
32149ee2af8cSMatthew G. Knepley   Input Parameters:
3215dce8aebaSBarry Smith + ds - The `PetscDS` object
32169ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
32179ee2af8cSMatthew G. Knepley 
32189ee2af8cSMatthew G. Knepley   Output Parameter:
32199ee2af8cSMatthew G. Knepley . offsets - The offsets
32209ee2af8cSMatthew G. Knepley 
32219ee2af8cSMatthew G. Knepley   Level: beginner
32229ee2af8cSMatthew G. Knepley 
3223dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
32249ee2af8cSMatthew G. Knepley @*/
3225d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
3226d71ae5a4SJacob Faibussowitsch {
32279ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
32289ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
32299ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
323028b400f6SJacob Faibussowitsch   PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
323163a3b9bcSJacob Faibussowitsch   PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s);
32329566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(ds));
32339ee2af8cSMatthew G. Knepley   *offsets = ds->offCohesive[s];
32343ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
32359ee2af8cSMatthew G. Knepley }
32369ee2af8cSMatthew G. Knepley 
32379ee2af8cSMatthew G. Knepley /*@
32389ee2af8cSMatthew G. Knepley   PetscDSGetComponentDerivativeOffsetsCohesive - Returns the offset of each field derivative on an evaluation point
32399ee2af8cSMatthew G. Knepley 
324020f4b53cSBarry Smith   Not Collective
32419ee2af8cSMatthew G. Knepley 
32429ee2af8cSMatthew G. Knepley   Input Parameters:
3243dce8aebaSBarry Smith + ds - The `PetscDS` object
32449ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
32459ee2af8cSMatthew G. Knepley 
32469ee2af8cSMatthew G. Knepley   Output Parameter:
32479ee2af8cSMatthew G. Knepley . offsets - The offsets
32489ee2af8cSMatthew G. Knepley 
32499ee2af8cSMatthew G. Knepley   Level: beginner
32509ee2af8cSMatthew G. Knepley 
3251dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
32529ee2af8cSMatthew G. Knepley @*/
3253d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentDerivativeOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
3254d71ae5a4SJacob Faibussowitsch {
32559ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
32569ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
32579ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
325828b400f6SJacob Faibussowitsch   PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
325963a3b9bcSJacob Faibussowitsch   PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s);
32609566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(ds));
32619ee2af8cSMatthew G. Knepley   *offsets = ds->offDerCohesive[s];
32623ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
32639ee2af8cSMatthew G. Knepley }
32649ee2af8cSMatthew G. Knepley 
326568c9edb9SMatthew G. Knepley /*@C
326668c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
326768c9edb9SMatthew G. Knepley 
326820f4b53cSBarry Smith   Not Collective
326968c9edb9SMatthew G. Knepley 
327068c9edb9SMatthew G. Knepley   Input Parameter:
3271dce8aebaSBarry Smith . prob - The `PetscDS` object
327268c9edb9SMatthew G. Knepley 
3273ef0bb6c7SMatthew G. Knepley   Output Parameter:
3274ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field
327568c9edb9SMatthew G. Knepley 
327668c9edb9SMatthew G. Knepley   Level: intermediate
327768c9edb9SMatthew G. Knepley 
3278dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscTabulation`, `PetscDSCreate()`
327968c9edb9SMatthew G. Knepley @*/
3280d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[])
3281d71ae5a4SJacob Faibussowitsch {
32822764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32832764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3284ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
32859566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3286ef0bb6c7SMatthew G. Knepley   *T = prob->T;
32873ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
32882764a2aaSMatthew G. Knepley }
32892764a2aaSMatthew G. Knepley 
329068c9edb9SMatthew G. Knepley /*@C
32914d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
329268c9edb9SMatthew G. Knepley 
329320f4b53cSBarry Smith   Not Collective
329468c9edb9SMatthew G. Knepley 
329568c9edb9SMatthew G. Knepley   Input Parameter:
3296dce8aebaSBarry Smith . prob - The `PetscDS` object
329768c9edb9SMatthew G. Knepley 
3298ef0bb6c7SMatthew G. Knepley   Output Parameter:
3299a5b23f4aSJose E. Roman . Tf - The basis function and derivative tabulation on each local face at quadrature points for each and field
330068c9edb9SMatthew G. Knepley 
330168c9edb9SMatthew G. Knepley   Level: intermediate
330268c9edb9SMatthew G. Knepley 
3303dce8aebaSBarry Smith .seealso: `PetscTabulation`, `PetscDS`, `PetscDSGetTabulation()`, `PetscDSCreate()`
330468c9edb9SMatthew G. Knepley @*/
3305d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[])
3306d71ae5a4SJacob Faibussowitsch {
33072764a2aaSMatthew G. Knepley   PetscFunctionBegin;
33082764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3309ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
33109566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3311ef0bb6c7SMatthew G. Knepley   *Tf = prob->Tf;
33123ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
33132764a2aaSMatthew G. Knepley }
33142764a2aaSMatthew G. Knepley 
3315d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
3316d71ae5a4SJacob Faibussowitsch {
33172764a2aaSMatthew G. Knepley   PetscFunctionBegin;
33182764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
33199566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
33209371c9d4SSatish Balay   if (u) {
33219371c9d4SSatish Balay     PetscValidPointer(u, 2);
33229371c9d4SSatish Balay     *u = prob->u;
33239371c9d4SSatish Balay   }
33249371c9d4SSatish Balay   if (u_t) {
33259371c9d4SSatish Balay     PetscValidPointer(u_t, 3);
33269371c9d4SSatish Balay     *u_t = prob->u_t;
33279371c9d4SSatish Balay   }
33289371c9d4SSatish Balay   if (u_x) {
33299371c9d4SSatish Balay     PetscValidPointer(u_x, 4);
33309371c9d4SSatish Balay     *u_x = prob->u_x;
33319371c9d4SSatish Balay   }
33323ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
33332764a2aaSMatthew G. Knepley }
33342764a2aaSMatthew G. Knepley 
3335d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
3336d71ae5a4SJacob Faibussowitsch {
33372764a2aaSMatthew G. Knepley   PetscFunctionBegin;
33382764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
33399566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
33409371c9d4SSatish Balay   if (f0) {
33419371c9d4SSatish Balay     PetscValidPointer(f0, 2);
33429371c9d4SSatish Balay     *f0 = prob->f0;
33439371c9d4SSatish Balay   }
33449371c9d4SSatish Balay   if (f1) {
33459371c9d4SSatish Balay     PetscValidPointer(f1, 3);
33469371c9d4SSatish Balay     *f1 = prob->f1;
33479371c9d4SSatish Balay   }
33489371c9d4SSatish Balay   if (g0) {
33499371c9d4SSatish Balay     PetscValidPointer(g0, 4);
33509371c9d4SSatish Balay     *g0 = prob->g0;
33519371c9d4SSatish Balay   }
33529371c9d4SSatish Balay   if (g1) {
33539371c9d4SSatish Balay     PetscValidPointer(g1, 5);
33549371c9d4SSatish Balay     *g1 = prob->g1;
33559371c9d4SSatish Balay   }
33569371c9d4SSatish Balay   if (g2) {
33579371c9d4SSatish Balay     PetscValidPointer(g2, 6);
33589371c9d4SSatish Balay     *g2 = prob->g2;
33599371c9d4SSatish Balay   }
33609371c9d4SSatish Balay   if (g3) {
33619371c9d4SSatish Balay     PetscValidPointer(g3, 7);
33629371c9d4SSatish Balay     *g3 = prob->g3;
33639371c9d4SSatish Balay   }
33643ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
33652764a2aaSMatthew G. Knepley }
33662764a2aaSMatthew G. Knepley 
3367d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal)
3368d71ae5a4SJacob Faibussowitsch {
33692764a2aaSMatthew G. Knepley   PetscFunctionBegin;
33702764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
33719566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
33729371c9d4SSatish Balay   if (x) {
33739371c9d4SSatish Balay     PetscValidPointer(x, 2);
33749371c9d4SSatish Balay     *x = prob->x;
33759371c9d4SSatish Balay   }
33769371c9d4SSatish Balay   if (basisReal) {
33779371c9d4SSatish Balay     PetscValidPointer(basisReal, 3);
33789371c9d4SSatish Balay     *basisReal = prob->basisReal;
33799371c9d4SSatish Balay   }
33809371c9d4SSatish Balay   if (basisDerReal) {
33819371c9d4SSatish Balay     PetscValidPointer(basisDerReal, 4);
33829371c9d4SSatish Balay     *basisDerReal = prob->basisDerReal;
33839371c9d4SSatish Balay   }
33849371c9d4SSatish Balay   if (testReal) {
33859371c9d4SSatish Balay     PetscValidPointer(testReal, 5);
33869371c9d4SSatish Balay     *testReal = prob->testReal;
33879371c9d4SSatish Balay   }
33889371c9d4SSatish Balay   if (testDerReal) {
33899371c9d4SSatish Balay     PetscValidPointer(testDerReal, 6);
33909371c9d4SSatish Balay     *testDerReal = prob->testDerReal;
33919371c9d4SSatish Balay   }
33923ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
33932764a2aaSMatthew G. Knepley }
33942764a2aaSMatthew G. Knepley 
339558ebd649SToby Isaac /*@C
3396dce8aebaSBarry Smith   PetscDSAddBoundary - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions.
3397dce8aebaSBarry Smith   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
3398dce8aebaSBarry Smith   integrals should be performed, using the kernels from `PetscDSSetBdResidual()`.
339958ebd649SToby Isaac 
340020f4b53cSBarry Smith   Collective
3401783e2ec8SMatthew G. Knepley 
340258ebd649SToby Isaac   Input Parameters:
340358ebd649SToby Isaac + ds       - The PetscDS object
3404dce8aebaSBarry Smith . type     - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann)
340558ebd649SToby Isaac . name     - The BC name
340645480ffeSMatthew G. Knepley . label    - The label defining constrained points
3407dce8aebaSBarry Smith . Nv       - The number of `DMLabel` values for constrained points
340845480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
340958ebd649SToby Isaac . field    - The field to constrain
341045480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
341158ebd649SToby Isaac . comps    - An array of constrained component numbers
341258ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3413a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
341458ebd649SToby Isaac - ctx      - An optional user context for bcFunc
341558ebd649SToby Isaac 
34162fe279fdSBarry Smith   Output Parameter:
341745480ffeSMatthew G. Knepley - bd       - The boundary number
341845480ffeSMatthew G. Knepley 
341958ebd649SToby Isaac   Options Database Keys:
342058ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
342158ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
342258ebd649SToby Isaac 
3423dce8aebaSBarry Smith   Level: developer
3424dce8aebaSBarry Smith 
342556cf3b9cSMatthew G. Knepley   Note:
342620f4b53cSBarry Smith   Both `bcFunc` and `bcFunc_t` will depend on the boundary condition type. If the type if `DM_BC_ESSENTIAL`, Then the calling sequence is:
342756cf3b9cSMatthew G. Knepley 
342820f4b53cSBarry Smith $ void bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
342956cf3b9cSMatthew G. Knepley 
3430dce8aebaSBarry Smith   If the type is `DM_BC_ESSENTIAL_FIELD` or other _FIELD value, then the calling sequence is:
3431dce8aebaSBarry Smith .vb
343220f4b53cSBarry Smith   void bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
3433dce8aebaSBarry Smith               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
3434dce8aebaSBarry Smith               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
3435dce8aebaSBarry Smith               PetscReal time, const PetscReal x[], PetscScalar bcval[])
3436dce8aebaSBarry Smith .ve
343756cf3b9cSMatthew G. Knepley + dim - the spatial dimension
343856cf3b9cSMatthew G. Knepley . Nf - the number of fields
343956cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
344056cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
344156cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point
344256cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
344356cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
344456cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
344556cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
344656cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
344756cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
344856cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
344956cf3b9cSMatthew G. Knepley . t - current time
345056cf3b9cSMatthew G. Knepley . x - coordinates of the current point
345156cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters
345256cf3b9cSMatthew G. Knepley . constants - constant parameters
345356cf3b9cSMatthew G. Knepley - bcval - output values at the current point
345456cf3b9cSMatthew G. Knepley 
3455dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMLabel`, `DMBoundaryConditionType`, `PetscDSAddBoundaryByName()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()`
345658ebd649SToby Isaac @*/
3457d71ae5a4SJacob 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)
3458d71ae5a4SJacob Faibussowitsch {
345945480ffeSMatthew G. Knepley   DSBoundary  head = ds->boundary, b;
346045480ffeSMatthew G. Knepley   PetscInt    n    = 0;
346145480ffeSMatthew G. Knepley   const char *lname;
346258ebd649SToby Isaac 
346358ebd649SToby Isaac   PetscFunctionBegin;
346458ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3465783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
346645480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
346745480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4);
346845480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
346945480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
347045480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
3471dce9da9cSMatthew G. Knepley   PetscCheck(field >= 0 && field < ds->Nf, PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_OUTOFRANGE, "Field %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", field, ds->Nf);
3472d57bb9dbSMatthew G. Knepley   if (Nc > 0) {
3473d57bb9dbSMatthew G. Knepley     PetscInt *fcomps;
3474d57bb9dbSMatthew G. Knepley     PetscInt  c;
3475d57bb9dbSMatthew G. Knepley 
34769566063dSJacob Faibussowitsch     PetscCall(PetscDSGetComponents(ds, &fcomps));
347763a3b9bcSJacob 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);
3478d57bb9dbSMatthew G. Knepley     for (c = 0; c < Nc; ++c) {
34791dca8a05SBarry 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);
3480d57bb9dbSMatthew G. Knepley     }
3481d57bb9dbSMatthew G. Knepley   }
34829566063dSJacob Faibussowitsch   PetscCall(PetscNew(&b));
34839566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(name, (char **)&b->name));
34849566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf));
34859566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf));
34869566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nv, &b->values));
34879566063dSJacob Faibussowitsch   if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv));
34889566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nc, &b->comps));
34899566063dSJacob Faibussowitsch   if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc));
34909566063dSJacob Faibussowitsch   PetscCall(PetscObjectGetName((PetscObject)label, &lname));
34919566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(lname, (char **)&b->lname));
3492f971fd6bSMatthew G. Knepley   b->type   = type;
349345480ffeSMatthew G. Knepley   b->label  = label;
349445480ffeSMatthew G. Knepley   b->Nv     = Nv;
349558ebd649SToby Isaac   b->field  = field;
349645480ffeSMatthew G. Knepley   b->Nc     = Nc;
349758ebd649SToby Isaac   b->func   = bcFunc;
349856cf3b9cSMatthew G. Knepley   b->func_t = bcFunc_t;
349958ebd649SToby Isaac   b->ctx    = ctx;
350045480ffeSMatthew G. Knepley   b->next   = NULL;
350145480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
350245480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
350345480ffeSMatthew G. Knepley   while (head) {
350445480ffeSMatthew G. Knepley     if (!head->next) {
350545480ffeSMatthew G. Knepley       head->next = b;
350645480ffeSMatthew G. Knepley       head       = b;
350745480ffeSMatthew G. Knepley     }
350845480ffeSMatthew G. Knepley     head = head->next;
350945480ffeSMatthew G. Knepley     ++n;
351045480ffeSMatthew G. Knepley   }
35119371c9d4SSatish Balay   if (bd) {
35129371c9d4SSatish Balay     PetscValidIntPointer(bd, 13);
35139371c9d4SSatish Balay     *bd = n;
35149371c9d4SSatish Balay   }
35153ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
351645480ffeSMatthew G. Knepley }
351745480ffeSMatthew G. Knepley 
351845480ffeSMatthew G. Knepley /*@C
3519dce8aebaSBarry Smith   PetscDSAddBoundaryByName - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions.
3520dce8aebaSBarry Smith   In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that
3521dce8aebaSBarry Smith   boundary integrals should be performed, using the kernels from `PetscDSSetBdResidual()`.
352245480ffeSMatthew G. Knepley 
352320f4b53cSBarry Smith   Collective
352445480ffeSMatthew G. Knepley 
352545480ffeSMatthew G. Knepley   Input Parameters:
3526dce8aebaSBarry Smith + ds       - The `PetscDS` object
3527dce8aebaSBarry Smith . type     - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann)
352845480ffeSMatthew G. Knepley . name     - The BC name
352945480ffeSMatthew G. Knepley . lname    - The naem of the label defining constrained points
3530dce8aebaSBarry Smith . Nv       - The number of `DMLabel` values for constrained points
353145480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
353245480ffeSMatthew G. Knepley . field    - The field to constrain
353345480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
353445480ffeSMatthew G. Knepley . comps    - An array of constrained component numbers
353545480ffeSMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3536a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
353745480ffeSMatthew G. Knepley - ctx      - An optional user context for bcFunc
353845480ffeSMatthew G. Knepley 
35392fe279fdSBarry Smith   Output Parameter:
354045480ffeSMatthew G. Knepley - bd       - The boundary number
354145480ffeSMatthew G. Knepley 
354245480ffeSMatthew G. Knepley   Options Database Keys:
354345480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids
354445480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components
354545480ffeSMatthew G. Knepley 
354620f4b53cSBarry Smith   Calling Sequence of `bcFunc` and `bcFunc_t`:
3547dce8aebaSBarry Smith   If the type is `DM_BC_ESSENTIAL`
3548dce8aebaSBarry Smith .vb
354920f4b53cSBarry Smith   void bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
3550dce8aebaSBarry Smith .ve
3551dce8aebaSBarry Smith   If the type is `DM_BC_ESSENTIAL_FIELD` or other _FIELD value,
3552dce8aebaSBarry Smith .vb
355320f4b53cSBarry Smith   void bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
3554dce8aebaSBarry Smith               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
3555dce8aebaSBarry Smith               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
3556dce8aebaSBarry Smith               PetscReal time, const PetscReal x[], PetscScalar bcval[])
3557dce8aebaSBarry Smith .ve
355845480ffeSMatthew G. Knepley + dim - the spatial dimension
355945480ffeSMatthew G. Knepley . Nf - the number of fields
356045480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
356145480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
356245480ffeSMatthew G. Knepley . u - each field evaluated at the current point
356345480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
356445480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
356545480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
356645480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
356745480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
356845480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
356945480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
357045480ffeSMatthew G. Knepley . t - current time
357145480ffeSMatthew G. Knepley . x - coordinates of the current point
357245480ffeSMatthew G. Knepley . numConstants - number of constant parameters
357345480ffeSMatthew G. Knepley . constants - constant parameters
357445480ffeSMatthew G. Knepley - bcval - output values at the current point
357545480ffeSMatthew G. Knepley 
357645480ffeSMatthew G. Knepley   Level: developer
357745480ffeSMatthew G. Knepley 
3578dce8aebaSBarry Smith   Note:
3579dce8aebaSBarry Smith   This function should only be used with `DMFOREST` currently, since labels cannot be defined before the underlying `DMPLEX` is built.
3580dce8aebaSBarry Smith 
3581dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMLabel`, `DMBoundaryConditionType`, `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()`
358245480ffeSMatthew G. Knepley @*/
3583d71ae5a4SJacob 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)
3584d71ae5a4SJacob Faibussowitsch {
358545480ffeSMatthew G. Knepley   DSBoundary head = ds->boundary, b;
358645480ffeSMatthew G. Knepley   PetscInt   n    = 0;
358745480ffeSMatthew G. Knepley 
358845480ffeSMatthew G. Knepley   PetscFunctionBegin;
358945480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
359045480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
359145480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
359245480ffeSMatthew G. Knepley   PetscValidCharPointer(lname, 4);
359345480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
359445480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
359545480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
35969566063dSJacob Faibussowitsch   PetscCall(PetscNew(&b));
35979566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(name, (char **)&b->name));
35989566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf));
35999566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf));
36009566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nv, &b->values));
36019566063dSJacob Faibussowitsch   if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv));
36029566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nc, &b->comps));
36039566063dSJacob Faibussowitsch   if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc));
36049566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(lname, (char **)&b->lname));
360545480ffeSMatthew G. Knepley   b->type   = type;
360645480ffeSMatthew G. Knepley   b->label  = NULL;
360745480ffeSMatthew G. Knepley   b->Nv     = Nv;
360845480ffeSMatthew G. Knepley   b->field  = field;
360945480ffeSMatthew G. Knepley   b->Nc     = Nc;
361045480ffeSMatthew G. Knepley   b->func   = bcFunc;
361145480ffeSMatthew G. Knepley   b->func_t = bcFunc_t;
361245480ffeSMatthew G. Knepley   b->ctx    = ctx;
361345480ffeSMatthew G. Knepley   b->next   = NULL;
361445480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
361545480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
361645480ffeSMatthew G. Knepley   while (head) {
361745480ffeSMatthew G. Knepley     if (!head->next) {
361845480ffeSMatthew G. Knepley       head->next = b;
361945480ffeSMatthew G. Knepley       head       = b;
362045480ffeSMatthew G. Knepley     }
362145480ffeSMatthew G. Knepley     head = head->next;
362245480ffeSMatthew G. Knepley     ++n;
362345480ffeSMatthew G. Knepley   }
36249371c9d4SSatish Balay   if (bd) {
36259371c9d4SSatish Balay     PetscValidIntPointer(bd, 13);
36269371c9d4SSatish Balay     *bd = n;
36279371c9d4SSatish Balay   }
36283ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
362958ebd649SToby Isaac }
363058ebd649SToby Isaac 
3631b67eacb3SMatthew G. Knepley /*@C
3632dce8aebaSBarry Smith   PetscDSUpdateBoundary - Change a boundary condition for the model. The pointwise functions are used to provide boundary values for essential boundary conditions.
3633dce8aebaSBarry Smith   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
3634dce8aebaSBarry Smith   should be performed, using the kernels from `PetscDSSetBdResidual()`.
3635b67eacb3SMatthew G. Knepley 
3636b67eacb3SMatthew G. Knepley   Input Parameters:
3637dce8aebaSBarry Smith + ds       - The `PetscDS` object
3638b67eacb3SMatthew G. Knepley . bd       - The boundary condition number
3639dce8aebaSBarry Smith . type     - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann)
3640b67eacb3SMatthew G. Knepley . name     - The BC name
364145480ffeSMatthew G. Knepley . label    - The label defining constrained points
3642dce8aebaSBarry Smith . Nv       - The number of `DMLabel` ids for constrained points
364345480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
3644b67eacb3SMatthew G. Knepley . field    - The field to constrain
364545480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
3646b67eacb3SMatthew G. Knepley . comps    - An array of constrained component numbers
3647b67eacb3SMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3648a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
3649b67eacb3SMatthew G. Knepley - ctx      - An optional user context for bcFunc
3650b67eacb3SMatthew G. Knepley 
3651b67eacb3SMatthew G. Knepley   Level: developer
3652b67eacb3SMatthew G. Knepley 
3653dce8aebaSBarry Smith   Note:
3654dce8aebaSBarry Smith   The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from `PetscDSGetNumBoundary()`.
3655dce8aebaSBarry Smith   See `PetscDSAddBoundary()` for a description of the calling sequences for the callbacks.
3656dce8aebaSBarry Smith 
3657dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMBoundaryConditionType`, `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSGetNumBoundary()`, `DMLabel`
3658b67eacb3SMatthew G. Knepley @*/
3659d71ae5a4SJacob 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)
3660d71ae5a4SJacob Faibussowitsch {
3661b67eacb3SMatthew G. Knepley   DSBoundary b = ds->boundary;
3662b67eacb3SMatthew G. Knepley   PetscInt   n = 0;
3663b67eacb3SMatthew G. Knepley 
3664b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
3665b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3666b67eacb3SMatthew G. Knepley   while (b) {
3667b67eacb3SMatthew G. Knepley     if (n == bd) break;
3668b67eacb3SMatthew G. Knepley     b = b->next;
3669b67eacb3SMatthew G. Knepley     ++n;
3670b67eacb3SMatthew G. Knepley   }
367163a3b9bcSJacob Faibussowitsch   PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n);
3672b67eacb3SMatthew G. Knepley   if (name) {
36739566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->name));
36749566063dSJacob Faibussowitsch     PetscCall(PetscStrallocpy(name, (char **)&b->name));
3675b67eacb3SMatthew G. Knepley   }
3676b67eacb3SMatthew G. Knepley   b->type = type;
367745480ffeSMatthew G. Knepley   if (label) {
367845480ffeSMatthew G. Knepley     const char *name;
367945480ffeSMatthew G. Knepley 
368045480ffeSMatthew G. Knepley     b->label = label;
36819566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->lname));
36829566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetName((PetscObject)label, &name));
36839566063dSJacob Faibussowitsch     PetscCall(PetscStrallocpy(name, (char **)&b->lname));
368445480ffeSMatthew G. Knepley   }
368545480ffeSMatthew G. Knepley   if (Nv >= 0) {
368645480ffeSMatthew G. Knepley     b->Nv = Nv;
36879566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->values));
36889566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(Nv, &b->values));
36899566063dSJacob Faibussowitsch     if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv));
369045480ffeSMatthew G. Knepley   }
369145480ffeSMatthew G. Knepley   if (field >= 0) b->field = field;
369245480ffeSMatthew G. Knepley   if (Nc >= 0) {
369345480ffeSMatthew G. Knepley     b->Nc = Nc;
36949566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->comps));
36959566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(Nc, &b->comps));
36969566063dSJacob Faibussowitsch     if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc));
369745480ffeSMatthew G. Knepley   }
369845480ffeSMatthew G. Knepley   if (bcFunc) b->func = bcFunc;
369945480ffeSMatthew G. Knepley   if (bcFunc_t) b->func_t = bcFunc_t;
370045480ffeSMatthew G. Knepley   if (ctx) b->ctx = ctx;
37013ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3702b67eacb3SMatthew G. Knepley }
3703b67eacb3SMatthew G. Knepley 
370458ebd649SToby Isaac /*@
370558ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
370658ebd649SToby Isaac 
37072fe279fdSBarry Smith   Input Parameter:
3708dce8aebaSBarry Smith . ds - The `PetscDS` object
370958ebd649SToby Isaac 
37102fe279fdSBarry Smith   Output Parameter:
371158ebd649SToby Isaac . numBd - The number of BC
371258ebd649SToby Isaac 
371358ebd649SToby Isaac   Level: intermediate
371458ebd649SToby Isaac 
3715dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSAddBoundary()`, `PetscDSGetBoundary()`
371658ebd649SToby Isaac @*/
3717d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
3718d71ae5a4SJacob Faibussowitsch {
371958ebd649SToby Isaac   DSBoundary b = ds->boundary;
372058ebd649SToby Isaac 
372158ebd649SToby Isaac   PetscFunctionBegin;
372258ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3723dadcf809SJacob Faibussowitsch   PetscValidIntPointer(numBd, 2);
372458ebd649SToby Isaac   *numBd = 0;
37259371c9d4SSatish Balay   while (b) {
37269371c9d4SSatish Balay     ++(*numBd);
37279371c9d4SSatish Balay     b = b->next;
37289371c9d4SSatish Balay   }
37293ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
373058ebd649SToby Isaac }
373158ebd649SToby Isaac 
373258ebd649SToby Isaac /*@C
37339a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
373458ebd649SToby Isaac 
373558ebd649SToby Isaac   Input Parameters:
3736dce8aebaSBarry Smith + ds          - The `PetscDS` object
373758ebd649SToby Isaac - bd          - The BC number
373858ebd649SToby Isaac 
373958ebd649SToby Isaac   Output Parameters:
3740dce8aebaSBarry Smith + wf       - The `PetscWeakForm` holding the pointwise functions
3741dce8aebaSBarry Smith . type     - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann)
374258ebd649SToby Isaac . name     - The BC name
374345480ffeSMatthew G. Knepley . label    - The label defining constrained points
3744dce8aebaSBarry Smith . Nv       - The number of `DMLabel` ids for constrained points
374545480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
374658ebd649SToby Isaac . field    - The field to constrain
374745480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
374858ebd649SToby Isaac . comps    - An array of constrained component numbers
374958ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3750a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values
375158ebd649SToby Isaac - ctx      - An optional user context for bcFunc
375258ebd649SToby Isaac 
375358ebd649SToby Isaac   Options Database Keys:
375458ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
375558ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
375658ebd649SToby Isaac 
375758ebd649SToby Isaac   Level: developer
375858ebd649SToby Isaac 
3759dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMBoundaryConditionType`, `PetscDSAddBoundary()`, `DMLabel`
376058ebd649SToby Isaac @*/
3761d71ae5a4SJacob 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)
3762d71ae5a4SJacob Faibussowitsch {
376358ebd649SToby Isaac   DSBoundary b = ds->boundary;
376458ebd649SToby Isaac   PetscInt   n = 0;
376558ebd649SToby Isaac 
376658ebd649SToby Isaac   PetscFunctionBegin;
376758ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
376858ebd649SToby Isaac   while (b) {
376958ebd649SToby Isaac     if (n == bd) break;
377058ebd649SToby Isaac     b = b->next;
377158ebd649SToby Isaac     ++n;
377258ebd649SToby Isaac   }
377363a3b9bcSJacob Faibussowitsch   PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n);
377445480ffeSMatthew G. Knepley   if (wf) {
377545480ffeSMatthew G. Knepley     PetscValidPointer(wf, 3);
377645480ffeSMatthew G. Knepley     *wf = b->wf;
377745480ffeSMatthew G. Knepley   }
3778f971fd6bSMatthew G. Knepley   if (type) {
377945480ffeSMatthew G. Knepley     PetscValidPointer(type, 4);
3780f971fd6bSMatthew G. Knepley     *type = b->type;
378158ebd649SToby Isaac   }
378258ebd649SToby Isaac   if (name) {
378345480ffeSMatthew G. Knepley     PetscValidPointer(name, 5);
378458ebd649SToby Isaac     *name = b->name;
378558ebd649SToby Isaac   }
378645480ffeSMatthew G. Knepley   if (label) {
378745480ffeSMatthew G. Knepley     PetscValidPointer(label, 6);
378845480ffeSMatthew G. Knepley     *label = b->label;
378945480ffeSMatthew G. Knepley   }
379045480ffeSMatthew G. Knepley   if (Nv) {
379145480ffeSMatthew G. Knepley     PetscValidIntPointer(Nv, 7);
379245480ffeSMatthew G. Knepley     *Nv = b->Nv;
379345480ffeSMatthew G. Knepley   }
379445480ffeSMatthew G. Knepley   if (values) {
379545480ffeSMatthew G. Knepley     PetscValidPointer(values, 8);
379645480ffeSMatthew G. Knepley     *values = b->values;
379758ebd649SToby Isaac   }
379858ebd649SToby Isaac   if (field) {
379945480ffeSMatthew G. Knepley     PetscValidIntPointer(field, 9);
380058ebd649SToby Isaac     *field = b->field;
380158ebd649SToby Isaac   }
380245480ffeSMatthew G. Knepley   if (Nc) {
380345480ffeSMatthew G. Knepley     PetscValidIntPointer(Nc, 10);
380445480ffeSMatthew G. Knepley     *Nc = b->Nc;
380558ebd649SToby Isaac   }
380658ebd649SToby Isaac   if (comps) {
380745480ffeSMatthew G. Knepley     PetscValidPointer(comps, 11);
380858ebd649SToby Isaac     *comps = b->comps;
380958ebd649SToby Isaac   }
381058ebd649SToby Isaac   if (func) {
381145480ffeSMatthew G. Knepley     PetscValidPointer(func, 12);
381258ebd649SToby Isaac     *func = b->func;
381358ebd649SToby Isaac   }
381456cf3b9cSMatthew G. Knepley   if (func_t) {
381545480ffeSMatthew G. Knepley     PetscValidPointer(func_t, 13);
381656cf3b9cSMatthew G. Knepley     *func_t = b->func_t;
381756cf3b9cSMatthew G. Knepley   }
381858ebd649SToby Isaac   if (ctx) {
381945480ffeSMatthew G. Knepley     PetscValidPointer(ctx, 14);
382058ebd649SToby Isaac     *ctx = b->ctx;
382158ebd649SToby Isaac   }
38223ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
382358ebd649SToby Isaac }
382458ebd649SToby Isaac 
3825d71ae5a4SJacob Faibussowitsch static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew)
3826d71ae5a4SJacob Faibussowitsch {
382745480ffeSMatthew G. Knepley   PetscFunctionBegin;
38289566063dSJacob Faibussowitsch   PetscCall(PetscNew(bNew));
38299566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf));
38309566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCopy(b->wf, (*bNew)->wf));
38319566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(b->name, (char **)&((*bNew)->name)));
38329566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(b->lname, (char **)&((*bNew)->lname)));
383345480ffeSMatthew G. Knepley   (*bNew)->type  = b->type;
383445480ffeSMatthew G. Knepley   (*bNew)->label = b->label;
383545480ffeSMatthew G. Knepley   (*bNew)->Nv    = b->Nv;
38369566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(b->Nv, &(*bNew)->values));
38379566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy((*bNew)->values, b->values, b->Nv));
383845480ffeSMatthew G. Knepley   (*bNew)->field = b->field;
383945480ffeSMatthew G. Knepley   (*bNew)->Nc    = b->Nc;
38409566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(b->Nc, &(*bNew)->comps));
38419566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy((*bNew)->comps, b->comps, b->Nc));
384245480ffeSMatthew G. Knepley   (*bNew)->func   = b->func;
384345480ffeSMatthew G. Knepley   (*bNew)->func_t = b->func_t;
384445480ffeSMatthew G. Knepley   (*bNew)->ctx    = b->ctx;
38453ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
384645480ffeSMatthew G. Knepley }
384745480ffeSMatthew G. Knepley 
38489252d075SMatthew G. Knepley /*@
38499252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
38509252d075SMatthew G. Knepley 
385120f4b53cSBarry Smith   Not Collective
38529252d075SMatthew G. Knepley 
385336951cb5SMatthew G. Knepley   Input Parameters:
3854dce8aebaSBarry Smith + ds        - The source `PetscDS` object
3855dce8aebaSBarry Smith . numFields - The number of selected fields, or `PETSC_DEFAULT` for all fields
385636951cb5SMatthew G. Knepley - fields    - The selected fields, or NULL for all fields
38579252d075SMatthew G. Knepley 
38589252d075SMatthew G. Knepley   Output Parameter:
3859dce8aebaSBarry Smith . newds     - The target `PetscDS`, now with a copy of the boundary conditions
38609252d075SMatthew G. Knepley 
38619252d075SMatthew G. Knepley   Level: intermediate
38629252d075SMatthew G. Knepley 
3863dce8aebaSBarry Smith .seealso: `PetscDS`, `DMBoundary`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
38649252d075SMatthew G. Knepley @*/
3865d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds)
3866d71ae5a4SJacob Faibussowitsch {
386745480ffeSMatthew G. Knepley   DSBoundary b, *lastnext;
3868dff059c6SToby Isaac 
3869dff059c6SToby Isaac   PetscFunctionBegin;
387036951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
387136951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4);
38723ba16761SJacob Faibussowitsch   if (ds == newds) PetscFunctionReturn(PETSC_SUCCESS);
38739566063dSJacob Faibussowitsch   PetscCall(PetscDSDestroyBoundary(newds));
387436951cb5SMatthew G. Knepley   lastnext = &(newds->boundary);
387536951cb5SMatthew G. Knepley   for (b = ds->boundary; b; b = b->next) {
3876dff059c6SToby Isaac     DSBoundary bNew;
387736951cb5SMatthew G. Knepley     PetscInt   fieldNew = -1;
3878dff059c6SToby Isaac 
387936951cb5SMatthew G. Knepley     if (numFields > 0 && fields) {
388036951cb5SMatthew G. Knepley       PetscInt f;
388136951cb5SMatthew G. Knepley 
38829371c9d4SSatish Balay       for (f = 0; f < numFields; ++f)
38839371c9d4SSatish Balay         if (b->field == fields[f]) break;
388436951cb5SMatthew G. Knepley       if (f == numFields) continue;
388536951cb5SMatthew G. Knepley       fieldNew = f;
388636951cb5SMatthew G. Knepley     }
38879566063dSJacob Faibussowitsch     PetscCall(DSBoundaryDuplicate_Internal(b, &bNew));
388836951cb5SMatthew G. Knepley     bNew->field = fieldNew < 0 ? b->field : fieldNew;
3889dff059c6SToby Isaac     *lastnext   = bNew;
3890dff059c6SToby Isaac     lastnext    = &(bNew->next);
3891dff059c6SToby Isaac   }
38923ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3893dff059c6SToby Isaac }
3894dff059c6SToby Isaac 
38956c1eb96dSMatthew G. Knepley /*@
3896dce8aebaSBarry Smith   PetscDSDestroyBoundary - Remove all `DMBoundary` objects from the `PetscDS`
389745480ffeSMatthew G. Knepley 
389820f4b53cSBarry Smith   Not Collective
389945480ffeSMatthew G. Knepley 
390045480ffeSMatthew G. Knepley   Input Parameter:
3901dce8aebaSBarry Smith . ds - The `PetscDS` object
390245480ffeSMatthew G. Knepley 
390345480ffeSMatthew G. Knepley   Level: intermediate
390445480ffeSMatthew G. Knepley 
3905dce8aebaSBarry Smith .seealso: `PetscDS`, `DMBoundary`, `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`
390645480ffeSMatthew G. Knepley @*/
3907d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSDestroyBoundary(PetscDS ds)
3908d71ae5a4SJacob Faibussowitsch {
390945480ffeSMatthew G. Knepley   DSBoundary next = ds->boundary;
391045480ffeSMatthew G. Knepley 
391145480ffeSMatthew G. Knepley   PetscFunctionBegin;
391245480ffeSMatthew G. Knepley   while (next) {
391345480ffeSMatthew G. Knepley     DSBoundary b = next;
391445480ffeSMatthew G. Knepley 
391545480ffeSMatthew G. Knepley     next = b->next;
39169566063dSJacob Faibussowitsch     PetscCall(PetscWeakFormDestroy(&b->wf));
39179566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->name));
39189566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->lname));
39199566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->values));
39209566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->comps));
39219566063dSJacob Faibussowitsch     PetscCall(PetscFree(b));
392245480ffeSMatthew G. Knepley   }
39233ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
392445480ffeSMatthew G. Knepley }
392545480ffeSMatthew G. Knepley 
392645480ffeSMatthew G. Knepley /*@
39276c1eb96dSMatthew G. Knepley   PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout
39286c1eb96dSMatthew G. Knepley 
392920f4b53cSBarry Smith   Not Collective
39306c1eb96dSMatthew G. Knepley 
3931d8d19677SJose E. Roman   Input Parameters:
3932dce8aebaSBarry Smith + prob - The `PetscDS` object
39336c1eb96dSMatthew G. Knepley . numFields - Number of new fields
39346c1eb96dSMatthew G. Knepley - fields - Old field number for each new field
39356c1eb96dSMatthew G. Knepley 
39366c1eb96dSMatthew G. Knepley   Output Parameter:
3937dce8aebaSBarry Smith . newprob - The `PetscDS` copy
39386c1eb96dSMatthew G. Knepley 
39396c1eb96dSMatthew G. Knepley   Level: intermediate
39406c1eb96dSMatthew G. Knepley 
3941dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSelectEquations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
39426c1eb96dSMatthew G. Knepley @*/
3943d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
3944d71ae5a4SJacob Faibussowitsch {
39456c1eb96dSMatthew G. Knepley   PetscInt Nf, Nfn, fn;
39466c1eb96dSMatthew G. Knepley 
39476c1eb96dSMatthew G. Knepley   PetscFunctionBegin;
39486c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3949dadcf809SJacob Faibussowitsch   if (fields) PetscValidIntPointer(fields, 3);
39506c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
39519566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
39529566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(newprob, &Nfn));
395345480ffeSMatthew G. Knepley   numFields = numFields < 0 ? Nf : numFields;
39546c1eb96dSMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
39556c1eb96dSMatthew G. Knepley     const PetscInt f = fields ? fields[fn] : fn;
39566c1eb96dSMatthew G. Knepley     PetscObject    disc;
39576c1eb96dSMatthew G. Knepley 
39586c1eb96dSMatthew G. Knepley     if (f >= Nf) continue;
39599566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(prob, f, &disc));
39609566063dSJacob Faibussowitsch     PetscCall(PetscDSSetDiscretization(newprob, fn, disc));
39616c1eb96dSMatthew G. Knepley   }
39623ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
39636c1eb96dSMatthew G. Knepley }
39646c1eb96dSMatthew G. Knepley 
39656c1eb96dSMatthew G. Knepley /*@
39669252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
39679252d075SMatthew G. Knepley 
396820f4b53cSBarry Smith   Not Collective
39699252d075SMatthew G. Knepley 
3970d8d19677SJose E. Roman   Input Parameters:
3971dce8aebaSBarry Smith + prob - The `PetscDS` object
39729252d075SMatthew G. Knepley . numFields - Number of new fields
39739252d075SMatthew G. Knepley - fields - Old field number for each new field
39749252d075SMatthew G. Knepley 
39759252d075SMatthew G. Knepley   Output Parameter:
3976dce8aebaSBarry Smith . newprob - The `PetscDS` copy
39779252d075SMatthew G. Knepley 
39789252d075SMatthew G. Knepley   Level: intermediate
39799252d075SMatthew G. Knepley 
3980dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSelectDiscretizations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
39819252d075SMatthew G. Knepley @*/
3982d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
3983d71ae5a4SJacob Faibussowitsch {
39849252d075SMatthew G. Knepley   PetscInt Nf, Nfn, fn, gn;
39859252d075SMatthew G. Knepley 
39869252d075SMatthew G. Knepley   PetscFunctionBegin;
39879252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3988dadcf809SJacob Faibussowitsch   if (fields) PetscValidIntPointer(fields, 3);
39899252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
39909566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
39919566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(newprob, &Nfn));
399263a3b9bcSJacob 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);
39939252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
39949252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
39959252d075SMatthew G. Knepley     PetscPointFunc   obj;
39969252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
39979252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
39989252d075SMatthew G. Knepley     PetscRiemannFunc r;
39999252d075SMatthew G. Knepley 
4000c52f1e13SMatthew G. Knepley     if (f >= Nf) continue;
40019566063dSJacob Faibussowitsch     PetscCall(PetscDSGetObjective(prob, f, &obj));
40029566063dSJacob Faibussowitsch     PetscCall(PetscDSGetResidual(prob, f, &f0, &f1));
40039566063dSJacob Faibussowitsch     PetscCall(PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd));
40049566063dSJacob Faibussowitsch     PetscCall(PetscDSGetRiemannSolver(prob, f, &r));
40059566063dSJacob Faibussowitsch     PetscCall(PetscDSSetObjective(newprob, fn, obj));
40069566063dSJacob Faibussowitsch     PetscCall(PetscDSSetResidual(newprob, fn, f0, f1));
40079566063dSJacob Faibussowitsch     PetscCall(PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd));
40089566063dSJacob Faibussowitsch     PetscCall(PetscDSSetRiemannSolver(newprob, fn, r));
40099252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
40109252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
40119252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
40129252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
40139252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
40149252d075SMatthew G. Knepley 
4015c52f1e13SMatthew G. Knepley       if (g >= Nf) continue;
40169566063dSJacob Faibussowitsch       PetscCall(PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3));
40179566063dSJacob Faibussowitsch       PetscCall(PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p));
40189566063dSJacob Faibussowitsch       PetscCall(PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd));
40199566063dSJacob Faibussowitsch       PetscCall(PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3));
40209566063dSJacob Faibussowitsch       PetscCall(PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p));
40219566063dSJacob Faibussowitsch       PetscCall(PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd));
40229252d075SMatthew G. Knepley     }
40239252d075SMatthew G. Knepley   }
40243ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
40259252d075SMatthew G. Knepley }
40269252d075SMatthew G. Knepley 
4027da51fcedSMatthew G. Knepley /*@
4028dce8aebaSBarry Smith   PetscDSCopyEquations - Copy all pointwise function pointers to another `PetscDS`
4029da51fcedSMatthew G. Knepley 
403020f4b53cSBarry Smith   Not Collective
4031da51fcedSMatthew G. Knepley 
4032da51fcedSMatthew G. Knepley   Input Parameter:
4033dce8aebaSBarry Smith . prob - The `PetscDS` object
4034da51fcedSMatthew G. Knepley 
4035da51fcedSMatthew G. Knepley   Output Parameter:
4036dce8aebaSBarry Smith . newprob - The `PetscDS` copy
4037da51fcedSMatthew G. Knepley 
4038da51fcedSMatthew G. Knepley   Level: intermediate
4039da51fcedSMatthew G. Knepley 
4040dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
4041da51fcedSMatthew G. Knepley @*/
4042d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
4043d71ae5a4SJacob Faibussowitsch {
4044b8025e53SMatthew G. Knepley   PetscWeakForm wf, newwf;
40459252d075SMatthew G. Knepley   PetscInt      Nf, Ng;
4046da51fcedSMatthew G. Knepley 
4047da51fcedSMatthew G. Knepley   PetscFunctionBegin;
4048da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
4049da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
40509566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
40519566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(newprob, &Ng));
405263a3b9bcSJacob Faibussowitsch   PetscCheck(Nf == Ng, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %" PetscInt_FMT " != %" PetscInt_FMT, Nf, Ng);
40539566063dSJacob Faibussowitsch   PetscCall(PetscDSGetWeakForm(prob, &wf));
40549566063dSJacob Faibussowitsch   PetscCall(PetscDSGetWeakForm(newprob, &newwf));
40559566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCopy(wf, newwf));
40563ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
40579252d075SMatthew G. Knepley }
405845480ffeSMatthew G. Knepley 
40599252d075SMatthew G. Knepley /*@
4060dce8aebaSBarry Smith   PetscDSCopyConstants - Copy all constants to another `PetscDS`
4061da51fcedSMatthew G. Knepley 
406220f4b53cSBarry Smith   Not Collective
40639252d075SMatthew G. Knepley 
40649252d075SMatthew G. Knepley   Input Parameter:
4065dce8aebaSBarry Smith . prob - The `PetscDS` object
40669252d075SMatthew G. Knepley 
40679252d075SMatthew G. Knepley   Output Parameter:
4068dce8aebaSBarry Smith . newprob - The `PetscDS` copy
40699252d075SMatthew G. Knepley 
40709252d075SMatthew G. Knepley   Level: intermediate
40719252d075SMatthew G. Knepley 
4072dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
40739252d075SMatthew G. Knepley @*/
4074d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
4075d71ae5a4SJacob Faibussowitsch {
40769252d075SMatthew G. Knepley   PetscInt           Nc;
40779252d075SMatthew G. Knepley   const PetscScalar *constants;
40789252d075SMatthew G. Knepley 
40799252d075SMatthew G. Knepley   PetscFunctionBegin;
40809252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
40819252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
40829566063dSJacob Faibussowitsch   PetscCall(PetscDSGetConstants(prob, &Nc, &constants));
40839566063dSJacob Faibussowitsch   PetscCall(PetscDSSetConstants(newprob, Nc, (PetscScalar *)constants));
40843ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
4085da51fcedSMatthew G. Knepley }
4086da51fcedSMatthew G. Knepley 
408745480ffeSMatthew G. Knepley /*@
4088dce8aebaSBarry Smith   PetscDSCopyExactSolutions - Copy all exact solutions to another `PetscDS`
408945480ffeSMatthew G. Knepley 
409020f4b53cSBarry Smith   Not Collective
409145480ffeSMatthew G. Knepley 
409245480ffeSMatthew G. Knepley   Input Parameter:
4093dce8aebaSBarry Smith . ds - The `PetscDS` object
409445480ffeSMatthew G. Knepley 
409545480ffeSMatthew G. Knepley   Output Parameter:
4096dce8aebaSBarry Smith . newds - The `PetscDS` copy
409745480ffeSMatthew G. Knepley 
409845480ffeSMatthew G. Knepley   Level: intermediate
409945480ffeSMatthew G. Knepley 
4100dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
410145480ffeSMatthew G. Knepley @*/
4102d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds)
4103d71ae5a4SJacob Faibussowitsch {
410445480ffeSMatthew G. Knepley   PetscSimplePointFunc sol;
410545480ffeSMatthew G. Knepley   void                *ctx;
410645480ffeSMatthew G. Knepley   PetscInt             Nf, f;
410745480ffeSMatthew G. Knepley 
410845480ffeSMatthew G. Knepley   PetscFunctionBegin;
410945480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
411045480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2);
41119566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(ds, &Nf));
411245480ffeSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
41139566063dSJacob Faibussowitsch     PetscCall(PetscDSGetExactSolution(ds, f, &sol, &ctx));
41149566063dSJacob Faibussowitsch     PetscCall(PetscDSSetExactSolution(newds, f, sol, ctx));
41159566063dSJacob Faibussowitsch     PetscCall(PetscDSGetExactSolutionTimeDerivative(ds, f, &sol, &ctx));
41169566063dSJacob Faibussowitsch     PetscCall(PetscDSSetExactSolutionTimeDerivative(newds, f, sol, ctx));
411745480ffeSMatthew G. Knepley   }
41183ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
411945480ffeSMatthew G. Knepley }
412045480ffeSMatthew G. Knepley 
412107218a29SMatthew G. Knepley PetscErrorCode PetscDSCopy(PetscDS ds, DM dmNew, PetscDS dsNew)
412207218a29SMatthew G. Knepley {
412307218a29SMatthew G. Knepley   DSBoundary b;
412407218a29SMatthew G. Knepley   PetscInt   cdim, Nf, f, d;
412507218a29SMatthew G. Knepley   PetscBool  isCohesive;
412607218a29SMatthew G. Knepley   void      *ctx;
412707218a29SMatthew G. Knepley 
412807218a29SMatthew G. Knepley   PetscFunctionBegin;
412907218a29SMatthew G. Knepley   PetscCall(PetscDSCopyConstants(ds, dsNew));
413007218a29SMatthew G. Knepley   PetscCall(PetscDSCopyExactSolutions(ds, dsNew));
413107218a29SMatthew G. Knepley   PetscCall(PetscDSSelectDiscretizations(ds, PETSC_DETERMINE, NULL, dsNew));
413207218a29SMatthew G. Knepley   PetscCall(PetscDSCopyEquations(ds, dsNew));
413307218a29SMatthew G. Knepley   PetscCall(PetscDSGetNumFields(ds, &Nf));
413407218a29SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
413507218a29SMatthew G. Knepley     PetscCall(PetscDSGetContext(ds, f, &ctx));
413607218a29SMatthew G. Knepley     PetscCall(PetscDSSetContext(dsNew, f, ctx));
413707218a29SMatthew G. Knepley     PetscCall(PetscDSGetCohesive(ds, f, &isCohesive));
413807218a29SMatthew G. Knepley     PetscCall(PetscDSSetCohesive(dsNew, f, isCohesive));
413907218a29SMatthew G. Knepley     PetscCall(PetscDSGetJetDegree(ds, f, &d));
414007218a29SMatthew G. Knepley     PetscCall(PetscDSSetJetDegree(dsNew, f, d));
414107218a29SMatthew G. Knepley   }
414207218a29SMatthew G. Knepley   if (Nf) {
414307218a29SMatthew G. Knepley     PetscCall(PetscDSGetCoordinateDimension(ds, &cdim));
414407218a29SMatthew G. Knepley     PetscCall(PetscDSSetCoordinateDimension(dsNew, cdim));
414507218a29SMatthew G. Knepley   }
414607218a29SMatthew G. Knepley   PetscCall(PetscDSCopyBoundary(ds, PETSC_DETERMINE, NULL, dsNew));
414707218a29SMatthew G. Knepley   for (b = dsNew->boundary; b; b = b->next) {
414807218a29SMatthew G. Knepley     PetscCall(DMGetLabel(dmNew, b->lname, &b->label));
414907218a29SMatthew G. Knepley     /* Do not check if label exists here, since p4est calls this for the reference tree which does not have the labels */
415007218a29SMatthew G. Knepley     //PetscCheck(b->label,PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Label %s missing in new DM", name);
415107218a29SMatthew G. Knepley   }
415207218a29SMatthew G. Knepley   PetscFunctionReturn(PETSC_SUCCESS);
415307218a29SMatthew G. Knepley }
415407218a29SMatthew G. Knepley 
4155d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
4156d71ae5a4SJacob Faibussowitsch {
4157df3a45bdSMatthew G. Knepley   PetscInt dim, Nf, f;
4158b1353e8eSMatthew G. Knepley 
4159b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
4160b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
4161b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
41629371c9d4SSatish Balay   if (height == 0) {
41639371c9d4SSatish Balay     *subprob = prob;
41643ba16761SJacob Faibussowitsch     PetscFunctionReturn(PETSC_SUCCESS);
41659371c9d4SSatish Balay   }
41669566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
41679566063dSJacob Faibussowitsch   PetscCall(PetscDSGetSpatialDimension(prob, &dim));
416863a3b9bcSJacob 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);
41699566063dSJacob Faibussowitsch   if (!prob->subprobs) PetscCall(PetscCalloc1(dim, &prob->subprobs));
4170df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height - 1]) {
4171b1353e8eSMatthew G. Knepley     PetscInt cdim;
4172b1353e8eSMatthew G. Knepley 
41739566063dSJacob Faibussowitsch     PetscCall(PetscDSCreate(PetscObjectComm((PetscObject)prob), &prob->subprobs[height - 1]));
41749566063dSJacob Faibussowitsch     PetscCall(PetscDSGetCoordinateDimension(prob, &cdim));
41759566063dSJacob Faibussowitsch     PetscCall(PetscDSSetCoordinateDimension(prob->subprobs[height - 1], cdim));
4176b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
4177b1353e8eSMatthew G. Knepley       PetscFE      subfe;
4178b1353e8eSMatthew G. Knepley       PetscObject  obj;
4179b1353e8eSMatthew G. Knepley       PetscClassId id;
4180b1353e8eSMatthew G. Knepley 
41819566063dSJacob Faibussowitsch       PetscCall(PetscDSGetDiscretization(prob, f, &obj));
41829566063dSJacob Faibussowitsch       PetscCall(PetscObjectGetClassId(obj, &id));
41839566063dSJacob Faibussowitsch       if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetHeightSubspace((PetscFE)obj, height, &subfe));
418463a3b9bcSJacob Faibussowitsch       else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %" PetscInt_FMT, f);
41859566063dSJacob Faibussowitsch       PetscCall(PetscDSSetDiscretization(prob->subprobs[height - 1], f, (PetscObject)subfe));
4186b1353e8eSMatthew G. Knepley     }
4187b1353e8eSMatthew G. Knepley   }
4188df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height - 1];
41893ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
4190b1353e8eSMatthew G. Knepley }
4191b1353e8eSMatthew G. Knepley 
41924366bac7SMatthew G. Knepley PetscErrorCode PetscDSPermuteQuadPoint(PetscDS ds, PetscInt ornt, PetscInt field, PetscInt q, PetscInt *qperm)
41934366bac7SMatthew G. Knepley {
41944366bac7SMatthew G. Knepley   IS              permIS;
41954366bac7SMatthew G. Knepley   PetscQuadrature quad;
41964366bac7SMatthew G. Knepley   DMPolytopeType  ct;
41974366bac7SMatthew G. Knepley   const PetscInt *perm;
41984366bac7SMatthew G. Knepley   PetscInt        Na, Nq;
41994366bac7SMatthew G. Knepley 
42004366bac7SMatthew G. Knepley   PetscFunctionBeginHot;
42014366bac7SMatthew G. Knepley   PetscCall(PetscFEGetQuadrature((PetscFE)ds->disc[field], &quad));
42024366bac7SMatthew G. Knepley   PetscCall(PetscQuadratureGetData(quad, NULL, NULL, &Nq, NULL, NULL));
42034366bac7SMatthew G. Knepley   PetscCall(PetscQuadratureGetCellType(quad, &ct));
42044366bac7SMatthew G. Knepley   PetscCheck(q >= 0 && q < Nq, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Quadrature point %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", q, Nq);
42054366bac7SMatthew G. Knepley   Na = DMPolytopeTypeGetNumArrangments(ct) / 2;
42064366bac7SMatthew G. Knepley   PetscCheck(ornt >= -Na && ornt < Na, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Orientation %" PetscInt_FMT " of %s is not in [%" PetscInt_FMT ", %" PetscInt_FMT ")", ornt, DMPolytopeTypes[ct], -Na, Na);
42074366bac7SMatthew G. Knepley   if (!ds->quadPerm[(PetscInt)ct]) PetscCall(PetscQuadratureComputePermutations(quad, NULL, &ds->quadPerm[(PetscInt)ct]));
42084366bac7SMatthew G. Knepley   permIS = ds->quadPerm[(PetscInt)ct][ornt + Na];
42094366bac7SMatthew G. Knepley   PetscCall(ISGetIndices(permIS, &perm));
42104366bac7SMatthew G. Knepley   *qperm = perm[q];
42114366bac7SMatthew G. Knepley   PetscCall(ISRestoreIndices(permIS, &perm));
42124366bac7SMatthew G. Knepley   PetscFunctionReturn(PETSC_SUCCESS);
42134366bac7SMatthew G. Knepley }
42144366bac7SMatthew G. Knepley 
4215d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype)
4216d71ae5a4SJacob Faibussowitsch {
4217c7bd5f0bSMatthew G. Knepley   PetscObject  obj;
4218c7bd5f0bSMatthew G. Knepley   PetscClassId id;
4219c7bd5f0bSMatthew G. Knepley   PetscInt     Nf;
4220c7bd5f0bSMatthew G. Knepley 
4221c7bd5f0bSMatthew G. Knepley   PetscFunctionBegin;
4222c7bd5f0bSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
4223665f567fSMatthew G. Knepley   PetscValidPointer(disctype, 3);
4224665f567fSMatthew G. Knepley   *disctype = PETSC_DISC_NONE;
42259566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(ds, &Nf));
422663a3b9bcSJacob Faibussowitsch   PetscCheck(f < Nf, PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_SIZ, "Field %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, Nf);
42279566063dSJacob Faibussowitsch   PetscCall(PetscDSGetDiscretization(ds, f, &obj));
4228665f567fSMatthew G. Knepley   if (obj) {
42299566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetClassId(obj, &id));
4230665f567fSMatthew G. Knepley     if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE;
4231665f567fSMatthew G. Knepley     else *disctype = PETSC_DISC_FV;
4232665f567fSMatthew G. Knepley   }
42333ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
4234c7bd5f0bSMatthew G. Knepley }
4235c7bd5f0bSMatthew G. Knepley 
4236d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds)
4237d71ae5a4SJacob Faibussowitsch {
42382764a2aaSMatthew G. Knepley   PetscFunctionBegin;
42399566063dSJacob Faibussowitsch   PetscCall(PetscFree(ds->data));
42403ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
42412764a2aaSMatthew G. Knepley }
42422764a2aaSMatthew G. Knepley 
4243d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds)
4244d71ae5a4SJacob Faibussowitsch {
42452764a2aaSMatthew G. Knepley   PetscFunctionBegin;
42466528b96dSMatthew G. Knepley   ds->ops->setfromoptions = NULL;
42476528b96dSMatthew G. Knepley   ds->ops->setup          = NULL;
42486528b96dSMatthew G. Knepley   ds->ops->view           = NULL;
42496528b96dSMatthew G. Knepley   ds->ops->destroy        = PetscDSDestroy_Basic;
42503ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
42512764a2aaSMatthew G. Knepley }
42522764a2aaSMatthew G. Knepley 
42532764a2aaSMatthew G. Knepley /*MC
42542764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
42552764a2aaSMatthew G. Knepley 
42562764a2aaSMatthew G. Knepley   Level: intermediate
42572764a2aaSMatthew G. Knepley 
4258db781477SPatrick Sanan .seealso: `PetscDSType`, `PetscDSCreate()`, `PetscDSSetType()`
42592764a2aaSMatthew G. Knepley M*/
42602764a2aaSMatthew G. Knepley 
4261d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds)
4262d71ae5a4SJacob Faibussowitsch {
42632764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
42642764a2aaSMatthew G. Knepley 
42652764a2aaSMatthew G. Knepley   PetscFunctionBegin;
42666528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
42674dfa11a4SJacob Faibussowitsch   PetscCall(PetscNew(&b));
42686528b96dSMatthew G. Knepley   ds->data = b;
42692764a2aaSMatthew G. Knepley 
42709566063dSJacob Faibussowitsch   PetscCall(PetscDSInitialize_Basic(ds));
42713ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
42722764a2aaSMatthew G. Knepley }
4273