xref: /petsc/src/dm/dt/interface/dtds.c (revision 07218a29b4d399ea5732e51342b017bba1a66494)
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;
377*07218a29SMatthew 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) {
392*07218a29SMatthew G. Knepley     // Note: This assumes we have one kind of cell at each dimension.
393*07218a29SMatthew G. Knepley     //       We can fix this by having quadrature hold the celltype
394*07218a29SMatthew 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;
400*07218a29SMatthew 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       }
415*07218a29SMatthew G. Knepley       if (q) {
416*07218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetData(q, &dim, NULL, NULL, NULL, NULL));
417*07218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetOrder(q, &order));
418*07218a29SMatthew G. Knepley         if (order > maxOrder[dim]) {
419*07218a29SMatthew G. Knepley           maxOrder[dim] = order;
420*07218a29SMatthew G. Knepley           maxQuad[dim]  = q;
42112fc5b22SMatthew G. Knepley         }
422*07218a29SMatthew G. Knepley       }
423*07218a29SMatthew G. Knepley       if (fq) {
424*07218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetData(fq, &dim, NULL, NULL, NULL, NULL));
425*07218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetOrder(fq, &forder));
426*07218a29SMatthew G. Knepley         if (forder > maxOrder[dim]) {
427*07218a29SMatthew G. Knepley           maxOrder[dim] = forder;
428*07218a29SMatthew G. Knepley           maxQuad[dim]  = fq;
429*07218a29SMatthew 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;
435*07218a29SMatthew G. Knepley       PetscQuadrature q;
436*07218a29SMatthew 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 
444*07218a29SMatthew G. Knepley         PetscCall(PetscFEGetQuadrature(fe, &q));
445*07218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetData(q, &dim, NULL, NULL, NULL, NULL));
446*07218a29SMatthew G. Knepley         PetscCall(PetscFESetQuadrature(fe, maxQuad[dim]));
447*07218a29SMatthew 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 
451*07218a29SMatthew G. Knepley         PetscCall(PetscFVGetQuadrature(fv, &q));
452*07218a29SMatthew G. Knepley         PetscCall(PetscQuadratureGetData(q, &dim, NULL, NULL, NULL, NULL));
453*07218a29SMatthew 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;
477*07218a29SMatthew G. Knepley           PetscInt        dim, order;
47849ae0b56SMatthew G. Knepley 
479*07218a29SMatthew G. Knepley           PetscCall(PetscQuadratureGetData(q, &dim, NULL, NULL, NULL, NULL));
48049ae0b56SMatthew G. Knepley           PetscCall(PetscQuadratureGetOrder(q, &order));
481*07218a29SMatthew G. Knepley           if (maxOrder[dim] < 0) maxOrder[dim] = order;
482*07218a29SMatthew 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) {
485*07218a29SMatthew G. Knepley             PetscCall(PetscQuadratureGetData(fq, &dim, NULL, NULL, NULL, NULL));
486*07218a29SMatthew G. Knepley             PetscCall(PetscQuadratureGetOrder(fq, &order));
487*07218a29SMatthew G. Knepley             if (maxOrder[dim] < 0) maxOrder[dim] = order;
488*07218a29SMatthew 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));
6519566063dSJacob Faibussowitsch   PetscCall(PetscHeaderDestroy(ds));
6523ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
6532764a2aaSMatthew G. Knepley }
6542764a2aaSMatthew G. Knepley 
6552764a2aaSMatthew G. Knepley /*@
656dce8aebaSBarry Smith   PetscDSCreate - Creates an empty `PetscDS` object. The type can then be set with `PetscDSSetType()`.
6572764a2aaSMatthew G. Knepley 
658d083f849SBarry Smith   Collective
6592764a2aaSMatthew G. Knepley 
6602764a2aaSMatthew G. Knepley   Input Parameter:
661dce8aebaSBarry Smith . comm - The communicator for the `PetscDS` object
6622764a2aaSMatthew G. Knepley 
6632764a2aaSMatthew G. Knepley   Output Parameter:
664dce8aebaSBarry Smith . ds   - The `PetscDS` object
6652764a2aaSMatthew G. Knepley 
6662764a2aaSMatthew G. Knepley   Level: beginner
6672764a2aaSMatthew G. Knepley 
668dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetType()`, `PETSCDSBASIC`, `PetscDSType`
6692764a2aaSMatthew G. Knepley @*/
670d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds)
671d71ae5a4SJacob Faibussowitsch {
6722764a2aaSMatthew G. Knepley   PetscDS p;
6732764a2aaSMatthew G. Knepley 
6742764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6756528b96dSMatthew G. Knepley   PetscValidPointer(ds, 2);
6766528b96dSMatthew G. Knepley   *ds = NULL;
6779566063dSJacob Faibussowitsch   PetscCall(PetscDSInitializePackage());
6782764a2aaSMatthew G. Knepley 
6799566063dSJacob Faibussowitsch   PetscCall(PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView));
6802764a2aaSMatthew G. Knepley 
6812764a2aaSMatthew G. Knepley   p->Nf           = 0;
6822764a2aaSMatthew G. Knepley   p->setup        = PETSC_FALSE;
68397b6e6e8SMatthew G. Knepley   p->numConstants = 0;
68497b6e6e8SMatthew G. Knepley   p->constants    = NULL;
685a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
68655c1f793SMatthew G. Knepley   p->useJacPre    = PETSC_TRUE;
68712fc5b22SMatthew G. Knepley   p->forceQuad    = PETSC_TRUE;
6889566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(comm, &p->wf));
6892764a2aaSMatthew G. Knepley 
6906528b96dSMatthew G. Knepley   *ds = p;
6913ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
6922764a2aaSMatthew G. Knepley }
6932764a2aaSMatthew G. Knepley 
694bc4ae4beSMatthew G. Knepley /*@
695dce8aebaSBarry Smith   PetscDSGetNumFields - Returns the number of fields in the `PetscDS`
696bc4ae4beSMatthew G. Knepley 
69720f4b53cSBarry Smith   Not Collective
698bc4ae4beSMatthew G. Knepley 
699bc4ae4beSMatthew G. Knepley   Input Parameter:
70020f4b53cSBarry Smith . prob - The `PetscDS` object
701bc4ae4beSMatthew G. Knepley 
702bc4ae4beSMatthew G. Knepley   Output Parameter:
703bc4ae4beSMatthew G. Knepley . Nf - The number of fields
704bc4ae4beSMatthew G. Knepley 
705bc4ae4beSMatthew G. Knepley   Level: beginner
706bc4ae4beSMatthew G. Knepley 
707dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetSpatialDimension()`, `PetscDSCreate()`
708bc4ae4beSMatthew G. Knepley @*/
709d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
710d71ae5a4SJacob Faibussowitsch {
7112764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7122764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
713dadcf809SJacob Faibussowitsch   PetscValidIntPointer(Nf, 2);
7142764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
7153ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
7162764a2aaSMatthew G. Knepley }
7172764a2aaSMatthew G. Knepley 
718bc4ae4beSMatthew G. Knepley /*@
719dce8aebaSBarry Smith   PetscDSGetSpatialDimension - Returns the spatial dimension of the `PetscDS`, meaning the topological dimension of the discretizations
720bc4ae4beSMatthew G. Knepley 
72120f4b53cSBarry Smith   Not Collective
722bc4ae4beSMatthew G. Knepley 
723bc4ae4beSMatthew G. Knepley   Input Parameter:
724dce8aebaSBarry Smith . prob - The `PetscDS` object
725bc4ae4beSMatthew G. Knepley 
726bc4ae4beSMatthew G. Knepley   Output Parameter:
727bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
728bc4ae4beSMatthew G. Knepley 
729bc4ae4beSMatthew G. Knepley   Level: beginner
730bc4ae4beSMatthew G. Knepley 
731dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetCoordinateDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
732bc4ae4beSMatthew G. Knepley @*/
733d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
734d71ae5a4SJacob Faibussowitsch {
7352764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7362764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
737dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dim, 2);
7382764a2aaSMatthew G. Knepley   *dim = 0;
7399de99aefSMatthew G. Knepley   if (prob->Nf) {
7409de99aefSMatthew G. Knepley     PetscObject  obj;
7419de99aefSMatthew G. Knepley     PetscClassId id;
7429de99aefSMatthew G. Knepley 
7439566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(prob, 0, &obj));
744665f567fSMatthew G. Knepley     if (obj) {
7459566063dSJacob Faibussowitsch       PetscCall(PetscObjectGetClassId(obj, &id));
7469566063dSJacob Faibussowitsch       if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetSpatialDimension((PetscFE)obj, dim));
7479566063dSJacob Faibussowitsch       else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetSpatialDimension((PetscFV)obj, dim));
74898921bdaSJacob Faibussowitsch       else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
7499de99aefSMatthew G. Knepley     }
750665f567fSMatthew G. Knepley   }
7513ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
7522764a2aaSMatthew G. Knepley }
7532764a2aaSMatthew G. Knepley 
754bc4ae4beSMatthew G. Knepley /*@
755dce8aebaSBarry Smith   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the `PetscDS`, meaning the dimension of the space into which the discretiaztions are embedded
756a859676bSMatthew G. Knepley 
75720f4b53cSBarry Smith   Not Collective
758a859676bSMatthew G. Knepley 
759a859676bSMatthew G. Knepley   Input Parameter:
760dce8aebaSBarry Smith . prob - The `PetscDS` object
761a859676bSMatthew G. Knepley 
762a859676bSMatthew G. Knepley   Output Parameter:
763a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
764a859676bSMatthew G. Knepley 
765a859676bSMatthew G. Knepley   Level: beginner
766a859676bSMatthew G. Knepley 
767dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
768a859676bSMatthew G. Knepley @*/
769d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
770d71ae5a4SJacob Faibussowitsch {
771a859676bSMatthew G. Knepley   PetscFunctionBegin;
772a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
773dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dimEmbed, 2);
77408401ef6SPierre Jolivet   PetscCheck(prob->dimEmbed >= 0, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
775a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
7763ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
777a859676bSMatthew G. Knepley }
778a859676bSMatthew G. Knepley 
779a859676bSMatthew G. Knepley /*@
780dce8aebaSBarry Smith   PetscDSSetCoordinateDimension - Set the coordinate dimension of the `PetscDS`, meaning the dimension of the space into which the discretiaztions are embedded
781a859676bSMatthew G. Knepley 
78220f4b53cSBarry Smith   Logically Collective
783a859676bSMatthew G. Knepley 
784a859676bSMatthew G. Knepley   Input Parameters:
785dce8aebaSBarry Smith + prob - The `PetscDS` object
786a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
787a859676bSMatthew G. Knepley 
788a859676bSMatthew G. Knepley   Level: beginner
789a859676bSMatthew G. Knepley 
790dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
791a859676bSMatthew G. Knepley @*/
792d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
793d71ae5a4SJacob Faibussowitsch {
794a859676bSMatthew G. Knepley   PetscFunctionBegin;
795a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
79663a3b9bcSJacob Faibussowitsch   PetscCheck(dimEmbed >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %" PetscInt_FMT, dimEmbed);
797a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
7983ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
799a859676bSMatthew G. Knepley }
800a859676bSMatthew G. Knepley 
801a859676bSMatthew G. Knepley /*@
80212fc5b22SMatthew G. Knepley   PetscDSGetForceQuad - Returns the flag to force matching quadratures among the field discretizations
80312fc5b22SMatthew G. Knepley 
80412fc5b22SMatthew G. Knepley   Not collective
80512fc5b22SMatthew G. Knepley 
80612fc5b22SMatthew G. Knepley   Input Parameter:
80712fc5b22SMatthew G. Knepley . prob - The `PetscDS` object
80812fc5b22SMatthew G. Knepley 
80912fc5b22SMatthew G. Knepley   Output Parameter:
81012fc5b22SMatthew G. Knepley . forceQuad - The flag
81112fc5b22SMatthew G. Knepley 
81212fc5b22SMatthew G. Knepley   Level: intermediate
81312fc5b22SMatthew G. Knepley 
81412fc5b22SMatthew G. Knepley .seealso: `PetscDS`, `PetscDSSetForceQuad()`, `PetscDSGetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
81512fc5b22SMatthew G. Knepley @*/
81612fc5b22SMatthew G. Knepley PetscErrorCode PetscDSGetForceQuad(PetscDS ds, PetscBool *forceQuad)
81712fc5b22SMatthew G. Knepley {
81812fc5b22SMatthew G. Knepley   PetscFunctionBegin;
81912fc5b22SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
820f87a0b54SStefano Zampini   PetscValidBoolPointer(forceQuad, 2);
82112fc5b22SMatthew G. Knepley   *forceQuad = ds->forceQuad;
82212fc5b22SMatthew G. Knepley   PetscFunctionReturn(PETSC_SUCCESS);
82312fc5b22SMatthew G. Knepley }
82412fc5b22SMatthew G. Knepley 
82512fc5b22SMatthew G. Knepley /*@
82612fc5b22SMatthew G. Knepley   PetscDSSetForceQuad - Set the flag to force matching quadratures among the field discretizations
82712fc5b22SMatthew G. Knepley 
82812fc5b22SMatthew G. Knepley   Logically collective on ds
82912fc5b22SMatthew G. Knepley 
83012fc5b22SMatthew G. Knepley   Input Parameters:
83112fc5b22SMatthew G. Knepley + ds - The `PetscDS` object
83212fc5b22SMatthew G. Knepley - forceQuad - The flag
83312fc5b22SMatthew G. Knepley 
83412fc5b22SMatthew G. Knepley   Level: intermediate
83512fc5b22SMatthew G. Knepley 
83612fc5b22SMatthew G. Knepley .seealso: `PetscDS`, `PetscDSGetForceQuad()`, `PetscDSGetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
83712fc5b22SMatthew G. Knepley @*/
83812fc5b22SMatthew G. Knepley PetscErrorCode PetscDSSetForceQuad(PetscDS ds, PetscBool forceQuad)
83912fc5b22SMatthew G. Knepley {
84012fc5b22SMatthew G. Knepley   PetscFunctionBegin;
84112fc5b22SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
84212fc5b22SMatthew G. Knepley   ds->forceQuad = forceQuad;
84312fc5b22SMatthew G. Knepley   PetscFunctionReturn(PETSC_SUCCESS);
84412fc5b22SMatthew G. Knepley }
84512fc5b22SMatthew G. Knepley 
84612fc5b22SMatthew G. Knepley /*@
847dce8aebaSBarry Smith   PetscDSIsCohesive - Returns the flag indicating that this `PetscDS` is for a cohesive cell
8488edf6225SMatthew G. Knepley 
84920f4b53cSBarry Smith   Not Collective
8508edf6225SMatthew G. Knepley 
8518edf6225SMatthew G. Knepley   Input Parameter:
852dce8aebaSBarry Smith . ds - The `PetscDS` object
8538edf6225SMatthew G. Knepley 
8548edf6225SMatthew G. Knepley   Output Parameter:
8555fedec97SMatthew G. Knepley . isCohesive - The flag
8568edf6225SMatthew G. Knepley 
8578edf6225SMatthew G. Knepley   Level: developer
8588edf6225SMatthew G. Knepley 
859dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumCohesive()`, `PetscDSGetCohesive()`, `PetscDSSetCohesive()`, `PetscDSCreate()`
8608edf6225SMatthew G. Knepley @*/
861d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSIsCohesive(PetscDS ds, PetscBool *isCohesive)
862d71ae5a4SJacob Faibussowitsch {
8638edf6225SMatthew G. Knepley   PetscFunctionBegin;
8645fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
865dadcf809SJacob Faibussowitsch   PetscValidBoolPointer(isCohesive, 2);
8665fedec97SMatthew G. Knepley   *isCohesive = ds->isCohesive;
8673ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
8688edf6225SMatthew G. Knepley }
8698edf6225SMatthew G. Knepley 
8708edf6225SMatthew G. Knepley /*@
8715fedec97SMatthew G. Knepley   PetscDSGetNumCohesive - Returns the numer of cohesive fields, meaning those defined on the interior of a cohesive cell
8725fedec97SMatthew G. Knepley 
87320f4b53cSBarry Smith   Not Collective
8745fedec97SMatthew G. Knepley 
8755fedec97SMatthew G. Knepley   Input Parameter:
876dce8aebaSBarry Smith . ds - The `PetscDS` object
8775fedec97SMatthew G. Knepley 
8785fedec97SMatthew G. Knepley   Output Parameter:
8795fedec97SMatthew G. Knepley . numCohesive - The number of cohesive fields
8805fedec97SMatthew G. Knepley 
8815fedec97SMatthew G. Knepley   Level: developer
8825fedec97SMatthew G. Knepley 
883dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetCohesive()`, `PetscDSCreate()`
8845fedec97SMatthew G. Knepley @*/
885d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumCohesive(PetscDS ds, PetscInt *numCohesive)
886d71ae5a4SJacob Faibussowitsch {
8875fedec97SMatthew G. Knepley   PetscInt f;
8885fedec97SMatthew G. Knepley 
8895fedec97SMatthew G. Knepley   PetscFunctionBegin;
8905fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
891dadcf809SJacob Faibussowitsch   PetscValidIntPointer(numCohesive, 2);
8925fedec97SMatthew G. Knepley   *numCohesive = 0;
8935fedec97SMatthew G. Knepley   for (f = 0; f < ds->Nf; ++f) *numCohesive += ds->cohesive[f] ? 1 : 0;
8943ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
8955fedec97SMatthew G. Knepley }
8965fedec97SMatthew G. Knepley 
8975fedec97SMatthew G. Knepley /*@
8985fedec97SMatthew G. Knepley   PetscDSGetCohesive - Returns the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell
8995fedec97SMatthew G. Knepley 
90020f4b53cSBarry Smith   Not Collective
9015fedec97SMatthew G. Knepley 
902f1a722f8SMatthew G. Knepley   Input Parameters:
903dce8aebaSBarry Smith + ds - The `PetscDS` object
9045fedec97SMatthew G. Knepley - f  - The field index
9055fedec97SMatthew G. Knepley 
9065fedec97SMatthew G. Knepley   Output Parameter:
9075fedec97SMatthew G. Knepley . isCohesive - The flag
9085fedec97SMatthew G. Knepley 
9095fedec97SMatthew G. Knepley   Level: developer
9105fedec97SMatthew G. Knepley 
911dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()`
9125fedec97SMatthew G. Knepley @*/
913d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetCohesive(PetscDS ds, PetscInt f, PetscBool *isCohesive)
914d71ae5a4SJacob Faibussowitsch {
9155fedec97SMatthew G. Knepley   PetscFunctionBegin;
9165fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
917dadcf809SJacob Faibussowitsch   PetscValidBoolPointer(isCohesive, 3);
91863a3b9bcSJacob 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);
9195fedec97SMatthew G. Knepley   *isCohesive = ds->cohesive[f];
9203ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9215fedec97SMatthew G. Knepley }
9225fedec97SMatthew G. Knepley 
9235fedec97SMatthew G. Knepley /*@
9245fedec97SMatthew G. Knepley   PetscDSSetCohesive - Set the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell
9258edf6225SMatthew G. Knepley 
92620f4b53cSBarry Smith   Not Collective
9278edf6225SMatthew G. Knepley 
9288edf6225SMatthew G. Knepley   Input Parameters:
929dce8aebaSBarry Smith + ds - The `PetscDS` object
9305fedec97SMatthew G. Knepley . f  - The field index
9315fedec97SMatthew G. Knepley - isCohesive - The flag for a cohesive field
9328edf6225SMatthew G. Knepley 
9338edf6225SMatthew G. Knepley   Level: developer
9348edf6225SMatthew G. Knepley 
935dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()`
9368edf6225SMatthew G. Knepley @*/
937d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetCohesive(PetscDS ds, PetscInt f, PetscBool isCohesive)
938d71ae5a4SJacob Faibussowitsch {
9395fedec97SMatthew G. Knepley   PetscInt i;
9405fedec97SMatthew G. Knepley 
9418edf6225SMatthew G. Knepley   PetscFunctionBegin;
9425fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
94363a3b9bcSJacob 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);
9445fedec97SMatthew G. Knepley   ds->cohesive[f] = isCohesive;
9455fedec97SMatthew G. Knepley   ds->isCohesive  = PETSC_FALSE;
9465fedec97SMatthew G. Knepley   for (i = 0; i < ds->Nf; ++i) ds->isCohesive = ds->isCohesive || ds->cohesive[f] ? PETSC_TRUE : PETSC_FALSE;
9473ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9488edf6225SMatthew G. Knepley }
9498edf6225SMatthew G. Knepley 
9508edf6225SMatthew G. Knepley /*@
951bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
952bc4ae4beSMatthew G. Knepley 
95320f4b53cSBarry Smith   Not Collective
954bc4ae4beSMatthew G. Knepley 
955bc4ae4beSMatthew G. Knepley   Input Parameter:
956dce8aebaSBarry Smith . prob - The `PetscDS` object
957bc4ae4beSMatthew G. Knepley 
958bc4ae4beSMatthew G. Knepley   Output Parameter:
959bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
960bc4ae4beSMatthew G. Knepley 
961bc4ae4beSMatthew G. Knepley   Level: beginner
962bc4ae4beSMatthew G. Knepley 
963dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
964bc4ae4beSMatthew G. Knepley @*/
965d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
966d71ae5a4SJacob Faibussowitsch {
9672764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9682764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9699566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
970dadcf809SJacob Faibussowitsch   PetscValidIntPointer(dim, 2);
9712764a2aaSMatthew G. Knepley   *dim = prob->totDim;
9723ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9732764a2aaSMatthew G. Knepley }
9742764a2aaSMatthew G. Knepley 
975bc4ae4beSMatthew G. Knepley /*@
976bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
977bc4ae4beSMatthew G. Knepley 
97820f4b53cSBarry Smith   Not Collective
979bc4ae4beSMatthew G. Knepley 
980bc4ae4beSMatthew G. Knepley   Input Parameter:
981dce8aebaSBarry Smith . prob - The `PetscDS` object
982bc4ae4beSMatthew G. Knepley 
983bc4ae4beSMatthew G. Knepley   Output Parameter:
984bc4ae4beSMatthew G. Knepley . dim - The total number of components
985bc4ae4beSMatthew G. Knepley 
986bc4ae4beSMatthew G. Knepley   Level: beginner
987bc4ae4beSMatthew G. Knepley 
988dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
989bc4ae4beSMatthew G. Knepley @*/
990d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
991d71ae5a4SJacob Faibussowitsch {
9922764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9932764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9949566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
995dadcf809SJacob Faibussowitsch   PetscValidIntPointer(Nc, 2);
9962764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
9973ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9982764a2aaSMatthew G. Knepley }
9992764a2aaSMatthew G. Knepley 
1000bc4ae4beSMatthew G. Knepley /*@
1001bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
1002bc4ae4beSMatthew G. Knepley 
100320f4b53cSBarry Smith   Not Collective
1004bc4ae4beSMatthew G. Knepley 
1005bc4ae4beSMatthew G. Knepley   Input Parameters:
1006dce8aebaSBarry Smith + prob - The `PetscDS` object
1007bc4ae4beSMatthew G. Knepley - f - The field number
1008bc4ae4beSMatthew G. Knepley 
1009bc4ae4beSMatthew G. Knepley   Output Parameter:
1010bc4ae4beSMatthew G. Knepley . disc - The discretization object
1011bc4ae4beSMatthew G. Knepley 
1012bc4ae4beSMatthew G. Knepley   Level: beginner
1013bc4ae4beSMatthew G. Knepley 
1014dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscFE`, `PetscFV`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1015bc4ae4beSMatthew G. Knepley @*/
1016d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
1017d71ae5a4SJacob Faibussowitsch {
10186528b96dSMatthew G. Knepley   PetscFunctionBeginHot;
10192764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10202764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
102163a3b9bcSJacob 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);
10222764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
10233ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10242764a2aaSMatthew G. Knepley }
10252764a2aaSMatthew G. Knepley 
1026bc4ae4beSMatthew G. Knepley /*@
1027bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
1028bc4ae4beSMatthew G. Knepley 
102920f4b53cSBarry Smith   Not Collective
1030bc4ae4beSMatthew G. Knepley 
1031bc4ae4beSMatthew G. Knepley   Input Parameters:
1032dce8aebaSBarry Smith + prob - The `PetscDS` object
1033bc4ae4beSMatthew G. Knepley . f - The field number
1034bc4ae4beSMatthew G. Knepley - disc - The discretization object
1035bc4ae4beSMatthew G. Knepley 
1036bc4ae4beSMatthew G. Knepley   Level: beginner
1037bc4ae4beSMatthew G. Knepley 
1038dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscFE`, `PetscFV`, `PetscDSGetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1039bc4ae4beSMatthew G. Knepley @*/
1040d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
1041d71ae5a4SJacob Faibussowitsch {
10422764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10432764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1044665f567fSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
104563a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
10469566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(prob, f + 1));
10479566063dSJacob Faibussowitsch   PetscCall(PetscObjectDereference(prob->disc[f]));
10482764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
10499566063dSJacob Faibussowitsch   PetscCall(PetscObjectReference(disc));
1050665f567fSMatthew G. Knepley   if (disc) {
1051249df284SMatthew G. Knepley     PetscClassId id;
1052249df284SMatthew G. Knepley 
10539566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetClassId(disc, &id));
10541cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
10559566063dSJacob Faibussowitsch       PetscCall(PetscDSSetImplicit(prob, f, PETSC_TRUE));
10561cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
10579566063dSJacob Faibussowitsch       PetscCall(PetscDSSetImplicit(prob, f, PETSC_FALSE));
1058a6cbbb48SMatthew G. Knepley     }
10599566063dSJacob Faibussowitsch     PetscCall(PetscDSSetJetDegree(prob, f, 1));
1060249df284SMatthew G. Knepley   }
10613ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10622764a2aaSMatthew G. Knepley }
10632764a2aaSMatthew G. Knepley 
1064bc4ae4beSMatthew G. Knepley /*@
10656528b96dSMatthew G. Knepley   PetscDSGetWeakForm - Returns the weak form object
10666528b96dSMatthew G. Knepley 
106720f4b53cSBarry Smith   Not Collective
10686528b96dSMatthew G. Knepley 
10696528b96dSMatthew G. Knepley   Input Parameter:
1070dce8aebaSBarry Smith . ds - The `PetscDS` object
10716528b96dSMatthew G. Knepley 
10726528b96dSMatthew G. Knepley   Output Parameter:
10736528b96dSMatthew G. Knepley . wf - The weak form object
10746528b96dSMatthew G. Knepley 
10756528b96dSMatthew G. Knepley   Level: beginner
10766528b96dSMatthew G. Knepley 
1077dce8aebaSBarry Smith .seealso: `PetscWeakForm`, `PetscDSSetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
10786528b96dSMatthew G. Knepley @*/
1079d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf)
1080d71ae5a4SJacob Faibussowitsch {
10816528b96dSMatthew G. Knepley   PetscFunctionBegin;
10826528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
10836528b96dSMatthew G. Knepley   PetscValidPointer(wf, 2);
10846528b96dSMatthew G. Knepley   *wf = ds->wf;
10853ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10866528b96dSMatthew G. Knepley }
10876528b96dSMatthew G. Knepley 
10886528b96dSMatthew G. Knepley /*@
10896528b96dSMatthew G. Knepley   PetscDSSetWeakForm - Sets the weak form object
10906528b96dSMatthew G. Knepley 
109120f4b53cSBarry Smith   Not Collective
10926528b96dSMatthew G. Knepley 
10936528b96dSMatthew G. Knepley   Input Parameters:
1094dce8aebaSBarry Smith + ds - The `PetscDS` object
10956528b96dSMatthew G. Knepley - wf - The weak form object
10966528b96dSMatthew G. Knepley 
10976528b96dSMatthew G. Knepley   Level: beginner
10986528b96dSMatthew G. Knepley 
1099dce8aebaSBarry Smith .seealso: `PetscWeakForm`, `PetscDSGetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
11006528b96dSMatthew G. Knepley @*/
1101d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf)
1102d71ae5a4SJacob Faibussowitsch {
11036528b96dSMatthew G. Knepley   PetscFunctionBegin;
11046528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
11056528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2);
11069566063dSJacob Faibussowitsch   PetscCall(PetscObjectDereference((PetscObject)ds->wf));
11076528b96dSMatthew G. Knepley   ds->wf = wf;
11089566063dSJacob Faibussowitsch   PetscCall(PetscObjectReference((PetscObject)wf));
11099566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(wf, ds->Nf));
11103ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
11116528b96dSMatthew G. Knepley }
11126528b96dSMatthew G. Knepley 
11136528b96dSMatthew G. Knepley /*@
1114bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
1115bc4ae4beSMatthew G. Knepley 
111620f4b53cSBarry Smith   Not Collective
1117bc4ae4beSMatthew G. Knepley 
1118bc4ae4beSMatthew G. Knepley   Input Parameters:
1119dce8aebaSBarry Smith + prob - The `PetscDS` object
1120bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
1121bc4ae4beSMatthew G. Knepley 
1122bc4ae4beSMatthew G. Knepley   Level: beginner
1123bc4ae4beSMatthew G. Knepley 
1124dce8aebaSBarry Smith .seealso: `PetscWeakForm`, `PetscDSGetDiscretization()`, `PetscDSSetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1125bc4ae4beSMatthew G. Knepley @*/
1126d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
1127d71ae5a4SJacob Faibussowitsch {
11282764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11299566063dSJacob Faibussowitsch   PetscCall(PetscDSSetDiscretization(prob, prob->Nf, disc));
11303ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
11312764a2aaSMatthew G. Knepley }
11322764a2aaSMatthew G. Knepley 
1133249df284SMatthew G. Knepley /*@
1134dce8aebaSBarry Smith   PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the `PetscDS`
1135083401c6SMatthew G. Knepley 
113620f4b53cSBarry Smith   Not Collective
1137083401c6SMatthew G. Knepley 
1138083401c6SMatthew G. Knepley   Input Parameter:
1139dce8aebaSBarry Smith . prob - The `PetscDS` object
1140083401c6SMatthew G. Knepley 
1141083401c6SMatthew G. Knepley   Output Parameter:
1142083401c6SMatthew G. Knepley . q - The quadrature object
1143083401c6SMatthew G. Knepley 
1144083401c6SMatthew G. Knepley   Level: intermediate
1145083401c6SMatthew G. Knepley 
1146dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscQuadrature`, `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1147083401c6SMatthew G. Knepley @*/
1148d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q)
1149d71ae5a4SJacob Faibussowitsch {
1150083401c6SMatthew G. Knepley   PetscObject  obj;
1151083401c6SMatthew G. Knepley   PetscClassId id;
1152083401c6SMatthew G. Knepley 
1153083401c6SMatthew G. Knepley   PetscFunctionBegin;
1154083401c6SMatthew G. Knepley   *q = NULL;
11553ba16761SJacob Faibussowitsch   if (!prob->Nf) PetscFunctionReturn(PETSC_SUCCESS);
11569566063dSJacob Faibussowitsch   PetscCall(PetscDSGetDiscretization(prob, 0, &obj));
11579566063dSJacob Faibussowitsch   PetscCall(PetscObjectGetClassId(obj, &id));
11589566063dSJacob Faibussowitsch   if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetQuadrature((PetscFE)obj, q));
11599566063dSJacob Faibussowitsch   else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetQuadrature((PetscFV)obj, q));
116098921bdaSJacob Faibussowitsch   else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
11613ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1162083401c6SMatthew G. Knepley }
1163083401c6SMatthew G. Knepley 
1164083401c6SMatthew G. Knepley /*@
1165dce8aebaSBarry Smith   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for `TSIMEX`
1166249df284SMatthew G. Knepley 
116720f4b53cSBarry Smith   Not Collective
1168249df284SMatthew G. Knepley 
1169249df284SMatthew G. Knepley   Input Parameters:
1170dce8aebaSBarry Smith + prob - The `PetscDS` object
1171249df284SMatthew G. Knepley - f - The field number
1172249df284SMatthew G. Knepley 
1173249df284SMatthew G. Knepley   Output Parameter:
1174249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
1175249df284SMatthew G. Knepley 
1176249df284SMatthew G. Knepley   Level: developer
1177249df284SMatthew G. Knepley 
1178dce8aebaSBarry Smith .seealso: `TSIMEX`, `PetscDS`, `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1179249df284SMatthew G. Knepley @*/
1180d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
1181d71ae5a4SJacob Faibussowitsch {
1182249df284SMatthew G. Knepley   PetscFunctionBegin;
1183249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1184dadcf809SJacob Faibussowitsch   PetscValidBoolPointer(implicit, 3);
118563a3b9bcSJacob 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);
1186249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
11873ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1188249df284SMatthew G. Knepley }
1189249df284SMatthew G. Knepley 
1190249df284SMatthew G. Knepley /*@
1191dce8aebaSBarry Smith   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for `TSIMEX`
1192249df284SMatthew G. Knepley 
119320f4b53cSBarry Smith   Not Collective
1194249df284SMatthew G. Knepley 
1195249df284SMatthew G. Knepley   Input Parameters:
1196dce8aebaSBarry Smith + prob - The `PetscDS` object
1197249df284SMatthew G. Knepley . f - The field number
1198249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
1199249df284SMatthew G. Knepley 
1200249df284SMatthew G. Knepley   Level: developer
1201249df284SMatthew G. Knepley 
1202dce8aebaSBarry Smith .seealso: `TSIMEX`, `PetscDSGetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1203249df284SMatthew G. Knepley @*/
1204d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
1205d71ae5a4SJacob Faibussowitsch {
1206249df284SMatthew G. Knepley   PetscFunctionBegin;
1207249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
120863a3b9bcSJacob 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);
1209249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
12103ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1211249df284SMatthew G. Knepley }
1212249df284SMatthew G. Knepley 
1213f9244615SMatthew G. Knepley /*@
1214f9244615SMatthew G. Knepley   PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1215f9244615SMatthew G. Knepley 
121620f4b53cSBarry Smith   Not Collective
1217f9244615SMatthew G. Knepley 
1218f9244615SMatthew G. Knepley   Input Parameters:
1219dce8aebaSBarry Smith + ds - The `PetscDS` object
1220f9244615SMatthew G. Knepley - f  - The field number
1221f9244615SMatthew G. Knepley 
1222f9244615SMatthew G. Knepley   Output Parameter:
1223f9244615SMatthew G. Knepley . k  - The highest derivative we need to tabulate
1224f9244615SMatthew G. Knepley 
1225f9244615SMatthew G. Knepley   Level: developer
1226f9244615SMatthew G. Knepley 
1227dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1228f9244615SMatthew G. Knepley @*/
1229d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k)
1230d71ae5a4SJacob Faibussowitsch {
1231f9244615SMatthew G. Knepley   PetscFunctionBegin;
1232f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1233dadcf809SJacob Faibussowitsch   PetscValidIntPointer(k, 3);
123463a3b9bcSJacob 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);
1235f9244615SMatthew G. Knepley   *k = ds->jetDegree[f];
12363ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1237f9244615SMatthew G. Knepley }
1238f9244615SMatthew G. Knepley 
1239f9244615SMatthew G. Knepley /*@
1240f9244615SMatthew G. Knepley   PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate.
1241f9244615SMatthew G. Knepley 
124220f4b53cSBarry Smith   Not Collective
1243f9244615SMatthew G. Knepley 
1244f9244615SMatthew G. Knepley   Input Parameters:
1245dce8aebaSBarry Smith + ds - The `PetscDS` object
1246f9244615SMatthew G. Knepley . f  - The field number
1247f9244615SMatthew G. Knepley - k  - The highest derivative we need to tabulate
1248f9244615SMatthew G. Knepley 
1249f9244615SMatthew G. Knepley   Level: developer
1250f9244615SMatthew G. Knepley 
1251dce8aebaSBarry Smith .seealso: ``PetscDS`, PetscDSGetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
1252f9244615SMatthew G. Knepley @*/
1253d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k)
1254d71ae5a4SJacob Faibussowitsch {
1255f9244615SMatthew G. Knepley   PetscFunctionBegin;
1256f9244615SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
125763a3b9bcSJacob 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);
1258f9244615SMatthew G. Knepley   ds->jetDegree[f] = k;
12593ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1260f9244615SMatthew G. Knepley }
1261f9244615SMatthew G. Knepley 
1262d71ae5a4SJacob 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[]))
1263d71ae5a4SJacob Faibussowitsch {
12646528b96dSMatthew G. Knepley   PetscPointFunc *tmp;
12656528b96dSMatthew G. Knepley   PetscInt        n;
12666528b96dSMatthew G. Knepley 
12672764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12686528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
12696528b96dSMatthew G. Knepley   PetscValidPointer(obj, 3);
127063a3b9bcSJacob 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);
12719566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetObjective(ds->wf, NULL, 0, f, 0, &n, &tmp));
12726528b96dSMatthew G. Knepley   *obj = tmp ? tmp[0] : NULL;
12733ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
12742764a2aaSMatthew G. Knepley }
12752764a2aaSMatthew G. Knepley 
1276d71ae5a4SJacob 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[]))
1277d71ae5a4SJacob Faibussowitsch {
12782764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12796528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
12806528b96dSMatthew G. Knepley   if (obj) PetscValidFunction(obj, 3);
128163a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
12829566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, 0, obj));
12833ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
12842764a2aaSMatthew G. Knepley }
12852764a2aaSMatthew G. Knepley 
1286194d53e6SMatthew G. Knepley /*@C
1287194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1288194d53e6SMatthew G. Knepley 
128920f4b53cSBarry Smith   Not Collective
1290194d53e6SMatthew G. Knepley 
1291194d53e6SMatthew G. Knepley   Input Parameters:
1292dce8aebaSBarry Smith + ds - The `PetscDS`
1293194d53e6SMatthew G. Knepley - f  - The test field number
1294194d53e6SMatthew G. Knepley 
1295194d53e6SMatthew G. Knepley   Output Parameters:
1296194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1297194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1298194d53e6SMatthew G. Knepley 
129920f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
1300dce8aebaSBarry Smith .vb
130120f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1302dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1303dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1304dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], PetscScalar f0[])
1305dce8aebaSBarry Smith .ve
1306194d53e6SMatthew G. Knepley + dim - the spatial dimension
1307194d53e6SMatthew G. Knepley . Nf - the number of fields
1308194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1309194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1310194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1311194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1312194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1313194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1314194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1315194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1316194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1317194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1318194d53e6SMatthew G. Knepley . t - current time
1319194d53e6SMatthew G. Knepley . x - coordinates of the current point
132097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
132197b6e6e8SMatthew G. Knepley . constants - constant parameters
1322194d53e6SMatthew G. Knepley - f0 - output values at the current point
1323194d53e6SMatthew G. Knepley 
1324194d53e6SMatthew G. Knepley   Level: intermediate
1325194d53e6SMatthew G. Knepley 
1326dce8aebaSBarry Smith   Note:
1327dce8aebaSBarry 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)
1328dce8aebaSBarry Smith 
1329dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetResidual()`
1330194d53e6SMatthew G. Knepley @*/
1331d71ae5a4SJacob 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[]))
1332d71ae5a4SJacob Faibussowitsch {
13336528b96dSMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
13346528b96dSMatthew G. Knepley   PetscInt        n0, n1;
13356528b96dSMatthew G. Knepley 
13362764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13376528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
133863a3b9bcSJacob 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);
13399566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1));
13406528b96dSMatthew G. Knepley   *f0 = tmp0 ? tmp0[0] : NULL;
13416528b96dSMatthew G. Knepley   *f1 = tmp1 ? tmp1[0] : NULL;
13423ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
13432764a2aaSMatthew G. Knepley }
13442764a2aaSMatthew G. Knepley 
1345194d53e6SMatthew G. Knepley /*@C
1346194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1347194d53e6SMatthew G. Knepley 
134820f4b53cSBarry Smith   Not Collective
1349194d53e6SMatthew G. Knepley 
1350194d53e6SMatthew G. Knepley   Input Parameters:
1351dce8aebaSBarry Smith + ds - The `PetscDS`
1352194d53e6SMatthew G. Knepley . f  - The test field number
1353194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1354194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1355194d53e6SMatthew G. Knepley 
135620f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
1357dce8aebaSBarry Smith .vb
135820f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1359dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1360dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1361dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], PetscScalar f0[])
1362dce8aebaSBarry Smith .ve
1363194d53e6SMatthew G. Knepley + dim - the spatial dimension
1364194d53e6SMatthew G. Knepley . Nf - the number of fields
1365194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1366194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1367194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1368194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1369194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1370194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1371194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1372194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1373194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1374194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1375194d53e6SMatthew G. Knepley . t - current time
1376194d53e6SMatthew G. Knepley . x - coordinates of the current point
137797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
137897b6e6e8SMatthew G. Knepley . constants - constant parameters
1379194d53e6SMatthew G. Knepley - f0 - output values at the current point
1380194d53e6SMatthew G. Knepley 
1381194d53e6SMatthew G. Knepley   Level: intermediate
1382194d53e6SMatthew G. Knepley 
1383dce8aebaSBarry Smith   Note:
1384dce8aebaSBarry 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)
1385dce8aebaSBarry Smith 
1386dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetResidual()`
1387194d53e6SMatthew G. Knepley @*/
1388d71ae5a4SJacob 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[]))
1389d71ae5a4SJacob Faibussowitsch {
13902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13916528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1392f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1393f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
139463a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
13959566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1));
13963ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
13972764a2aaSMatthew G. Knepley }
13982764a2aaSMatthew G. Knepley 
13993e75805dSMatthew G. Knepley /*@C
1400cb36c0f9SMatthew G. Knepley   PetscDSGetRHSResidual - Get the pointwise RHS residual function for explicit timestepping for a given test field
1401cb36c0f9SMatthew G. Knepley 
140220f4b53cSBarry Smith   Not Collective
1403cb36c0f9SMatthew G. Knepley 
1404cb36c0f9SMatthew G. Knepley   Input Parameters:
1405dce8aebaSBarry Smith + ds - The `PetscDS`
1406cb36c0f9SMatthew G. Knepley - f  - The test field number
1407cb36c0f9SMatthew G. Knepley 
1408cb36c0f9SMatthew G. Knepley   Output Parameters:
1409cb36c0f9SMatthew G. Knepley + f0 - integrand for the test function term
1410cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term
1411cb36c0f9SMatthew G. Knepley 
141220f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
1413dce8aebaSBarry Smith .vb
141420f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1415dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1416dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1417dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], PetscScalar f0[])
1418dce8aebaSBarry Smith .ve
1419cb36c0f9SMatthew G. Knepley + dim - the spatial dimension
1420cb36c0f9SMatthew G. Knepley . Nf - the number of fields
1421cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1422cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1423cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point
1424cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1425cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1426cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1427cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1428cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1429cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1430cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1431cb36c0f9SMatthew G. Knepley . t - current time
1432cb36c0f9SMatthew G. Knepley . x - coordinates of the current point
1433cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters
1434cb36c0f9SMatthew G. Knepley . constants - constant parameters
1435cb36c0f9SMatthew G. Knepley - f0 - output values at the current point
1436cb36c0f9SMatthew G. Knepley 
1437cb36c0f9SMatthew G. Knepley   Level: intermediate
1438cb36c0f9SMatthew G. Knepley 
1439dce8aebaSBarry Smith   Note:
1440dce8aebaSBarry 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)
1441dce8aebaSBarry Smith 
1442dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetRHSResidual()`
1443cb36c0f9SMatthew G. Knepley @*/
1444d71ae5a4SJacob 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[]))
1445d71ae5a4SJacob Faibussowitsch {
1446cb36c0f9SMatthew G. Knepley   PetscPointFunc *tmp0, *tmp1;
1447cb36c0f9SMatthew G. Knepley   PetscInt        n0, n1;
1448cb36c0f9SMatthew G. Knepley 
1449cb36c0f9SMatthew G. Knepley   PetscFunctionBegin;
1450cb36c0f9SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
145163a3b9bcSJacob 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);
14529566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 100, &n0, &tmp0, &n1, &tmp1));
1453cb36c0f9SMatthew G. Knepley   *f0 = tmp0 ? tmp0[0] : NULL;
1454cb36c0f9SMatthew G. Knepley   *f1 = tmp1 ? tmp1[0] : NULL;
14553ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1456cb36c0f9SMatthew G. Knepley }
1457cb36c0f9SMatthew G. Knepley 
1458cb36c0f9SMatthew G. Knepley /*@C
1459cb36c0f9SMatthew G. Knepley   PetscDSSetRHSResidual - Set the pointwise residual function for explicit timestepping for a given test field
1460cb36c0f9SMatthew G. Knepley 
146120f4b53cSBarry Smith   Not Collective
1462cb36c0f9SMatthew G. Knepley 
1463cb36c0f9SMatthew G. Knepley   Input Parameters:
1464dce8aebaSBarry Smith + ds - The `PetscDS`
1465cb36c0f9SMatthew G. Knepley . f  - The test field number
1466cb36c0f9SMatthew G. Knepley . f0 - integrand for the test function term
1467cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term
1468cb36c0f9SMatthew G. Knepley 
1469dce8aebaSBarry Smith   Clling sequence for the callbacks f0 and f1:
1470dce8aebaSBarry Smith .vb
1471dce8aebaSBarry Smith   f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1472dce8aebaSBarry Smith      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1473dce8aebaSBarry Smith      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1474dce8aebaSBarry Smith      PetscReal t, const PetscReal x[], PetscScalar f0[])
1475dce8aebaSBarry Smith .ve
1476cb36c0f9SMatthew G. Knepley + dim - the spatial dimension
1477cb36c0f9SMatthew G. Knepley . Nf - the number of fields
1478cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1479cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1480cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point
1481cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1482cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1483cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1484cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1485cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1486cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1487cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1488cb36c0f9SMatthew G. Knepley . t - current time
1489cb36c0f9SMatthew G. Knepley . x - coordinates of the current point
1490cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters
1491cb36c0f9SMatthew G. Knepley . constants - constant parameters
1492cb36c0f9SMatthew G. Knepley - f0 - output values at the current point
1493cb36c0f9SMatthew G. Knepley 
1494cb36c0f9SMatthew G. Knepley   Level: intermediate
1495cb36c0f9SMatthew G. Knepley 
1496dce8aebaSBarry Smith   Note:
1497dce8aebaSBarry 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)
1498dce8aebaSBarry Smith 
1499dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetResidual()`
1500cb36c0f9SMatthew G. Knepley @*/
1501d71ae5a4SJacob 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[]))
1502d71ae5a4SJacob Faibussowitsch {
1503cb36c0f9SMatthew G. Knepley   PetscFunctionBegin;
1504cb36c0f9SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1505cb36c0f9SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1506cb36c0f9SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
150763a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
15089566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 100, 0, f0, 0, f1));
15093ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1510cb36c0f9SMatthew G. Knepley }
1511cb36c0f9SMatthew G. Knepley 
1512cb36c0f9SMatthew G. Knepley /*@C
1513dce8aebaSBarry Smith   PetscDSHasJacobian - Checks that the Jacobian functions have been set
15143e75805dSMatthew G. Knepley 
151520f4b53cSBarry Smith   Not Collective
15163e75805dSMatthew G. Knepley 
15173e75805dSMatthew G. Knepley   Input Parameter:
1518dce8aebaSBarry Smith . prob - The `PetscDS`
15193e75805dSMatthew G. Knepley 
15203e75805dSMatthew G. Knepley   Output Parameter:
15213e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
15223e75805dSMatthew G. Knepley 
15233e75805dSMatthew G. Knepley   Level: intermediate
15243e75805dSMatthew G. Knepley 
1525dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
15263e75805dSMatthew G. Knepley @*/
1527d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac)
1528d71ae5a4SJacob Faibussowitsch {
15293e75805dSMatthew G. Knepley   PetscFunctionBegin;
15306528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
15319566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasJacobian(ds->wf, hasJac));
15323ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
15333e75805dSMatthew G. Knepley }
15343e75805dSMatthew G. Knepley 
1535194d53e6SMatthew G. Knepley /*@C
1536194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1537194d53e6SMatthew G. Knepley 
153820f4b53cSBarry Smith   Not Collective
1539194d53e6SMatthew G. Knepley 
1540194d53e6SMatthew G. Knepley   Input Parameters:
1541dce8aebaSBarry Smith + ds - The `PetscDS`
1542194d53e6SMatthew G. Knepley . f  - The test field number
1543194d53e6SMatthew G. Knepley - g  - The field number
1544194d53e6SMatthew G. Knepley 
1545194d53e6SMatthew G. Knepley   Output Parameters:
1546194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1547194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1548194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1549194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1550194d53e6SMatthew G. Knepley 
155120f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
1552dce8aebaSBarry Smith .vb
155320f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1554dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1555dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1556dce8aebaSBarry Smith           PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1557dce8aebaSBarry Smith .ve
1558194d53e6SMatthew G. Knepley + dim - the spatial dimension
1559194d53e6SMatthew G. Knepley . Nf - the number of fields
1560194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1561194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1562194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1563194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1564194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1565194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1566194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1567194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1568194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1569194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1570194d53e6SMatthew G. Knepley . t - current time
15712aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1572194d53e6SMatthew G. Knepley . x - coordinates of the current point
157397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
157497b6e6e8SMatthew G. Knepley . constants - constant parameters
1575194d53e6SMatthew G. Knepley - g0 - output values at the current point
1576194d53e6SMatthew G. Knepley 
1577194d53e6SMatthew G. Knepley   Level: intermediate
1578194d53e6SMatthew G. Knepley 
1579dce8aebaSBarry Smith   Note:
1580dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
1581dce8aebaSBarry 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
1582dce8aebaSBarry Smith 
1583dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJacobian()`
1584194d53e6SMatthew G. Knepley @*/
1585d71ae5a4SJacob 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[]))
1586d71ae5a4SJacob Faibussowitsch {
15876528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
15886528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
15896528b96dSMatthew G. Knepley 
15902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
15916528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
159263a3b9bcSJacob 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);
159363a3b9bcSJacob 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);
15949566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
15956528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
15966528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
15976528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
15986528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
15993ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
16002764a2aaSMatthew G. Knepley }
16012764a2aaSMatthew G. Knepley 
1602194d53e6SMatthew G. Knepley /*@C
1603194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1604194d53e6SMatthew G. Knepley 
160520f4b53cSBarry Smith   Not Collective
1606194d53e6SMatthew G. Knepley 
1607194d53e6SMatthew G. Knepley   Input Parameters:
1608dce8aebaSBarry Smith + ds - The `PetscDS`
1609194d53e6SMatthew G. Knepley . f  - The test field number
1610194d53e6SMatthew G. Knepley . g  - The field number
1611194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1612194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1613194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1614194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1615194d53e6SMatthew G. Knepley 
161620f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
1617dce8aebaSBarry Smith .vb
161820f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1619dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1620dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1621dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], PetscScalar g0[])
1622dce8aebaSBarry Smith .ve
1623194d53e6SMatthew G. Knepley + dim - the spatial dimension
1624194d53e6SMatthew G. Knepley . Nf - the number of fields
1625194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1626194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1627194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1628194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1629194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1630194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1631194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1632194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1633194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1634194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1635194d53e6SMatthew G. Knepley . t - current time
16362aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1637194d53e6SMatthew G. Knepley . x - coordinates of the current point
163897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
163997b6e6e8SMatthew G. Knepley . constants - constant parameters
1640194d53e6SMatthew G. Knepley - g0 - output values at the current point
1641194d53e6SMatthew G. Knepley 
1642194d53e6SMatthew G. Knepley   Level: intermediate
1643194d53e6SMatthew G. Knepley 
1644dce8aebaSBarry Smith   Note:
1645dce8aebaSBarry Smith    We are using a first order FEM model for the weak form:
1646dce8aebaSBarry 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
1647dce8aebaSBarry Smith 
1648dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobian()`
1649194d53e6SMatthew G. Knepley @*/
1650d71ae5a4SJacob 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[]))
1651d71ae5a4SJacob Faibussowitsch {
16522764a2aaSMatthew G. Knepley   PetscFunctionBegin;
16536528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
16542764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
16552764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
16562764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
16572764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
165863a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
165963a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
16609566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
16613ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
16622764a2aaSMatthew G. Knepley }
16632764a2aaSMatthew G. Knepley 
1664475e0ac9SMatthew G. Knepley /*@C
1665dce8aebaSBarry Smith   PetscDSUseJacobianPreconditioner - Set whether to construct a Jacobian preconditioner
166655c1f793SMatthew G. Knepley 
166720f4b53cSBarry Smith   Not Collective
166855c1f793SMatthew G. Knepley 
166955c1f793SMatthew G. Knepley   Input Parameters:
1670dce8aebaSBarry Smith + prob - The `PetscDS`
167155c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner
167255c1f793SMatthew G. Knepley 
167355c1f793SMatthew G. Knepley   Level: intermediate
167455c1f793SMatthew G. Knepley 
1675dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
167655c1f793SMatthew G. Knepley @*/
1677d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre)
1678d71ae5a4SJacob Faibussowitsch {
167955c1f793SMatthew G. Knepley   PetscFunctionBegin;
168055c1f793SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
168155c1f793SMatthew G. Knepley   prob->useJacPre = useJacPre;
16823ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
168355c1f793SMatthew G. Knepley }
168455c1f793SMatthew G. Knepley 
168555c1f793SMatthew G. Knepley /*@C
1686dce8aebaSBarry Smith   PetscDSHasJacobianPreconditioner - Checks if a Jacobian preconditioner matrix has been set
1687475e0ac9SMatthew G. Knepley 
168820f4b53cSBarry Smith   Not Collective
1689475e0ac9SMatthew G. Knepley 
1690475e0ac9SMatthew G. Knepley   Input Parameter:
1691dce8aebaSBarry Smith . prob - The `PetscDS`
1692475e0ac9SMatthew G. Knepley 
1693475e0ac9SMatthew G. Knepley   Output Parameter:
1694475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1695475e0ac9SMatthew G. Knepley 
1696475e0ac9SMatthew G. Knepley   Level: intermediate
1697475e0ac9SMatthew G. Knepley 
1698dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
1699475e0ac9SMatthew G. Knepley @*/
1700d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre)
1701d71ae5a4SJacob Faibussowitsch {
1702475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
17036528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1704475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
17053ba16761SJacob Faibussowitsch   if (!ds->useJacPre) PetscFunctionReturn(PETSC_SUCCESS);
17069566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre));
17073ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1708475e0ac9SMatthew G. Knepley }
1709475e0ac9SMatthew G. Knepley 
1710475e0ac9SMatthew G. Knepley /*@C
1711dce8aebaSBarry Smith   PetscDSGetJacobianPreconditioner - Get the pointwise Jacobian preconditioner function for given test and basis field. If this is missing,
1712dce8aebaSBarry Smith    the system matrix is used to build the preconditioner.
1713475e0ac9SMatthew G. Knepley 
171420f4b53cSBarry Smith   Not Collective
1715475e0ac9SMatthew G. Knepley 
1716475e0ac9SMatthew G. Knepley   Input Parameters:
1717dce8aebaSBarry Smith + ds - The `PetscDS`
1718475e0ac9SMatthew G. Knepley . f  - The test field number
1719475e0ac9SMatthew G. Knepley - g  - The field number
1720475e0ac9SMatthew G. Knepley 
1721475e0ac9SMatthew G. Knepley   Output Parameters:
1722475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1723475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1724475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1725475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1726475e0ac9SMatthew G. Knepley 
172720f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
1728dce8aebaSBarry Smith .vb
172920f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1730dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1731dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1732dce8aebaSBarry Smith           PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1733dce8aebaSBarry Smith .ve
1734475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1735475e0ac9SMatthew G. Knepley . Nf - the number of fields
1736475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1737475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1738475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1739475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1740475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1741475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1742475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1743475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1744475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1745475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1746475e0ac9SMatthew G. Knepley . t - current time
1747475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1748475e0ac9SMatthew G. Knepley . x - coordinates of the current point
174997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
175097b6e6e8SMatthew G. Knepley . constants - constant parameters
1751475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1752475e0ac9SMatthew G. Knepley 
1753475e0ac9SMatthew G. Knepley   Level: intermediate
1754475e0ac9SMatthew G. Knepley 
1755dce8aebaSBarry Smith   Note:
1756dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
1757dce8aebaSBarry 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
1758dce8aebaSBarry Smith 
1759dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()`
1760475e0ac9SMatthew G. Knepley @*/
1761d71ae5a4SJacob 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[]))
1762d71ae5a4SJacob Faibussowitsch {
17636528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
17646528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
17656528b96dSMatthew G. Knepley 
1766475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
17676528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
176863a3b9bcSJacob 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);
176963a3b9bcSJacob 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);
17709566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
17716528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
17726528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
17736528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
17746528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
17753ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1776475e0ac9SMatthew G. Knepley }
1777475e0ac9SMatthew G. Knepley 
1778475e0ac9SMatthew G. Knepley /*@C
1779dce8aebaSBarry Smith   PetscDSSetJacobianPreconditioner - Set the pointwise Jacobian preconditioner function for given test and basis fields.
1780dce8aebaSBarry Smith   If this is missing, the system matrix is used to build the preconditioner.
1781475e0ac9SMatthew G. Knepley 
178220f4b53cSBarry Smith   Not Collective
1783475e0ac9SMatthew G. Knepley 
1784475e0ac9SMatthew G. Knepley   Input Parameters:
1785dce8aebaSBarry Smith + ds - The `PetscDS`
1786475e0ac9SMatthew G. Knepley . f  - The test field number
1787475e0ac9SMatthew G. Knepley . g  - The field number
1788475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1789475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1790475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1791475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1792475e0ac9SMatthew G. Knepley 
179320f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
1794dce8aebaSBarry Smith .vb
179520f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1796dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1797dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1798dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], PetscScalar g0[])
1799dce8aebaSBarry Smith .ve
1800475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1801475e0ac9SMatthew G. Knepley . Nf - the number of fields
1802475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1803475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1804475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1805475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1806475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1807475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1808475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1809475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1810475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1811475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1812475e0ac9SMatthew G. Knepley . t - current time
1813475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1814475e0ac9SMatthew G. Knepley . x - coordinates of the current point
181597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
181697b6e6e8SMatthew G. Knepley . constants - constant parameters
1817475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1818475e0ac9SMatthew G. Knepley 
1819475e0ac9SMatthew G. Knepley   Level: intermediate
1820475e0ac9SMatthew G. Knepley 
1821dce8aebaSBarry Smith   Note:
1822dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
1823dce8aebaSBarry 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
1824dce8aebaSBarry Smith 
1825dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobian()`
1826475e0ac9SMatthew G. Knepley @*/
1827d71ae5a4SJacob 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[]))
1828d71ae5a4SJacob Faibussowitsch {
1829475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
18306528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1831475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1832475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1833475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1834475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
183563a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
183663a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
18379566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
18383ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1839475e0ac9SMatthew G. Knepley }
1840475e0ac9SMatthew G. Knepley 
1841b7e05686SMatthew G. Knepley /*@C
1842b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1843b7e05686SMatthew G. Knepley 
184420f4b53cSBarry Smith   Not Collective
1845b7e05686SMatthew G. Knepley 
1846b7e05686SMatthew G. Knepley   Input Parameter:
1847dce8aebaSBarry Smith . ds - The `PetscDS`
1848b7e05686SMatthew G. Knepley 
1849b7e05686SMatthew G. Knepley   Output Parameter:
1850b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1851b7e05686SMatthew G. Knepley 
1852b7e05686SMatthew G. Knepley   Level: intermediate
1853b7e05686SMatthew G. Knepley 
1854dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetDynamicJacobian()`, `PetscDSSetDynamicJacobian()`, `PetscDSGetJacobian()`
1855b7e05686SMatthew G. Knepley @*/
1856d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac)
1857d71ae5a4SJacob Faibussowitsch {
1858b7e05686SMatthew G. Knepley   PetscFunctionBegin;
18596528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
18609566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac));
18613ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1862b7e05686SMatthew G. Knepley }
1863b7e05686SMatthew G. Knepley 
1864b7e05686SMatthew G. Knepley /*@C
1865b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1866b7e05686SMatthew G. Knepley 
186720f4b53cSBarry Smith   Not Collective
1868b7e05686SMatthew G. Knepley 
1869b7e05686SMatthew G. Knepley   Input Parameters:
1870dce8aebaSBarry Smith + ds - The `PetscDS`
1871b7e05686SMatthew G. Knepley . f  - The test field number
1872b7e05686SMatthew G. Knepley - g  - The field number
1873b7e05686SMatthew G. Knepley 
1874b7e05686SMatthew G. Knepley   Output Parameters:
1875b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1876b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1877b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1878b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1879b7e05686SMatthew G. Knepley 
188020f4b53cSBarry Smith    Calling sequence of `g0`, `g1`, `g2` and `g3`:
1881dce8aebaSBarry Smith .vb
188220f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1883dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1884dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1885dce8aebaSBarry Smith           PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1886dce8aebaSBarry Smith .ve
1887b7e05686SMatthew G. Knepley + dim - the spatial dimension
1888b7e05686SMatthew G. Knepley . Nf - the number of fields
1889b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1890b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1891b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1892b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1893b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1894b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1895b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1896b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1897b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1898b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1899b7e05686SMatthew G. Knepley . t - current time
1900b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1901b7e05686SMatthew G. Knepley . x - coordinates of the current point
190297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
190397b6e6e8SMatthew G. Knepley . constants - constant parameters
1904b7e05686SMatthew G. Knepley - g0 - output values at the current point
1905b7e05686SMatthew G. Knepley 
1906b7e05686SMatthew G. Knepley   Level: intermediate
1907b7e05686SMatthew G. Knepley 
1908dce8aebaSBarry Smith   Note:
1909dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
1910dce8aebaSBarry 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
1911dce8aebaSBarry Smith 
1912dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJacobian()`
1913b7e05686SMatthew G. Knepley @*/
1914d71ae5a4SJacob 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[]))
1915d71ae5a4SJacob Faibussowitsch {
19166528b96dSMatthew G. Knepley   PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3;
19176528b96dSMatthew G. Knepley   PetscInt       n0, n1, n2, n3;
19186528b96dSMatthew G. Knepley 
1919b7e05686SMatthew G. Knepley   PetscFunctionBegin;
19206528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
192163a3b9bcSJacob 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);
192263a3b9bcSJacob 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);
19239566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
19246528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
19256528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
19266528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
19276528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
19283ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1929b7e05686SMatthew G. Knepley }
1930b7e05686SMatthew G. Knepley 
1931b7e05686SMatthew G. Knepley /*@C
1932b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1933b7e05686SMatthew G. Knepley 
193420f4b53cSBarry Smith   Not Collective
1935b7e05686SMatthew G. Knepley 
1936b7e05686SMatthew G. Knepley   Input Parameters:
1937dce8aebaSBarry Smith + ds - The `PetscDS`
1938b7e05686SMatthew G. Knepley . f  - The test field number
1939b7e05686SMatthew G. Knepley . g  - The field number
1940b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1941b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1942b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1943b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1944b7e05686SMatthew G. Knepley 
194520f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
1946dce8aebaSBarry Smith .vb
194720f4b53cSBarry Smith    void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1948dce8aebaSBarry Smith            const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1949dce8aebaSBarry Smith            const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1950dce8aebaSBarry Smith            PetscReal t, const PetscReal x[], PetscScalar g0[])
1951dce8aebaSBarry Smith .ve
1952b7e05686SMatthew G. Knepley + dim - the spatial dimension
1953b7e05686SMatthew G. Knepley . Nf - the number of fields
1954b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1955b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1956b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1957b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1958b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1959b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1960b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1961b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1962b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1963b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1964b7e05686SMatthew G. Knepley . t - current time
1965b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1966b7e05686SMatthew G. Knepley . x - coordinates of the current point
196797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
196897b6e6e8SMatthew G. Knepley . constants - constant parameters
1969b7e05686SMatthew G. Knepley - g0 - output values at the current point
1970b7e05686SMatthew G. Knepley 
1971b7e05686SMatthew G. Knepley   Level: intermediate
1972b7e05686SMatthew G. Knepley 
1973dce8aebaSBarry Smith   Note:
1974dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
1975dce8aebaSBarry 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
1976dce8aebaSBarry Smith 
1977dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobian()`
1978b7e05686SMatthew G. Knepley @*/
1979d71ae5a4SJacob 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[]))
1980d71ae5a4SJacob Faibussowitsch {
1981b7e05686SMatthew G. Knepley   PetscFunctionBegin;
19826528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
1983b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1984b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1985b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1986b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
198763a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
198863a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
19899566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
19903ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
1991b7e05686SMatthew G. Knepley }
1992b7e05686SMatthew G. Knepley 
19930c2f2876SMatthew G. Knepley /*@C
19940c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
19950c2f2876SMatthew G. Knepley 
199620f4b53cSBarry Smith   Not Collective
19970c2f2876SMatthew G. Knepley 
19984165533cSJose E. Roman   Input Parameters:
1999dce8aebaSBarry Smith + ds - The `PetscDS` object
20000c2f2876SMatthew G. Knepley - f  - The field number
20010c2f2876SMatthew G. Knepley 
20024165533cSJose E. Roman   Output Parameter:
20030c2f2876SMatthew G. Knepley . r    - Riemann solver
20040c2f2876SMatthew G. Knepley 
200520f4b53cSBarry Smith   Calling sequence of `r`:
2006dce8aebaSBarry Smith .vb
200720f4b53cSBarry Smith   void r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
2008dce8aebaSBarry Smith .ve
20095db36cf9SMatthew G. Knepley + dim  - The spatial dimension
20105db36cf9SMatthew G. Knepley . Nf   - The number of fields
20115db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
20120c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
20130c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
20140c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
20150c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
201697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
201797b6e6e8SMatthew G. Knepley . constants - constant parameters
20180c2f2876SMatthew G. Knepley - ctx  - optional user context
20190c2f2876SMatthew G. Knepley 
20200c2f2876SMatthew G. Knepley   Level: intermediate
20210c2f2876SMatthew G. Knepley 
2022dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetRiemannSolver()`
20230c2f2876SMatthew G. Knepley @*/
2024d71ae5a4SJacob 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))
2025d71ae5a4SJacob Faibussowitsch {
20266528b96dSMatthew G. Knepley   PetscRiemannFunc *tmp;
20276528b96dSMatthew G. Knepley   PetscInt          n;
20286528b96dSMatthew G. Knepley 
20290c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20306528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
20310c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
203263a3b9bcSJacob 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);
20339566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, 0, &n, &tmp));
20346528b96dSMatthew G. Knepley   *r = tmp ? tmp[0] : NULL;
20353ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
20360c2f2876SMatthew G. Knepley }
20370c2f2876SMatthew G. Knepley 
20380c2f2876SMatthew G. Knepley /*@C
20390c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
20400c2f2876SMatthew G. Knepley 
204120f4b53cSBarry Smith   Not Collective
20420c2f2876SMatthew G. Knepley 
20434165533cSJose E. Roman   Input Parameters:
2044dce8aebaSBarry Smith + ds - The `PetscDS` object
20450c2f2876SMatthew G. Knepley . f  - The field number
20460c2f2876SMatthew G. Knepley - r  - Riemann solver
20470c2f2876SMatthew G. Knepley 
204820f4b53cSBarry Smith   Calling sequence of `r`:
2049dce8aebaSBarry Smith .vb
205020f4b53cSBarry Smith    void r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
2051dce8aebaSBarry Smith .ve
20525db36cf9SMatthew G. Knepley + dim  - The spatial dimension
20535db36cf9SMatthew G. Knepley . Nf   - The number of fields
20545db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
20550c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
20560c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
20570c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
20580c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
205997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
206097b6e6e8SMatthew G. Knepley . constants - constant parameters
20610c2f2876SMatthew G. Knepley - ctx  - optional user context
20620c2f2876SMatthew G. Knepley 
20630c2f2876SMatthew G. Knepley   Level: intermediate
20640c2f2876SMatthew G. Knepley 
2065dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetRiemannSolver()`
20660c2f2876SMatthew G. Knepley @*/
2067d71ae5a4SJacob 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))
2068d71ae5a4SJacob Faibussowitsch {
20690c2f2876SMatthew G. Knepley   PetscFunctionBegin;
20706528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2071de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
207263a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
20739566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, 0, r));
20743ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
20750c2f2876SMatthew G. Knepley }
20760c2f2876SMatthew G. Knepley 
207732d2bbc9SMatthew G. Knepley /*@C
207832d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
207932d2bbc9SMatthew G. Knepley 
208020f4b53cSBarry Smith   Not Collective
208132d2bbc9SMatthew G. Knepley 
208232d2bbc9SMatthew G. Knepley   Input Parameters:
2083dce8aebaSBarry Smith + ds - The `PetscDS`
208432d2bbc9SMatthew G. Knepley - f  - The field number
208532d2bbc9SMatthew G. Knepley 
2086f899ff85SJose E. Roman   Output Parameter:
2087a2b725a8SWilliam Gropp . update - update function
208832d2bbc9SMatthew G. Knepley 
208920f4b53cSBarry Smith   Calling sequence of `update`:
2090dce8aebaSBarry Smith .vb
209120f4b53cSBarry Smith   void update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2092dce8aebaSBarry Smith               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2093dce8aebaSBarry Smith               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2094dce8aebaSBarry Smith               PetscReal t, const PetscReal x[], PetscScalar uNew[])
2095dce8aebaSBarry Smith .ve
209632d2bbc9SMatthew G. Knepley + dim - the spatial dimension
209732d2bbc9SMatthew G. Knepley . Nf - the number of fields
209832d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
209932d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
210032d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
210132d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
210232d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
210332d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
210432d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
210532d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
210632d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
210732d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
210832d2bbc9SMatthew G. Knepley . t - current time
210932d2bbc9SMatthew G. Knepley . x - coordinates of the current point
211032d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
211132d2bbc9SMatthew G. Knepley 
211232d2bbc9SMatthew G. Knepley   Level: intermediate
211332d2bbc9SMatthew G. Knepley 
2114dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetUpdate()`, `PetscDSSetResidual()`
211532d2bbc9SMatthew G. Knepley @*/
2116d71ae5a4SJacob 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[]))
2117d71ae5a4SJacob Faibussowitsch {
211832d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
21196528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
212063a3b9bcSJacob 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);
21219371c9d4SSatish Balay   if (update) {
21229371c9d4SSatish Balay     PetscValidPointer(update, 3);
21239371c9d4SSatish Balay     *update = ds->update[f];
21249371c9d4SSatish Balay   }
21253ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
212632d2bbc9SMatthew G. Knepley }
212732d2bbc9SMatthew G. Knepley 
212832d2bbc9SMatthew G. Knepley /*@C
21293fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
213032d2bbc9SMatthew G. Knepley 
213120f4b53cSBarry Smith   Not Collective
213232d2bbc9SMatthew G. Knepley 
213332d2bbc9SMatthew G. Knepley   Input Parameters:
2134dce8aebaSBarry Smith + ds     - The `PetscDS`
213532d2bbc9SMatthew G. Knepley . f      - The field number
213632d2bbc9SMatthew G. Knepley - update - update function
213732d2bbc9SMatthew G. Knepley 
213820f4b53cSBarry Smith   Calling sequence of `update`:
2139dce8aebaSBarry Smith .vb
214020f4b53cSBarry Smith   void update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2141dce8aebaSBarry Smith               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2142dce8aebaSBarry Smith               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2143dce8aebaSBarry Smith               PetscReal t, const PetscReal x[], PetscScalar uNew[])
2144dce8aebaSBarry Smith .ve
214532d2bbc9SMatthew G. Knepley + dim - the spatial dimension
214632d2bbc9SMatthew G. Knepley . Nf - the number of fields
214732d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
214832d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
214932d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
215032d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
215132d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
215232d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
215332d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
215432d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
215532d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
215632d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
215732d2bbc9SMatthew G. Knepley . t - current time
215832d2bbc9SMatthew G. Knepley . x - coordinates of the current point
215932d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
216032d2bbc9SMatthew G. Knepley 
216132d2bbc9SMatthew G. Knepley   Level: intermediate
216232d2bbc9SMatthew G. Knepley 
2163dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetResidual()`
216432d2bbc9SMatthew G. Knepley @*/
2165d71ae5a4SJacob 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[]))
2166d71ae5a4SJacob Faibussowitsch {
216732d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
21686528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
216932d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
217063a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
21719566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(ds, f + 1));
21726528b96dSMatthew G. Knepley   ds->update[f] = update;
21733ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
217432d2bbc9SMatthew G. Knepley }
217532d2bbc9SMatthew G. Knepley 
2176d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void *ctx)
2177d71ae5a4SJacob Faibussowitsch {
21780c2f2876SMatthew G. Knepley   PetscFunctionBegin;
21796528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
218063a3b9bcSJacob 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);
21810c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
21823ec1f749SStefano Zampini   *(void **)ctx = ds->ctx[f];
21833ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
21840c2f2876SMatthew G. Knepley }
21850c2f2876SMatthew G. Knepley 
2186d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx)
2187d71ae5a4SJacob Faibussowitsch {
21880c2f2876SMatthew G. Knepley   PetscFunctionBegin;
21896528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
219063a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
21919566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(ds, f + 1));
21926528b96dSMatthew G. Knepley   ds->ctx[f] = ctx;
21933ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
21940c2f2876SMatthew G. Knepley }
21950c2f2876SMatthew G. Knepley 
2196194d53e6SMatthew G. Knepley /*@C
2197194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
2198194d53e6SMatthew G. Knepley 
219920f4b53cSBarry Smith   Not Collective
2200194d53e6SMatthew G. Knepley 
2201194d53e6SMatthew G. Knepley   Input Parameters:
22026528b96dSMatthew G. Knepley + ds - The PetscDS
2203194d53e6SMatthew G. Knepley - f  - The test field number
2204194d53e6SMatthew G. Knepley 
2205194d53e6SMatthew G. Knepley   Output Parameters:
2206194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
2207194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2208194d53e6SMatthew G. Knepley 
220920f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
2210dce8aebaSBarry Smith .vb
221120f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2212dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2213dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2214dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2215dce8aebaSBarry Smith .ve
2216194d53e6SMatthew G. Knepley + dim - the spatial dimension
2217194d53e6SMatthew G. Knepley . Nf - the number of fields
2218194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2219194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2220194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2221194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2222194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2223194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2224194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2225194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2226194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2227194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2228194d53e6SMatthew G. Knepley . t - current time
2229194d53e6SMatthew G. Knepley . x - coordinates of the current point
2230194d53e6SMatthew G. Knepley . n - unit normal at the current point
223197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
223297b6e6e8SMatthew G. Knepley . constants - constant parameters
2233194d53e6SMatthew G. Knepley - f0 - output values at the current point
2234194d53e6SMatthew G. Knepley 
2235194d53e6SMatthew G. Knepley   Level: intermediate
2236194d53e6SMatthew G. Knepley 
2237dce8aebaSBarry Smith   Note:
2238dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2239dce8aebaSBarry 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
2240dce8aebaSBarry Smith 
2241dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetBdResidual()`
2242194d53e6SMatthew G. Knepley @*/
2243d71ae5a4SJacob 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[]))
2244d71ae5a4SJacob Faibussowitsch {
22456528b96dSMatthew G. Knepley   PetscBdPointFunc *tmp0, *tmp1;
22466528b96dSMatthew G. Knepley   PetscInt          n0, n1;
22476528b96dSMatthew G. Knepley 
22482764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22496528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
225063a3b9bcSJacob 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);
22519566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1));
22526528b96dSMatthew G. Knepley   *f0 = tmp0 ? tmp0[0] : NULL;
22536528b96dSMatthew G. Knepley   *f1 = tmp1 ? tmp1[0] : NULL;
22543ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
22552764a2aaSMatthew G. Knepley }
22562764a2aaSMatthew G. Knepley 
2257194d53e6SMatthew G. Knepley /*@C
2258194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
2259194d53e6SMatthew G. Knepley 
226020f4b53cSBarry Smith   Not Collective
2261194d53e6SMatthew G. Knepley 
2262194d53e6SMatthew G. Knepley   Input Parameters:
2263dce8aebaSBarry Smith + ds - The `PetscDS`
2264194d53e6SMatthew G. Knepley . f  - The test field number
2265194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
2266194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
2267194d53e6SMatthew G. Knepley 
226820f4b53cSBarry Smith   Calling sequence of `f0` and `f1`:
2269dce8aebaSBarry Smith .vb
227020f4b53cSBarry Smith   void f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2271dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2272dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2273dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
2274dce8aebaSBarry Smith .ve
2275194d53e6SMatthew G. Knepley + dim - the spatial dimension
2276194d53e6SMatthew G. Knepley . Nf - the number of fields
2277194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2278194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2279194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2280194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2281194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2282194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2283194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2284194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2285194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2286194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2287194d53e6SMatthew G. Knepley . t - current time
2288194d53e6SMatthew G. Knepley . x - coordinates of the current point
2289194d53e6SMatthew G. Knepley . n - unit normal at the current point
229097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
229197b6e6e8SMatthew G. Knepley . constants - constant parameters
2292194d53e6SMatthew G. Knepley - f0 - output values at the current point
2293194d53e6SMatthew G. Knepley 
2294194d53e6SMatthew G. Knepley   Level: intermediate
2295194d53e6SMatthew G. Knepley 
2296dce8aebaSBarry Smith   Note:
2297dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2298dce8aebaSBarry 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
2299dce8aebaSBarry Smith 
2300dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetBdResidual()`
2301194d53e6SMatthew G. Knepley @*/
2302d71ae5a4SJacob 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[]))
2303d71ae5a4SJacob Faibussowitsch {
23042764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23056528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
230663a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
23079566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1));
23083ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
23092764a2aaSMatthew G. Knepley }
23102764a2aaSMatthew G. Knepley 
231127f02ce8SMatthew G. Knepley /*@
2312dce8aebaSBarry Smith   PetscDSHasBdJacobian - Indicates that boundary Jacobian functions have been set
231327f02ce8SMatthew G. Knepley 
231420f4b53cSBarry Smith   Not Collective
231527f02ce8SMatthew G. Knepley 
231627f02ce8SMatthew G. Knepley   Input Parameter:
2317dce8aebaSBarry Smith . ds - The `PetscDS`
231827f02ce8SMatthew G. Knepley 
231927f02ce8SMatthew G. Knepley   Output Parameter:
232027f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set
232127f02ce8SMatthew G. Knepley 
232227f02ce8SMatthew G. Knepley   Level: intermediate
232327f02ce8SMatthew G. Knepley 
2324dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()`
232527f02ce8SMatthew G. Knepley @*/
2326d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac)
2327d71ae5a4SJacob Faibussowitsch {
232827f02ce8SMatthew G. Knepley   PetscFunctionBegin;
23296528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
23306528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJac, 2);
23319566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasBdJacobian(ds->wf, hasBdJac));
23323ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
233327f02ce8SMatthew G. Knepley }
233427f02ce8SMatthew G. Knepley 
2335194d53e6SMatthew G. Knepley /*@C
2336194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
2337194d53e6SMatthew G. Knepley 
233820f4b53cSBarry Smith   Not Collective
2339194d53e6SMatthew G. Knepley 
2340194d53e6SMatthew G. Knepley   Input Parameters:
2341dce8aebaSBarry Smith + ds - The `PetscDS`
2342194d53e6SMatthew G. Knepley . f  - The test field number
2343194d53e6SMatthew G. Knepley - g  - The field number
2344194d53e6SMatthew G. Knepley 
2345194d53e6SMatthew G. Knepley   Output Parameters:
2346194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2347194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2348194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2349194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2350194d53e6SMatthew G. Knepley 
235120f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
2352dce8aebaSBarry Smith .vb
235320f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2354dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2355dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2356dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2357dce8aebaSBarry Smith .ve
2358194d53e6SMatthew G. Knepley + dim - the spatial dimension
2359194d53e6SMatthew G. Knepley . Nf - the number of fields
2360194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2361194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2362194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2363194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2364194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2365194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2366194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2367194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2368194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2369194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2370194d53e6SMatthew G. Knepley . t - current time
23712aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2372194d53e6SMatthew G. Knepley . x - coordinates of the current point
2373194d53e6SMatthew G. Knepley . n - normal at the current point
237497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
237597b6e6e8SMatthew G. Knepley . constants - constant parameters
2376194d53e6SMatthew G. Knepley - g0 - output values at the current point
2377194d53e6SMatthew G. Knepley 
2378194d53e6SMatthew G. Knepley   Level: intermediate
2379194d53e6SMatthew G. Knepley 
2380dce8aebaSBarry Smith   Note:
2381dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2382dce8aebaSBarry 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
2383dce8aebaSBarry Smith 
2384dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetBdJacobian()`
2385194d53e6SMatthew G. Knepley @*/
2386d71ae5a4SJacob 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[]))
2387d71ae5a4SJacob Faibussowitsch {
23886528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
23896528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
23906528b96dSMatthew G. Knepley 
23912764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23926528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
239363a3b9bcSJacob 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);
239463a3b9bcSJacob 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);
23959566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
23966528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
23976528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
23986528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
23996528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
24003ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
24012764a2aaSMatthew G. Knepley }
24022764a2aaSMatthew G. Knepley 
2403194d53e6SMatthew G. Knepley /*@C
2404194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2405194d53e6SMatthew G. Knepley 
240620f4b53cSBarry Smith   Not Collective
2407194d53e6SMatthew G. Knepley 
2408194d53e6SMatthew G. Knepley   Input Parameters:
24096528b96dSMatthew G. Knepley + ds - The PetscDS
2410194d53e6SMatthew G. Knepley . f  - The test field number
2411194d53e6SMatthew G. Knepley . g  - The field number
2412194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2413194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2414194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2415194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2416194d53e6SMatthew G. Knepley 
241720f4b53cSBarry Smith   Calling sequence of `g0`, `g1`, `g2` and `g3`:
2418dce8aebaSBarry Smith .vb
241920f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2420dce8aebaSBarry Smith        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2421dce8aebaSBarry Smith        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2422dce8aebaSBarry Smith        PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2423dce8aebaSBarry Smith .ve
2424194d53e6SMatthew G. Knepley + dim - the spatial dimension
2425194d53e6SMatthew G. Knepley . Nf - the number of fields
2426194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2427194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2428194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2429194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2430194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2431194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2432194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2433194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2434194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2435194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2436194d53e6SMatthew G. Knepley . t - current time
24372aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2438194d53e6SMatthew G. Knepley . x - coordinates of the current point
2439194d53e6SMatthew G. Knepley . n - normal at the current point
244097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
244197b6e6e8SMatthew G. Knepley . constants - constant parameters
2442194d53e6SMatthew G. Knepley - g0 - output values at the current point
2443194d53e6SMatthew G. Knepley 
2444194d53e6SMatthew G. Knepley   Level: intermediate
2445194d53e6SMatthew G. Knepley 
2446dce8aebaSBarry Smith   Note:
2447dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2448dce8aebaSBarry 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
2449dce8aebaSBarry Smith 
2450dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetBdJacobian()`
2451194d53e6SMatthew G. Knepley @*/
2452d71ae5a4SJacob 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[]))
2453d71ae5a4SJacob Faibussowitsch {
24542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24556528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24562764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
24572764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
24582764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
24592764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
246063a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
246163a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
24629566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
24633ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
24642764a2aaSMatthew G. Knepley }
24652764a2aaSMatthew G. Knepley 
246627f02ce8SMatthew G. Knepley /*@
246727f02ce8SMatthew G. Knepley   PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set
246827f02ce8SMatthew G. Knepley 
246920f4b53cSBarry Smith   Not Collective
247027f02ce8SMatthew G. Knepley 
247127f02ce8SMatthew G. Knepley   Input Parameter:
2472dce8aebaSBarry Smith . ds - The `PetscDS`
247327f02ce8SMatthew G. Knepley 
247427f02ce8SMatthew G. Knepley   Output Parameter:
247527f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set
247627f02ce8SMatthew G. Knepley 
247727f02ce8SMatthew G. Knepley   Level: intermediate
247827f02ce8SMatthew G. Knepley 
2479dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()`
248027f02ce8SMatthew G. Knepley @*/
2481d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre)
2482d71ae5a4SJacob Faibussowitsch {
248327f02ce8SMatthew G. Knepley   PetscFunctionBegin;
24846528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
24856528b96dSMatthew G. Knepley   PetscValidBoolPointer(hasBdJacPre, 2);
24869566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre));
24873ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
248827f02ce8SMatthew G. Knepley }
248927f02ce8SMatthew G. Knepley 
249027f02ce8SMatthew G. Knepley /*@C
249127f02ce8SMatthew G. Knepley   PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field
249227f02ce8SMatthew G. Knepley 
249320f4b53cSBarry Smith   Not Collective; No Fortran Support
249427f02ce8SMatthew G. Knepley 
249527f02ce8SMatthew G. Knepley   Input Parameters:
2496dce8aebaSBarry Smith + ds - The `PetscDS`
249727f02ce8SMatthew G. Knepley . f  - The test field number
249827f02ce8SMatthew G. Knepley - g  - The field number
249927f02ce8SMatthew G. Knepley 
250027f02ce8SMatthew G. Knepley   Output Parameters:
250127f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term
250227f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
250327f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
250427f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
250527f02ce8SMatthew G. Knepley 
250620f4b53cSBarry Smith    Calling sequence of `g0`, `g1`, `g2` and `g3`:
2507dce8aebaSBarry Smith .vb
250820f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2509dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2510dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2511dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
2512dce8aebaSBarry Smith .ve
251327f02ce8SMatthew G. Knepley + dim - the spatial dimension
251427f02ce8SMatthew G. Knepley . Nf - the number of fields
251527f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
251627f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
251727f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
251827f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
251927f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
252027f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
252127f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
252227f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
252327f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
252427f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
252527f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
252627f02ce8SMatthew G. Knepley . t - current time
252727f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
252827f02ce8SMatthew G. Knepley . x - coordinates of the current point
252927f02ce8SMatthew G. Knepley . n - normal at the current point
253027f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
253127f02ce8SMatthew G. Knepley . constants - constant parameters
253227f02ce8SMatthew G. Knepley - g0 - output values at the current point
253327f02ce8SMatthew G. Knepley 
253427f02ce8SMatthew G. Knepley   Level: intermediate
253527f02ce8SMatthew G. Knepley 
2536dce8aebaSBarry Smith   Note:
2537dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2538dce8aebaSBarry 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
2539dce8aebaSBarry Smith 
2540dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetBdJacobianPreconditioner()`
254127f02ce8SMatthew G. Knepley @*/
2542d71ae5a4SJacob 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[]))
2543d71ae5a4SJacob Faibussowitsch {
25446528b96dSMatthew G. Knepley   PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3;
25456528b96dSMatthew G. Knepley   PetscInt         n0, n1, n2, n3;
25466528b96dSMatthew G. Knepley 
254727f02ce8SMatthew G. Knepley   PetscFunctionBegin;
25486528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
254963a3b9bcSJacob 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);
255063a3b9bcSJacob 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);
25519566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3));
25526528b96dSMatthew G. Knepley   *g0 = tmp0 ? tmp0[0] : NULL;
25536528b96dSMatthew G. Knepley   *g1 = tmp1 ? tmp1[0] : NULL;
25546528b96dSMatthew G. Knepley   *g2 = tmp2 ? tmp2[0] : NULL;
25556528b96dSMatthew G. Knepley   *g3 = tmp3 ? tmp3[0] : NULL;
25563ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
255727f02ce8SMatthew G. Knepley }
255827f02ce8SMatthew G. Knepley 
255927f02ce8SMatthew G. Knepley /*@C
256027f02ce8SMatthew G. Knepley   PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field
256127f02ce8SMatthew G. Knepley 
256220f4b53cSBarry Smith   Not Collective; No Fortran Support
256327f02ce8SMatthew G. Knepley 
256427f02ce8SMatthew G. Knepley   Input Parameters:
2565dce8aebaSBarry Smith + ds - The `PetscDS`
256627f02ce8SMatthew G. Knepley . f  - The test field number
256727f02ce8SMatthew G. Knepley . g  - The field number
256827f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term
256927f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
257027f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
257127f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
257227f02ce8SMatthew G. Knepley 
257320f4b53cSBarry Smith    Calling sequence of `g0`, `g1`, `g2` and `g3`:
2574dce8aebaSBarry Smith .vb
257520f4b53cSBarry Smith   void g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2576dce8aebaSBarry Smith           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2577dce8aebaSBarry Smith           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
2578dce8aebaSBarry Smith           PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[])
2579dce8aebaSBarry Smith .ve
258027f02ce8SMatthew G. Knepley + dim - the spatial dimension
258127f02ce8SMatthew G. Knepley . Nf - the number of fields
258227f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields
258327f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
258427f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
258527f02ce8SMatthew G. Knepley . u - each field evaluated at the current point
258627f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
258727f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
258827f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
258927f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
259027f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
259127f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
259227f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
259327f02ce8SMatthew G. Knepley . t - current time
259427f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
259527f02ce8SMatthew G. Knepley . x - coordinates of the current point
259627f02ce8SMatthew G. Knepley . n - normal at the current point
259727f02ce8SMatthew G. Knepley . numConstants - number of constant parameters
259827f02ce8SMatthew G. Knepley . constants - constant parameters
259927f02ce8SMatthew G. Knepley - g0 - output values at the current point
260027f02ce8SMatthew G. Knepley 
260127f02ce8SMatthew G. Knepley   Level: intermediate
260227f02ce8SMatthew G. Knepley 
2603dce8aebaSBarry Smith   Note:
2604dce8aebaSBarry Smith   We are using a first order FEM model for the weak form:
2605dce8aebaSBarry 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
2606dce8aebaSBarry Smith 
2607dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetBdJacobianPreconditioner()`
260827f02ce8SMatthew G. Knepley @*/
2609d71ae5a4SJacob 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[]))
2610d71ae5a4SJacob Faibussowitsch {
261127f02ce8SMatthew G. Knepley   PetscFunctionBegin;
26126528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
261327f02ce8SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
261427f02ce8SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
261527f02ce8SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
261627f02ce8SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
261763a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
261863a3b9bcSJacob Faibussowitsch   PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g);
26199566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3));
26203ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
262127f02ce8SMatthew G. Knepley }
262227f02ce8SMatthew G. Knepley 
26230d3e9b51SMatthew G. Knepley /*@C
2624c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2625c371a6d1SMatthew G. Knepley 
262620f4b53cSBarry Smith   Not Collective
2627c371a6d1SMatthew G. Knepley 
2628c371a6d1SMatthew G. Knepley   Input Parameters:
2629c371a6d1SMatthew G. Knepley + prob - The PetscDS
2630c371a6d1SMatthew G. Knepley - f    - The test field number
2631c371a6d1SMatthew G. Knepley 
2632d8d19677SJose E. Roman   Output Parameters:
263395cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field
263495cbbfd3SMatthew G. Knepley - exactCtx - exact solution context
2635c371a6d1SMatthew G. Knepley 
263620f4b53cSBarry Smith   Calling sequence of `exactSol`:
2637dce8aebaSBarry Smith .vb
263820f4b53cSBarry Smith   PetscErrorCode sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2639dce8aebaSBarry Smith .ve
2640c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2641c371a6d1SMatthew G. Knepley . t - current time
2642c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2643c371a6d1SMatthew G. Knepley . Nc - the number of field components
2644c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2645c371a6d1SMatthew G. Knepley - ctx - a user context
2646c371a6d1SMatthew G. Knepley 
2647c371a6d1SMatthew G. Knepley   Level: intermediate
2648c371a6d1SMatthew G. Knepley 
2649dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetExactSolution()`, `PetscDSGetExactSolutionTimeDerivative()`
2650c371a6d1SMatthew G. Knepley @*/
2651d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2652d71ae5a4SJacob Faibussowitsch {
2653c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2654c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
265563a3b9bcSJacob 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);
26569371c9d4SSatish Balay   if (sol) {
26579371c9d4SSatish Balay     PetscValidPointer(sol, 3);
26589371c9d4SSatish Balay     *sol = prob->exactSol[f];
26599371c9d4SSatish Balay   }
26609371c9d4SSatish Balay   if (ctx) {
26619371c9d4SSatish Balay     PetscValidPointer(ctx, 4);
26629371c9d4SSatish Balay     *ctx = prob->exactCtx[f];
26639371c9d4SSatish Balay   }
26643ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2665c371a6d1SMatthew G. Knepley }
2666c371a6d1SMatthew G. Knepley 
2667c371a6d1SMatthew G. Knepley /*@C
2668578a5ef5SMatthew Knepley   PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field
2669c371a6d1SMatthew G. Knepley 
267020f4b53cSBarry Smith   Not Collective
2671c371a6d1SMatthew G. Knepley 
2672c371a6d1SMatthew G. Knepley   Input Parameters:
2673dce8aebaSBarry Smith + prob - The `PetscDS`
2674c371a6d1SMatthew G. Knepley . f    - The test field number
267595cbbfd3SMatthew G. Knepley . sol  - solution function for the test fields
267620f4b53cSBarry Smith - ctx  - solution context or `NULL`
2677c371a6d1SMatthew G. Knepley 
267820f4b53cSBarry Smith   Calling sequence of `sol`:
2679dce8aebaSBarry Smith .vb
268020f4b53cSBarry Smith   PetscErrorCode sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2681dce8aebaSBarry Smith .ve
2682c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2683c371a6d1SMatthew G. Knepley . t - current time
2684c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2685c371a6d1SMatthew G. Knepley . Nc - the number of field components
2686c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2687c371a6d1SMatthew G. Knepley - ctx - a user context
2688c371a6d1SMatthew G. Knepley 
2689c371a6d1SMatthew G. Knepley   Level: intermediate
2690c371a6d1SMatthew G. Knepley 
2691dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetExactSolution()`
2692c371a6d1SMatthew G. Knepley @*/
2693d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2694d71ae5a4SJacob Faibussowitsch {
2695c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2696c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
269763a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
26989566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(prob, f + 1));
26999371c9d4SSatish Balay   if (sol) {
27009371c9d4SSatish Balay     PetscValidFunction(sol, 3);
27019371c9d4SSatish Balay     prob->exactSol[f] = sol;
27029371c9d4SSatish Balay   }
27039371c9d4SSatish Balay   if (ctx) {
27049371c9d4SSatish Balay     PetscValidFunction(ctx, 4);
27059371c9d4SSatish Balay     prob->exactCtx[f] = ctx;
27069371c9d4SSatish Balay   }
27073ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2708c371a6d1SMatthew G. Knepley }
2709c371a6d1SMatthew G. Knepley 
27105638fd0eSMatthew G. Knepley /*@C
2711f2cacb80SMatthew G. Knepley   PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field
2712f2cacb80SMatthew G. Knepley 
271320f4b53cSBarry Smith   Not Collective
2714f2cacb80SMatthew G. Knepley 
2715f2cacb80SMatthew G. Knepley   Input Parameters:
2716dce8aebaSBarry Smith + prob - The `PetscDS`
2717f2cacb80SMatthew G. Knepley - f    - The test field number
2718f2cacb80SMatthew G. Knepley 
2719d8d19677SJose E. Roman   Output Parameters:
2720f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field
2721f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context
2722f2cacb80SMatthew G. Knepley 
272320f4b53cSBarry Smith   Calling sequence of `exactSol`:
2724dce8aebaSBarry Smith .vb
272520f4b53cSBarry Smith   PetscErrorCode sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2726dce8aebaSBarry Smith .ve
2727f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2728f2cacb80SMatthew G. Knepley . t - current time
2729f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2730f2cacb80SMatthew G. Knepley . Nc - the number of field components
2731f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2732f2cacb80SMatthew G. Knepley - ctx - a user context
2733f2cacb80SMatthew G. Knepley 
2734f2cacb80SMatthew G. Knepley   Level: intermediate
2735f2cacb80SMatthew G. Knepley 
2736dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetExactSolutionTimeDerivative()`, `PetscDSGetExactSolution()`
2737f2cacb80SMatthew G. Knepley @*/
2738d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx)
2739d71ae5a4SJacob Faibussowitsch {
2740f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2741f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
274263a3b9bcSJacob 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);
27439371c9d4SSatish Balay   if (sol) {
27449371c9d4SSatish Balay     PetscValidPointer(sol, 3);
27459371c9d4SSatish Balay     *sol = prob->exactSol_t[f];
27469371c9d4SSatish Balay   }
27479371c9d4SSatish Balay   if (ctx) {
27489371c9d4SSatish Balay     PetscValidPointer(ctx, 4);
27499371c9d4SSatish Balay     *ctx = prob->exactCtx_t[f];
27509371c9d4SSatish Balay   }
27513ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2752f2cacb80SMatthew G. Knepley }
2753f2cacb80SMatthew G. Knepley 
2754f2cacb80SMatthew G. Knepley /*@C
2755f2cacb80SMatthew G. Knepley   PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field
2756f2cacb80SMatthew G. Knepley 
275720f4b53cSBarry Smith   Not Collective
2758f2cacb80SMatthew G. Knepley 
2759f2cacb80SMatthew G. Knepley   Input Parameters:
2760dce8aebaSBarry Smith + prob - The `PetscDS`
2761f2cacb80SMatthew G. Knepley . f    - The test field number
2762f2cacb80SMatthew G. Knepley . sol  - time derivative of the solution function for the test fields
276320f4b53cSBarry Smith - ctx  - time derivative of the solution context or `NULL`
2764f2cacb80SMatthew G. Knepley 
276520f4b53cSBarry Smith   Calling sequence of `sol`:
2766dce8aebaSBarry Smith .vb
276720f4b53cSBarry Smith   PetscErrorCode sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2768dce8aebaSBarry Smith .ve
2769f2cacb80SMatthew G. Knepley + dim - the spatial dimension
2770f2cacb80SMatthew G. Knepley . t - current time
2771f2cacb80SMatthew G. Knepley . x - coordinates of the current point
2772f2cacb80SMatthew G. Knepley . Nc - the number of field components
2773f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point
2774f2cacb80SMatthew G. Knepley - ctx - a user context
2775f2cacb80SMatthew G. Knepley 
2776f2cacb80SMatthew G. Knepley   Level: intermediate
2777f2cacb80SMatthew G. Knepley 
2778dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetExactSolutionTimeDerivative()`, `PetscDSSetExactSolution()`
2779f2cacb80SMatthew G. Knepley @*/
2780d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx)
2781d71ae5a4SJacob Faibussowitsch {
2782f2cacb80SMatthew G. Knepley   PetscFunctionBegin;
2783f2cacb80SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
278463a3b9bcSJacob Faibussowitsch   PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f);
27859566063dSJacob Faibussowitsch   PetscCall(PetscDSEnlarge_Static(prob, f + 1));
27869371c9d4SSatish Balay   if (sol) {
27879371c9d4SSatish Balay     PetscValidFunction(sol, 3);
27889371c9d4SSatish Balay     prob->exactSol_t[f] = sol;
27899371c9d4SSatish Balay   }
27909371c9d4SSatish Balay   if (ctx) {
27919371c9d4SSatish Balay     PetscValidFunction(ctx, 4);
27929371c9d4SSatish Balay     prob->exactCtx_t[f] = ctx;
27939371c9d4SSatish Balay   }
27943ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
2795f2cacb80SMatthew G. Knepley }
2796f2cacb80SMatthew G. Knepley 
2797f2cacb80SMatthew G. Knepley /*@C
279897b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
279997b6e6e8SMatthew G. Knepley 
280020f4b53cSBarry Smith   Not Collective
280197b6e6e8SMatthew G. Knepley 
280297b6e6e8SMatthew G. Knepley   Input Parameter:
2803dce8aebaSBarry Smith . prob - The `PetscDS` object
280497b6e6e8SMatthew G. Knepley 
280597b6e6e8SMatthew G. Knepley   Output Parameters:
280697b6e6e8SMatthew G. Knepley + numConstants - The number of constants
280797b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
280897b6e6e8SMatthew G. Knepley 
280997b6e6e8SMatthew G. Knepley   Level: intermediate
281097b6e6e8SMatthew G. Knepley 
2811dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetConstants()`, `PetscDSCreate()`
281297b6e6e8SMatthew G. Knepley @*/
2813d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
2814d71ae5a4SJacob Faibussowitsch {
281597b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
281697b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28179371c9d4SSatish Balay   if (numConstants) {
28189371c9d4SSatish Balay     PetscValidIntPointer(numConstants, 2);
28199371c9d4SSatish Balay     *numConstants = prob->numConstants;
28209371c9d4SSatish Balay   }
28219371c9d4SSatish Balay   if (constants) {
28229371c9d4SSatish Balay     PetscValidPointer(constants, 3);
28239371c9d4SSatish Balay     *constants = prob->constants;
28249371c9d4SSatish Balay   }
28253ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
282697b6e6e8SMatthew G. Knepley }
282797b6e6e8SMatthew G. Knepley 
28280d3e9b51SMatthew G. Knepley /*@C
282997b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
283097b6e6e8SMatthew G. Knepley 
283120f4b53cSBarry Smith   Not Collective
283297b6e6e8SMatthew G. Knepley 
283397b6e6e8SMatthew G. Knepley   Input Parameters:
2834dce8aebaSBarry Smith + prob         - The `PetscDS` object
283597b6e6e8SMatthew G. Knepley . numConstants - The number of constants
283697b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
283797b6e6e8SMatthew G. Knepley 
283897b6e6e8SMatthew G. Knepley   Level: intermediate
283997b6e6e8SMatthew G. Knepley 
2840dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetConstants()`, `PetscDSCreate()`
284197b6e6e8SMatthew G. Knepley @*/
2842d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
2843d71ae5a4SJacob Faibussowitsch {
284497b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
284597b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
284697b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
28479566063dSJacob Faibussowitsch     PetscCall(PetscFree(prob->constants));
284897b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
284997b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
28509566063dSJacob Faibussowitsch       PetscCall(PetscMalloc1(prob->numConstants, &prob->constants));
285120be0f5bSMatthew G. Knepley     } else {
285220be0f5bSMatthew G. Knepley       prob->constants = NULL;
285320be0f5bSMatthew G. Knepley     }
285420be0f5bSMatthew G. Knepley   }
285520be0f5bSMatthew G. Knepley   if (prob->numConstants) {
2856dadcf809SJacob Faibussowitsch     PetscValidScalarPointer(constants, 3);
28579566063dSJacob Faibussowitsch     PetscCall(PetscArraycpy(prob->constants, constants, prob->numConstants));
285897b6e6e8SMatthew G. Knepley   }
28593ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
286097b6e6e8SMatthew G. Knepley }
286197b6e6e8SMatthew G. Knepley 
28624cd1e086SMatthew G. Knepley /*@
28634cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
28644cd1e086SMatthew G. Knepley 
286520f4b53cSBarry Smith   Not Collective
28664cd1e086SMatthew G. Knepley 
28674cd1e086SMatthew G. Knepley   Input Parameters:
2868dce8aebaSBarry Smith + prob - The `PetscDS` object
28694cd1e086SMatthew G. Knepley - disc - The discretization object
28704cd1e086SMatthew G. Knepley 
28714cd1e086SMatthew G. Knepley   Output Parameter:
28724cd1e086SMatthew G. Knepley . f - The field number
28734cd1e086SMatthew G. Knepley 
28744cd1e086SMatthew G. Knepley   Level: beginner
28754cd1e086SMatthew G. Knepley 
2876dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscGetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
28774cd1e086SMatthew G. Knepley @*/
2878d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
2879d71ae5a4SJacob Faibussowitsch {
28804cd1e086SMatthew G. Knepley   PetscInt g;
28814cd1e086SMatthew G. Knepley 
28824cd1e086SMatthew G. Knepley   PetscFunctionBegin;
28834cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2884dadcf809SJacob Faibussowitsch   PetscValidIntPointer(f, 3);
28854cd1e086SMatthew G. Knepley   *f = -1;
28869371c9d4SSatish Balay   for (g = 0; g < prob->Nf; ++g) {
28879371c9d4SSatish Balay     if (disc == prob->disc[g]) break;
28889371c9d4SSatish Balay   }
288908401ef6SPierre Jolivet   PetscCheck(g != prob->Nf, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
28904cd1e086SMatthew G. Knepley   *f = g;
28913ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
28924cd1e086SMatthew G. Knepley }
28934cd1e086SMatthew G. Knepley 
28944cd1e086SMatthew G. Knepley /*@
28954cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
28964cd1e086SMatthew G. Knepley 
289720f4b53cSBarry Smith   Not Collective
28984cd1e086SMatthew G. Knepley 
28994cd1e086SMatthew G. Knepley   Input Parameters:
2900dce8aebaSBarry Smith + prob - The `PetscDS` object
29014cd1e086SMatthew G. Knepley - f - The field number
29024cd1e086SMatthew G. Knepley 
29034cd1e086SMatthew G. Knepley   Output Parameter:
29044cd1e086SMatthew G. Knepley . size - The size
29054cd1e086SMatthew G. Knepley 
29064cd1e086SMatthew G. Knepley   Level: beginner
29074cd1e086SMatthew G. Knepley 
2908dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetFieldOffset()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
29094cd1e086SMatthew G. Knepley @*/
2910d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
2911d71ae5a4SJacob Faibussowitsch {
29124cd1e086SMatthew G. Knepley   PetscFunctionBegin;
29134cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2914dadcf809SJacob Faibussowitsch   PetscValidIntPointer(size, 3);
291563a3b9bcSJacob 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);
29169566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
2917d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
29183ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
29194cd1e086SMatthew G. Knepley }
29204cd1e086SMatthew G. Knepley 
2921bc4ae4beSMatthew G. Knepley /*@
2922bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2923bc4ae4beSMatthew G. Knepley 
292420f4b53cSBarry Smith   Not Collective
2925bc4ae4beSMatthew G. Knepley 
2926bc4ae4beSMatthew G. Knepley   Input Parameters:
2927dce8aebaSBarry Smith + prob - The `PetscDS` object
2928bc4ae4beSMatthew G. Knepley - f - The field number
2929bc4ae4beSMatthew G. Knepley 
2930bc4ae4beSMatthew G. Knepley   Output Parameter:
2931bc4ae4beSMatthew G. Knepley . off - The offset
2932bc4ae4beSMatthew G. Knepley 
2933bc4ae4beSMatthew G. Knepley   Level: beginner
2934bc4ae4beSMatthew G. Knepley 
2935dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
2936bc4ae4beSMatthew G. Knepley @*/
2937d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
2938d71ae5a4SJacob Faibussowitsch {
29394cd1e086SMatthew G. Knepley   PetscInt size, g;
29402764a2aaSMatthew G. Knepley 
29412764a2aaSMatthew G. Knepley   PetscFunctionBegin;
29422764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2943dadcf809SJacob Faibussowitsch   PetscValidIntPointer(off, 3);
294463a3b9bcSJacob 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);
29452764a2aaSMatthew G. Knepley   *off = 0;
29462764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
29479566063dSJacob Faibussowitsch     PetscCall(PetscDSGetFieldSize(prob, g, &size));
29484cd1e086SMatthew G. Knepley     *off += size;
29492764a2aaSMatthew G. Knepley   }
29503ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
29512764a2aaSMatthew G. Knepley }
29522764a2aaSMatthew G. Knepley 
2953bc4ae4beSMatthew G. Knepley /*@
29545fedec97SMatthew G. Knepley   PetscDSGetFieldOffsetCohesive - Returns the offset of the given field in the full space basis on a cohesive cell
29555fedec97SMatthew G. Knepley 
295620f4b53cSBarry Smith   Not Collective
29575fedec97SMatthew G. Knepley 
29585fedec97SMatthew G. Knepley   Input Parameters:
2959dce8aebaSBarry Smith + prob - The `PetscDS` object
29605fedec97SMatthew G. Knepley - f - The field number
29615fedec97SMatthew G. Knepley 
29625fedec97SMatthew G. Knepley   Output Parameter:
29635fedec97SMatthew G. Knepley . off - The offset
29645fedec97SMatthew G. Knepley 
29655fedec97SMatthew G. Knepley   Level: beginner
29665fedec97SMatthew G. Knepley 
2967dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
29685fedec97SMatthew G. Knepley @*/
2969d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldOffsetCohesive(PetscDS ds, PetscInt f, PetscInt *off)
2970d71ae5a4SJacob Faibussowitsch {
29715fedec97SMatthew G. Knepley   PetscInt size, g;
29725fedec97SMatthew G. Knepley 
29735fedec97SMatthew G. Knepley   PetscFunctionBegin;
29745fedec97SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
2975dadcf809SJacob Faibussowitsch   PetscValidIntPointer(off, 3);
297663a3b9bcSJacob 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);
29775fedec97SMatthew G. Knepley   *off = 0;
29785fedec97SMatthew G. Knepley   for (g = 0; g < f; ++g) {
29795fedec97SMatthew G. Knepley     PetscBool cohesive;
29805fedec97SMatthew G. Knepley 
29819566063dSJacob Faibussowitsch     PetscCall(PetscDSGetCohesive(ds, g, &cohesive));
29829566063dSJacob Faibussowitsch     PetscCall(PetscDSGetFieldSize(ds, g, &size));
29835fedec97SMatthew G. Knepley     *off += cohesive ? size : size * 2;
29845fedec97SMatthew G. Knepley   }
29853ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
29865fedec97SMatthew G. Knepley }
29875fedec97SMatthew G. Knepley 
29885fedec97SMatthew G. Knepley /*@
298947e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2990bc4ae4beSMatthew G. Knepley 
299120f4b53cSBarry Smith   Not Collective
2992bc4ae4beSMatthew G. Knepley 
299347e57110SSander Arens   Input Parameter:
2994dce8aebaSBarry Smith . prob - The `PetscDS` object
2995bc4ae4beSMatthew G. Knepley 
2996bc4ae4beSMatthew G. Knepley   Output Parameter:
299747e57110SSander Arens . dimensions - The number of dimensions
2998bc4ae4beSMatthew G. Knepley 
2999bc4ae4beSMatthew G. Knepley   Level: beginner
3000bc4ae4beSMatthew G. Knepley 
3001dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
3002bc4ae4beSMatthew G. Knepley @*/
3003d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
3004d71ae5a4SJacob Faibussowitsch {
30052764a2aaSMatthew G. Knepley   PetscFunctionBegin;
30062764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30079566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
300847e57110SSander Arens   PetscValidPointer(dimensions, 2);
300947e57110SSander Arens   *dimensions = prob->Nb;
30103ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
30116ce16762SMatthew G. Knepley }
301247e57110SSander Arens 
301347e57110SSander Arens /*@
301447e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
301547e57110SSander Arens 
301620f4b53cSBarry Smith   Not Collective
301747e57110SSander Arens 
301847e57110SSander Arens   Input Parameter:
3019dce8aebaSBarry Smith . prob - The `PetscDS` object
302047e57110SSander Arens 
302147e57110SSander Arens   Output Parameter:
302247e57110SSander Arens . components - The number of components
302347e57110SSander Arens 
302447e57110SSander Arens   Level: beginner
302547e57110SSander Arens 
3026dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()`
302747e57110SSander Arens @*/
3028d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
3029d71ae5a4SJacob Faibussowitsch {
303047e57110SSander Arens   PetscFunctionBegin;
303147e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30329566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
303347e57110SSander Arens   PetscValidPointer(components, 2);
303447e57110SSander Arens   *components = prob->Nc;
30353ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
30366ce16762SMatthew G. Knepley }
30376ce16762SMatthew G. Knepley 
30386ce16762SMatthew G. Knepley /*@
30396ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
30406ce16762SMatthew G. Knepley 
304120f4b53cSBarry Smith   Not Collective
30426ce16762SMatthew G. Knepley 
30436ce16762SMatthew G. Knepley   Input Parameters:
3044dce8aebaSBarry Smith + prob - The `PetscDS` object
30456ce16762SMatthew G. Knepley - f - The field number
30466ce16762SMatthew G. Knepley 
30476ce16762SMatthew G. Knepley   Output Parameter:
30486ce16762SMatthew G. Knepley . off - The offset
30496ce16762SMatthew G. Knepley 
30506ce16762SMatthew G. Knepley   Level: beginner
30516ce16762SMatthew G. Knepley 
3052dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
30536ce16762SMatthew G. Knepley @*/
3054d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
3055d71ae5a4SJacob Faibussowitsch {
30566ce16762SMatthew G. Knepley   PetscFunctionBegin;
30576ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3058dadcf809SJacob Faibussowitsch   PetscValidIntPointer(off, 3);
305963a3b9bcSJacob 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);
30609566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
306147e57110SSander Arens   *off = prob->off[f];
30623ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
30632764a2aaSMatthew G. Knepley }
30642764a2aaSMatthew G. Knepley 
3065194d53e6SMatthew G. Knepley /*@
3066194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
3067194d53e6SMatthew G. Knepley 
306820f4b53cSBarry Smith   Not Collective
3069194d53e6SMatthew G. Knepley 
3070194d53e6SMatthew G. Knepley   Input Parameter:
3071dce8aebaSBarry Smith . prob - The `PetscDS` object
3072194d53e6SMatthew G. Knepley 
3073194d53e6SMatthew G. Knepley   Output Parameter:
3074194d53e6SMatthew G. Knepley . offsets - The offsets
3075194d53e6SMatthew G. Knepley 
3076194d53e6SMatthew G. Knepley   Level: beginner
3077194d53e6SMatthew G. Knepley 
3078dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
3079194d53e6SMatthew G. Knepley @*/
3080d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
3081d71ae5a4SJacob Faibussowitsch {
3082194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3083194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3084194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
30859566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3086194d53e6SMatthew G. Knepley   *offsets = prob->off;
30873ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3088194d53e6SMatthew G. Knepley }
3089194d53e6SMatthew G. Knepley 
3090194d53e6SMatthew G. Knepley /*@
3091194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
3092194d53e6SMatthew G. Knepley 
309320f4b53cSBarry Smith   Not Collective
3094194d53e6SMatthew G. Knepley 
3095194d53e6SMatthew G. Knepley   Input Parameter:
3096dce8aebaSBarry Smith . prob - The `PetscDS` object
3097194d53e6SMatthew G. Knepley 
3098194d53e6SMatthew G. Knepley   Output Parameter:
3099194d53e6SMatthew G. Knepley . offsets - The offsets
3100194d53e6SMatthew G. Knepley 
3101194d53e6SMatthew G. Knepley   Level: beginner
3102194d53e6SMatthew G. Knepley 
3103dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
3104194d53e6SMatthew G. Knepley @*/
3105d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
3106d71ae5a4SJacob Faibussowitsch {
3107194d53e6SMatthew G. Knepley   PetscFunctionBegin;
3108194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3109194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
31109566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3111194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
31123ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3113194d53e6SMatthew G. Knepley }
3114194d53e6SMatthew G. Knepley 
31159ee2af8cSMatthew G. Knepley /*@
31169ee2af8cSMatthew G. Knepley   PetscDSGetComponentOffsetsCohesive - Returns the offset of each field on an evaluation point
31179ee2af8cSMatthew G. Knepley 
311820f4b53cSBarry Smith   Not Collective
31199ee2af8cSMatthew G. Knepley 
31209ee2af8cSMatthew G. Knepley   Input Parameters:
3121dce8aebaSBarry Smith + ds - The `PetscDS` object
31229ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
31239ee2af8cSMatthew G. Knepley 
31249ee2af8cSMatthew G. Knepley   Output Parameter:
31259ee2af8cSMatthew G. Knepley . offsets - The offsets
31269ee2af8cSMatthew G. Knepley 
31279ee2af8cSMatthew G. Knepley   Level: beginner
31289ee2af8cSMatthew G. Knepley 
3129dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
31309ee2af8cSMatthew G. Knepley @*/
3131d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
3132d71ae5a4SJacob Faibussowitsch {
31339ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
31349ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
31359ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
313628b400f6SJacob Faibussowitsch   PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
313763a3b9bcSJacob Faibussowitsch   PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s);
31389566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(ds));
31399ee2af8cSMatthew G. Knepley   *offsets = ds->offCohesive[s];
31403ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
31419ee2af8cSMatthew G. Knepley }
31429ee2af8cSMatthew G. Knepley 
31439ee2af8cSMatthew G. Knepley /*@
31449ee2af8cSMatthew G. Knepley   PetscDSGetComponentDerivativeOffsetsCohesive - Returns the offset of each field derivative on an evaluation point
31459ee2af8cSMatthew G. Knepley 
314620f4b53cSBarry Smith   Not Collective
31479ee2af8cSMatthew G. Knepley 
31489ee2af8cSMatthew G. Knepley   Input Parameters:
3149dce8aebaSBarry Smith + ds - The `PetscDS` object
31509ee2af8cSMatthew G. Knepley - s  - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive
31519ee2af8cSMatthew G. Knepley 
31529ee2af8cSMatthew G. Knepley   Output Parameter:
31539ee2af8cSMatthew G. Knepley . offsets - The offsets
31549ee2af8cSMatthew G. Knepley 
31559ee2af8cSMatthew G. Knepley   Level: beginner
31569ee2af8cSMatthew G. Knepley 
3157dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()`
31589ee2af8cSMatthew G. Knepley @*/
3159d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentDerivativeOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[])
3160d71ae5a4SJacob Faibussowitsch {
31619ee2af8cSMatthew G. Knepley   PetscFunctionBegin;
31629ee2af8cSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
31639ee2af8cSMatthew G. Knepley   PetscValidPointer(offsets, 3);
316428b400f6SJacob Faibussowitsch   PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS");
316563a3b9bcSJacob Faibussowitsch   PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s);
31669566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(ds));
31679ee2af8cSMatthew G. Knepley   *offsets = ds->offDerCohesive[s];
31683ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
31699ee2af8cSMatthew G. Knepley }
31709ee2af8cSMatthew G. Knepley 
317168c9edb9SMatthew G. Knepley /*@C
317268c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
317368c9edb9SMatthew G. Knepley 
317420f4b53cSBarry Smith   Not Collective
317568c9edb9SMatthew G. Knepley 
317668c9edb9SMatthew G. Knepley   Input Parameter:
3177dce8aebaSBarry Smith . prob - The `PetscDS` object
317868c9edb9SMatthew G. Knepley 
3179ef0bb6c7SMatthew G. Knepley   Output Parameter:
3180ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field
318168c9edb9SMatthew G. Knepley 
318268c9edb9SMatthew G. Knepley   Level: intermediate
318368c9edb9SMatthew G. Knepley 
3184dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscTabulation`, `PetscDSCreate()`
318568c9edb9SMatthew G. Knepley @*/
3186d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[])
3187d71ae5a4SJacob Faibussowitsch {
31882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
31892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3190ef0bb6c7SMatthew G. Knepley   PetscValidPointer(T, 2);
31919566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3192ef0bb6c7SMatthew G. Knepley   *T = prob->T;
31933ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
31942764a2aaSMatthew G. Knepley }
31952764a2aaSMatthew G. Knepley 
319668c9edb9SMatthew G. Knepley /*@C
31974d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
319868c9edb9SMatthew G. Knepley 
319920f4b53cSBarry Smith   Not Collective
320068c9edb9SMatthew G. Knepley 
320168c9edb9SMatthew G. Knepley   Input Parameter:
3202dce8aebaSBarry Smith . prob - The `PetscDS` object
320368c9edb9SMatthew G. Knepley 
3204ef0bb6c7SMatthew G. Knepley   Output Parameter:
3205a5b23f4aSJose E. Roman . Tf - The basis function and derivative tabulation on each local face at quadrature points for each and field
320668c9edb9SMatthew G. Knepley 
320768c9edb9SMatthew G. Knepley   Level: intermediate
320868c9edb9SMatthew G. Knepley 
3209dce8aebaSBarry Smith .seealso: `PetscTabulation`, `PetscDS`, `PetscDSGetTabulation()`, `PetscDSCreate()`
321068c9edb9SMatthew G. Knepley @*/
3211d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[])
3212d71ae5a4SJacob Faibussowitsch {
32132764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32142764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3215ef0bb6c7SMatthew G. Knepley   PetscValidPointer(Tf, 2);
32169566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
3217ef0bb6c7SMatthew G. Knepley   *Tf = prob->Tf;
32183ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
32192764a2aaSMatthew G. Knepley }
32202764a2aaSMatthew G. Knepley 
3221d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
3222d71ae5a4SJacob Faibussowitsch {
32232764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32242764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
32259566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
32269371c9d4SSatish Balay   if (u) {
32279371c9d4SSatish Balay     PetscValidPointer(u, 2);
32289371c9d4SSatish Balay     *u = prob->u;
32299371c9d4SSatish Balay   }
32309371c9d4SSatish Balay   if (u_t) {
32319371c9d4SSatish Balay     PetscValidPointer(u_t, 3);
32329371c9d4SSatish Balay     *u_t = prob->u_t;
32339371c9d4SSatish Balay   }
32349371c9d4SSatish Balay   if (u_x) {
32359371c9d4SSatish Balay     PetscValidPointer(u_x, 4);
32369371c9d4SSatish Balay     *u_x = prob->u_x;
32379371c9d4SSatish Balay   }
32383ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
32392764a2aaSMatthew G. Knepley }
32402764a2aaSMatthew G. Knepley 
3241d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
3242d71ae5a4SJacob Faibussowitsch {
32432764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32442764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
32459566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
32469371c9d4SSatish Balay   if (f0) {
32479371c9d4SSatish Balay     PetscValidPointer(f0, 2);
32489371c9d4SSatish Balay     *f0 = prob->f0;
32499371c9d4SSatish Balay   }
32509371c9d4SSatish Balay   if (f1) {
32519371c9d4SSatish Balay     PetscValidPointer(f1, 3);
32529371c9d4SSatish Balay     *f1 = prob->f1;
32539371c9d4SSatish Balay   }
32549371c9d4SSatish Balay   if (g0) {
32559371c9d4SSatish Balay     PetscValidPointer(g0, 4);
32569371c9d4SSatish Balay     *g0 = prob->g0;
32579371c9d4SSatish Balay   }
32589371c9d4SSatish Balay   if (g1) {
32599371c9d4SSatish Balay     PetscValidPointer(g1, 5);
32609371c9d4SSatish Balay     *g1 = prob->g1;
32619371c9d4SSatish Balay   }
32629371c9d4SSatish Balay   if (g2) {
32639371c9d4SSatish Balay     PetscValidPointer(g2, 6);
32649371c9d4SSatish Balay     *g2 = prob->g2;
32659371c9d4SSatish Balay   }
32669371c9d4SSatish Balay   if (g3) {
32679371c9d4SSatish Balay     PetscValidPointer(g3, 7);
32689371c9d4SSatish Balay     *g3 = prob->g3;
32699371c9d4SSatish Balay   }
32703ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
32712764a2aaSMatthew G. Knepley }
32722764a2aaSMatthew G. Knepley 
3273d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal)
3274d71ae5a4SJacob Faibussowitsch {
32752764a2aaSMatthew G. Knepley   PetscFunctionBegin;
32762764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
32779566063dSJacob Faibussowitsch   PetscCall(PetscDSSetUp(prob));
32789371c9d4SSatish Balay   if (x) {
32799371c9d4SSatish Balay     PetscValidPointer(x, 2);
32809371c9d4SSatish Balay     *x = prob->x;
32819371c9d4SSatish Balay   }
32829371c9d4SSatish Balay   if (basisReal) {
32839371c9d4SSatish Balay     PetscValidPointer(basisReal, 3);
32849371c9d4SSatish Balay     *basisReal = prob->basisReal;
32859371c9d4SSatish Balay   }
32869371c9d4SSatish Balay   if (basisDerReal) {
32879371c9d4SSatish Balay     PetscValidPointer(basisDerReal, 4);
32889371c9d4SSatish Balay     *basisDerReal = prob->basisDerReal;
32899371c9d4SSatish Balay   }
32909371c9d4SSatish Balay   if (testReal) {
32919371c9d4SSatish Balay     PetscValidPointer(testReal, 5);
32929371c9d4SSatish Balay     *testReal = prob->testReal;
32939371c9d4SSatish Balay   }
32949371c9d4SSatish Balay   if (testDerReal) {
32959371c9d4SSatish Balay     PetscValidPointer(testDerReal, 6);
32969371c9d4SSatish Balay     *testDerReal = prob->testDerReal;
32979371c9d4SSatish Balay   }
32983ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
32992764a2aaSMatthew G. Knepley }
33002764a2aaSMatthew G. Knepley 
330158ebd649SToby Isaac /*@C
3302dce8aebaSBarry Smith   PetscDSAddBoundary - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions.
3303dce8aebaSBarry 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
3304dce8aebaSBarry Smith   integrals should be performed, using the kernels from `PetscDSSetBdResidual()`.
330558ebd649SToby Isaac 
330620f4b53cSBarry Smith   Collective
3307783e2ec8SMatthew G. Knepley 
330858ebd649SToby Isaac   Input Parameters:
330958ebd649SToby Isaac + ds       - The PetscDS object
3310dce8aebaSBarry Smith . type     - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann)
331158ebd649SToby Isaac . name     - The BC name
331245480ffeSMatthew G. Knepley . label    - The label defining constrained points
3313dce8aebaSBarry Smith . Nv       - The number of `DMLabel` values for constrained points
331445480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
331558ebd649SToby Isaac . field    - The field to constrain
331645480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
331758ebd649SToby Isaac . comps    - An array of constrained component numbers
331858ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3319a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
332058ebd649SToby Isaac - ctx      - An optional user context for bcFunc
332158ebd649SToby Isaac 
332245480ffeSMatthew G. Knepley   Output Parameters:
332345480ffeSMatthew G. Knepley - bd       - The boundary number
332445480ffeSMatthew G. Knepley 
332558ebd649SToby Isaac   Options Database Keys:
332658ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
332758ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
332858ebd649SToby Isaac 
3329dce8aebaSBarry Smith   Level: developer
3330dce8aebaSBarry Smith 
333156cf3b9cSMatthew G. Knepley   Note:
333220f4b53cSBarry 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:
333356cf3b9cSMatthew G. Knepley 
333420f4b53cSBarry Smith $ void bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
333556cf3b9cSMatthew G. Knepley 
3336dce8aebaSBarry Smith   If the type is `DM_BC_ESSENTIAL_FIELD` or other _FIELD value, then the calling sequence is:
3337dce8aebaSBarry Smith .vb
333820f4b53cSBarry Smith   void bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
3339dce8aebaSBarry Smith               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
3340dce8aebaSBarry Smith               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
3341dce8aebaSBarry Smith               PetscReal time, const PetscReal x[], PetscScalar bcval[])
3342dce8aebaSBarry Smith .ve
334356cf3b9cSMatthew G. Knepley + dim - the spatial dimension
334456cf3b9cSMatthew G. Knepley . Nf - the number of fields
334556cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
334656cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
334756cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point
334856cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
334956cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
335056cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
335156cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
335256cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
335356cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
335456cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
335556cf3b9cSMatthew G. Knepley . t - current time
335656cf3b9cSMatthew G. Knepley . x - coordinates of the current point
335756cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters
335856cf3b9cSMatthew G. Knepley . constants - constant parameters
335956cf3b9cSMatthew G. Knepley - bcval - output values at the current point
336056cf3b9cSMatthew G. Knepley 
3361dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMLabel`, `DMBoundaryConditionType`, `PetscDSAddBoundaryByName()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()`
336258ebd649SToby Isaac @*/
3363d71ae5a4SJacob 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)
3364d71ae5a4SJacob Faibussowitsch {
336545480ffeSMatthew G. Knepley   DSBoundary  head = ds->boundary, b;
336645480ffeSMatthew G. Knepley   PetscInt    n    = 0;
336745480ffeSMatthew G. Knepley   const char *lname;
336858ebd649SToby Isaac 
336958ebd649SToby Isaac   PetscFunctionBegin;
337058ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3371783e2ec8SMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
337245480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
337345480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4);
337445480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
337545480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
337645480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
3377dce9da9cSMatthew 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);
3378d57bb9dbSMatthew G. Knepley   if (Nc > 0) {
3379d57bb9dbSMatthew G. Knepley     PetscInt *fcomps;
3380d57bb9dbSMatthew G. Knepley     PetscInt  c;
3381d57bb9dbSMatthew G. Knepley 
33829566063dSJacob Faibussowitsch     PetscCall(PetscDSGetComponents(ds, &fcomps));
338363a3b9bcSJacob 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);
3384d57bb9dbSMatthew G. Knepley     for (c = 0; c < Nc; ++c) {
33851dca8a05SBarry 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);
3386d57bb9dbSMatthew G. Knepley     }
3387d57bb9dbSMatthew G. Knepley   }
33889566063dSJacob Faibussowitsch   PetscCall(PetscNew(&b));
33899566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(name, (char **)&b->name));
33909566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf));
33919566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf));
33929566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nv, &b->values));
33939566063dSJacob Faibussowitsch   if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv));
33949566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nc, &b->comps));
33959566063dSJacob Faibussowitsch   if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc));
33969566063dSJacob Faibussowitsch   PetscCall(PetscObjectGetName((PetscObject)label, &lname));
33979566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(lname, (char **)&b->lname));
3398f971fd6bSMatthew G. Knepley   b->type   = type;
339945480ffeSMatthew G. Knepley   b->label  = label;
340045480ffeSMatthew G. Knepley   b->Nv     = Nv;
340158ebd649SToby Isaac   b->field  = field;
340245480ffeSMatthew G. Knepley   b->Nc     = Nc;
340358ebd649SToby Isaac   b->func   = bcFunc;
340456cf3b9cSMatthew G. Knepley   b->func_t = bcFunc_t;
340558ebd649SToby Isaac   b->ctx    = ctx;
340645480ffeSMatthew G. Knepley   b->next   = NULL;
340745480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
340845480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
340945480ffeSMatthew G. Knepley   while (head) {
341045480ffeSMatthew G. Knepley     if (!head->next) {
341145480ffeSMatthew G. Knepley       head->next = b;
341245480ffeSMatthew G. Knepley       head       = b;
341345480ffeSMatthew G. Knepley     }
341445480ffeSMatthew G. Knepley     head = head->next;
341545480ffeSMatthew G. Knepley     ++n;
341645480ffeSMatthew G. Knepley   }
34179371c9d4SSatish Balay   if (bd) {
34189371c9d4SSatish Balay     PetscValidIntPointer(bd, 13);
34199371c9d4SSatish Balay     *bd = n;
34209371c9d4SSatish Balay   }
34213ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
342245480ffeSMatthew G. Knepley }
342345480ffeSMatthew G. Knepley 
342445480ffeSMatthew G. Knepley /*@C
3425dce8aebaSBarry Smith   PetscDSAddBoundaryByName - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions.
3426dce8aebaSBarry 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
3427dce8aebaSBarry Smith   boundary integrals should be performed, using the kernels from `PetscDSSetBdResidual()`.
342845480ffeSMatthew G. Knepley 
342920f4b53cSBarry Smith   Collective
343045480ffeSMatthew G. Knepley 
343145480ffeSMatthew G. Knepley   Input Parameters:
3432dce8aebaSBarry Smith + ds       - The `PetscDS` object
3433dce8aebaSBarry Smith . type     - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann)
343445480ffeSMatthew G. Knepley . name     - The BC name
343545480ffeSMatthew G. Knepley . lname    - The naem of the label defining constrained points
3436dce8aebaSBarry Smith . Nv       - The number of `DMLabel` values for constrained points
343745480ffeSMatthew G. Knepley . values   - An array of label values for constrained points
343845480ffeSMatthew G. Knepley . field    - The field to constrain
343945480ffeSMatthew G. Knepley . Nc       - The number of constrained field components (0 will constrain all fields)
344045480ffeSMatthew G. Knepley . comps    - An array of constrained component numbers
344145480ffeSMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3442a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
344345480ffeSMatthew G. Knepley - ctx      - An optional user context for bcFunc
344445480ffeSMatthew G. Knepley 
344545480ffeSMatthew G. Knepley   Output Parameters:
344645480ffeSMatthew G. Knepley - bd       - The boundary number
344745480ffeSMatthew G. Knepley 
344845480ffeSMatthew G. Knepley   Options Database Keys:
344945480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids
345045480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components
345145480ffeSMatthew G. Knepley 
345220f4b53cSBarry Smith   Calling Sequence of `bcFunc` and `bcFunc_t`:
3453dce8aebaSBarry Smith   If the type is `DM_BC_ESSENTIAL`
3454dce8aebaSBarry Smith .vb
345520f4b53cSBarry Smith   void bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[])
3456dce8aebaSBarry Smith .ve
3457dce8aebaSBarry Smith   If the type is `DM_BC_ESSENTIAL_FIELD` or other _FIELD value,
3458dce8aebaSBarry Smith .vb
345920f4b53cSBarry Smith   void bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux,
3460dce8aebaSBarry Smith               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
3461dce8aebaSBarry Smith               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
3462dce8aebaSBarry Smith               PetscReal time, const PetscReal x[], PetscScalar bcval[])
3463dce8aebaSBarry Smith .ve
346445480ffeSMatthew G. Knepley + dim - the spatial dimension
346545480ffeSMatthew G. Knepley . Nf - the number of fields
346645480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
346745480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
346845480ffeSMatthew G. Knepley . u - each field evaluated at the current point
346945480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
347045480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
347145480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
347245480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
347345480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point
347445480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
347545480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
347645480ffeSMatthew G. Knepley . t - current time
347745480ffeSMatthew G. Knepley . x - coordinates of the current point
347845480ffeSMatthew G. Knepley . numConstants - number of constant parameters
347945480ffeSMatthew G. Knepley . constants - constant parameters
348045480ffeSMatthew G. Knepley - bcval - output values at the current point
348145480ffeSMatthew G. Knepley 
348245480ffeSMatthew G. Knepley   Level: developer
348345480ffeSMatthew G. Knepley 
3484dce8aebaSBarry Smith   Note:
3485dce8aebaSBarry Smith   This function should only be used with `DMFOREST` currently, since labels cannot be defined before the underlying `DMPLEX` is built.
3486dce8aebaSBarry Smith 
3487dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMLabel`, `DMBoundaryConditionType`, `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()`
348845480ffeSMatthew G. Knepley @*/
3489d71ae5a4SJacob 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)
3490d71ae5a4SJacob Faibussowitsch {
349145480ffeSMatthew G. Knepley   DSBoundary head = ds->boundary, b;
349245480ffeSMatthew G. Knepley   PetscInt   n    = 0;
349345480ffeSMatthew G. Knepley 
349445480ffeSMatthew G. Knepley   PetscFunctionBegin;
349545480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
349645480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveEnum(ds, type, 2);
349745480ffeSMatthew G. Knepley   PetscValidCharPointer(name, 3);
349845480ffeSMatthew G. Knepley   PetscValidCharPointer(lname, 4);
349945480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nv, 5);
350045480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, field, 7);
350145480ffeSMatthew G. Knepley   PetscValidLogicalCollectiveInt(ds, Nc, 8);
35029566063dSJacob Faibussowitsch   PetscCall(PetscNew(&b));
35039566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(name, (char **)&b->name));
35049566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf));
35059566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf));
35069566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nv, &b->values));
35079566063dSJacob Faibussowitsch   if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv));
35089566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(Nc, &b->comps));
35099566063dSJacob Faibussowitsch   if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc));
35109566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(lname, (char **)&b->lname));
351145480ffeSMatthew G. Knepley   b->type   = type;
351245480ffeSMatthew G. Knepley   b->label  = NULL;
351345480ffeSMatthew G. Knepley   b->Nv     = Nv;
351445480ffeSMatthew G. Knepley   b->field  = field;
351545480ffeSMatthew G. Knepley   b->Nc     = Nc;
351645480ffeSMatthew G. Knepley   b->func   = bcFunc;
351745480ffeSMatthew G. Knepley   b->func_t = bcFunc_t;
351845480ffeSMatthew G. Knepley   b->ctx    = ctx;
351945480ffeSMatthew G. Knepley   b->next   = NULL;
352045480ffeSMatthew G. Knepley   /* Append to linked list so that we can preserve the order */
352145480ffeSMatthew G. Knepley   if (!head) ds->boundary = b;
352245480ffeSMatthew G. Knepley   while (head) {
352345480ffeSMatthew G. Knepley     if (!head->next) {
352445480ffeSMatthew G. Knepley       head->next = b;
352545480ffeSMatthew G. Knepley       head       = b;
352645480ffeSMatthew G. Knepley     }
352745480ffeSMatthew G. Knepley     head = head->next;
352845480ffeSMatthew G. Knepley     ++n;
352945480ffeSMatthew G. Knepley   }
35309371c9d4SSatish Balay   if (bd) {
35319371c9d4SSatish Balay     PetscValidIntPointer(bd, 13);
35329371c9d4SSatish Balay     *bd = n;
35339371c9d4SSatish Balay   }
35343ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
353558ebd649SToby Isaac }
353658ebd649SToby Isaac 
3537b67eacb3SMatthew G. Knepley /*@C
3538dce8aebaSBarry Smith   PetscDSUpdateBoundary - Change a boundary condition for the model. The pointwise functions are used to provide boundary values for essential boundary conditions.
3539dce8aebaSBarry 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
3540dce8aebaSBarry Smith   should be performed, using the kernels from `PetscDSSetBdResidual()`.
3541b67eacb3SMatthew G. Knepley 
3542b67eacb3SMatthew G. Knepley   Input Parameters:
3543dce8aebaSBarry Smith + ds       - The `PetscDS` object
3544b67eacb3SMatthew G. Knepley . bd       - The boundary condition number
3545dce8aebaSBarry Smith . type     - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann)
3546b67eacb3SMatthew G. Knepley . name     - The BC name
354745480ffeSMatthew G. Knepley . label    - The label defining constrained points
3548dce8aebaSBarry Smith . Nv       - The number of `DMLabel` ids for constrained points
354945480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
3550b67eacb3SMatthew G. Knepley . field    - The field to constrain
355145480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
3552b67eacb3SMatthew G. Knepley . comps    - An array of constrained component numbers
3553b67eacb3SMatthew G. Knepley . bcFunc   - A pointwise function giving boundary values
3554a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL
3555b67eacb3SMatthew G. Knepley - ctx      - An optional user context for bcFunc
3556b67eacb3SMatthew G. Knepley 
3557b67eacb3SMatthew G. Knepley   Level: developer
3558b67eacb3SMatthew G. Knepley 
3559dce8aebaSBarry Smith   Note:
3560dce8aebaSBarry Smith   The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from `PetscDSGetNumBoundary()`.
3561dce8aebaSBarry Smith   See `PetscDSAddBoundary()` for a description of the calling sequences for the callbacks.
3562dce8aebaSBarry Smith 
3563dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMBoundaryConditionType`, `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSGetNumBoundary()`, `DMLabel`
3564b67eacb3SMatthew G. Knepley @*/
3565d71ae5a4SJacob 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)
3566d71ae5a4SJacob Faibussowitsch {
3567b67eacb3SMatthew G. Knepley   DSBoundary b = ds->boundary;
3568b67eacb3SMatthew G. Knepley   PetscInt   n = 0;
3569b67eacb3SMatthew G. Knepley 
3570b67eacb3SMatthew G. Knepley   PetscFunctionBegin;
3571b67eacb3SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3572b67eacb3SMatthew G. Knepley   while (b) {
3573b67eacb3SMatthew G. Knepley     if (n == bd) break;
3574b67eacb3SMatthew G. Knepley     b = b->next;
3575b67eacb3SMatthew G. Knepley     ++n;
3576b67eacb3SMatthew G. Knepley   }
357763a3b9bcSJacob Faibussowitsch   PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n);
3578b67eacb3SMatthew G. Knepley   if (name) {
35799566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->name));
35809566063dSJacob Faibussowitsch     PetscCall(PetscStrallocpy(name, (char **)&b->name));
3581b67eacb3SMatthew G. Knepley   }
3582b67eacb3SMatthew G. Knepley   b->type = type;
358345480ffeSMatthew G. Knepley   if (label) {
358445480ffeSMatthew G. Knepley     const char *name;
358545480ffeSMatthew G. Knepley 
358645480ffeSMatthew G. Knepley     b->label = label;
35879566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->lname));
35889566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetName((PetscObject)label, &name));
35899566063dSJacob Faibussowitsch     PetscCall(PetscStrallocpy(name, (char **)&b->lname));
359045480ffeSMatthew G. Knepley   }
359145480ffeSMatthew G. Knepley   if (Nv >= 0) {
359245480ffeSMatthew G. Knepley     b->Nv = Nv;
35939566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->values));
35949566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(Nv, &b->values));
35959566063dSJacob Faibussowitsch     if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv));
359645480ffeSMatthew G. Knepley   }
359745480ffeSMatthew G. Knepley   if (field >= 0) b->field = field;
359845480ffeSMatthew G. Knepley   if (Nc >= 0) {
359945480ffeSMatthew G. Knepley     b->Nc = Nc;
36009566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->comps));
36019566063dSJacob Faibussowitsch     PetscCall(PetscMalloc1(Nc, &b->comps));
36029566063dSJacob Faibussowitsch     if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc));
360345480ffeSMatthew G. Knepley   }
360445480ffeSMatthew G. Knepley   if (bcFunc) b->func = bcFunc;
360545480ffeSMatthew G. Knepley   if (bcFunc_t) b->func_t = bcFunc_t;
360645480ffeSMatthew G. Knepley   if (ctx) b->ctx = ctx;
36073ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3608b67eacb3SMatthew G. Knepley }
3609b67eacb3SMatthew G. Knepley 
361058ebd649SToby Isaac /*@
361158ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
361258ebd649SToby Isaac 
361358ebd649SToby Isaac   Input Parameters:
3614dce8aebaSBarry Smith . ds - The `PetscDS` object
361558ebd649SToby Isaac 
361658ebd649SToby Isaac   Output Parameters:
361758ebd649SToby Isaac . numBd - The number of BC
361858ebd649SToby Isaac 
361958ebd649SToby Isaac   Level: intermediate
362058ebd649SToby Isaac 
3621dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSAddBoundary()`, `PetscDSGetBoundary()`
362258ebd649SToby Isaac @*/
3623d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
3624d71ae5a4SJacob Faibussowitsch {
362558ebd649SToby Isaac   DSBoundary b = ds->boundary;
362658ebd649SToby Isaac 
362758ebd649SToby Isaac   PetscFunctionBegin;
362858ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
3629dadcf809SJacob Faibussowitsch   PetscValidIntPointer(numBd, 2);
363058ebd649SToby Isaac   *numBd = 0;
36319371c9d4SSatish Balay   while (b) {
36329371c9d4SSatish Balay     ++(*numBd);
36339371c9d4SSatish Balay     b = b->next;
36349371c9d4SSatish Balay   }
36353ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
363658ebd649SToby Isaac }
363758ebd649SToby Isaac 
363858ebd649SToby Isaac /*@C
36399a6efb6aSMatthew G. Knepley   PetscDSGetBoundary - Gets a boundary condition to the model
364058ebd649SToby Isaac 
364158ebd649SToby Isaac   Input Parameters:
3642dce8aebaSBarry Smith + ds          - The `PetscDS` object
364358ebd649SToby Isaac - bd          - The BC number
364458ebd649SToby Isaac 
364558ebd649SToby Isaac   Output Parameters:
3646dce8aebaSBarry Smith + wf       - The `PetscWeakForm` holding the pointwise functions
3647dce8aebaSBarry Smith . type     - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann)
364858ebd649SToby Isaac . name     - The BC name
364945480ffeSMatthew G. Knepley . label    - The label defining constrained points
3650dce8aebaSBarry Smith . Nv       - The number of `DMLabel` ids for constrained points
365145480ffeSMatthew G. Knepley . values   - An array of ids for constrained points
365258ebd649SToby Isaac . field    - The field to constrain
365345480ffeSMatthew G. Knepley . Nc       - The number of constrained field components
365458ebd649SToby Isaac . comps    - An array of constrained component numbers
365558ebd649SToby Isaac . bcFunc   - A pointwise function giving boundary values
3656a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values
365758ebd649SToby Isaac - ctx      - An optional user context for bcFunc
365858ebd649SToby Isaac 
365958ebd649SToby Isaac   Options Database Keys:
366058ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
366158ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
366258ebd649SToby Isaac 
366358ebd649SToby Isaac   Level: developer
366458ebd649SToby Isaac 
3665dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMBoundaryConditionType`, `PetscDSAddBoundary()`, `DMLabel`
366658ebd649SToby Isaac @*/
3667d71ae5a4SJacob 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)
3668d71ae5a4SJacob Faibussowitsch {
366958ebd649SToby Isaac   DSBoundary b = ds->boundary;
367058ebd649SToby Isaac   PetscInt   n = 0;
367158ebd649SToby Isaac 
367258ebd649SToby Isaac   PetscFunctionBegin;
367358ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
367458ebd649SToby Isaac   while (b) {
367558ebd649SToby Isaac     if (n == bd) break;
367658ebd649SToby Isaac     b = b->next;
367758ebd649SToby Isaac     ++n;
367858ebd649SToby Isaac   }
367963a3b9bcSJacob Faibussowitsch   PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n);
368045480ffeSMatthew G. Knepley   if (wf) {
368145480ffeSMatthew G. Knepley     PetscValidPointer(wf, 3);
368245480ffeSMatthew G. Knepley     *wf = b->wf;
368345480ffeSMatthew G. Knepley   }
3684f971fd6bSMatthew G. Knepley   if (type) {
368545480ffeSMatthew G. Knepley     PetscValidPointer(type, 4);
3686f971fd6bSMatthew G. Knepley     *type = b->type;
368758ebd649SToby Isaac   }
368858ebd649SToby Isaac   if (name) {
368945480ffeSMatthew G. Knepley     PetscValidPointer(name, 5);
369058ebd649SToby Isaac     *name = b->name;
369158ebd649SToby Isaac   }
369245480ffeSMatthew G. Knepley   if (label) {
369345480ffeSMatthew G. Knepley     PetscValidPointer(label, 6);
369445480ffeSMatthew G. Knepley     *label = b->label;
369545480ffeSMatthew G. Knepley   }
369645480ffeSMatthew G. Knepley   if (Nv) {
369745480ffeSMatthew G. Knepley     PetscValidIntPointer(Nv, 7);
369845480ffeSMatthew G. Knepley     *Nv = b->Nv;
369945480ffeSMatthew G. Knepley   }
370045480ffeSMatthew G. Knepley   if (values) {
370145480ffeSMatthew G. Knepley     PetscValidPointer(values, 8);
370245480ffeSMatthew G. Knepley     *values = b->values;
370358ebd649SToby Isaac   }
370458ebd649SToby Isaac   if (field) {
370545480ffeSMatthew G. Knepley     PetscValidIntPointer(field, 9);
370658ebd649SToby Isaac     *field = b->field;
370758ebd649SToby Isaac   }
370845480ffeSMatthew G. Knepley   if (Nc) {
370945480ffeSMatthew G. Knepley     PetscValidIntPointer(Nc, 10);
371045480ffeSMatthew G. Knepley     *Nc = b->Nc;
371158ebd649SToby Isaac   }
371258ebd649SToby Isaac   if (comps) {
371345480ffeSMatthew G. Knepley     PetscValidPointer(comps, 11);
371458ebd649SToby Isaac     *comps = b->comps;
371558ebd649SToby Isaac   }
371658ebd649SToby Isaac   if (func) {
371745480ffeSMatthew G. Knepley     PetscValidPointer(func, 12);
371858ebd649SToby Isaac     *func = b->func;
371958ebd649SToby Isaac   }
372056cf3b9cSMatthew G. Knepley   if (func_t) {
372145480ffeSMatthew G. Knepley     PetscValidPointer(func_t, 13);
372256cf3b9cSMatthew G. Knepley     *func_t = b->func_t;
372356cf3b9cSMatthew G. Knepley   }
372458ebd649SToby Isaac   if (ctx) {
372545480ffeSMatthew G. Knepley     PetscValidPointer(ctx, 14);
372658ebd649SToby Isaac     *ctx = b->ctx;
372758ebd649SToby Isaac   }
37283ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
372958ebd649SToby Isaac }
373058ebd649SToby Isaac 
3731d71ae5a4SJacob Faibussowitsch static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew)
3732d71ae5a4SJacob Faibussowitsch {
373345480ffeSMatthew G. Knepley   PetscFunctionBegin;
37349566063dSJacob Faibussowitsch   PetscCall(PetscNew(bNew));
37359566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf));
37369566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCopy(b->wf, (*bNew)->wf));
37379566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(b->name, (char **)&((*bNew)->name)));
37389566063dSJacob Faibussowitsch   PetscCall(PetscStrallocpy(b->lname, (char **)&((*bNew)->lname)));
373945480ffeSMatthew G. Knepley   (*bNew)->type  = b->type;
374045480ffeSMatthew G. Knepley   (*bNew)->label = b->label;
374145480ffeSMatthew G. Knepley   (*bNew)->Nv    = b->Nv;
37429566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(b->Nv, &(*bNew)->values));
37439566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy((*bNew)->values, b->values, b->Nv));
374445480ffeSMatthew G. Knepley   (*bNew)->field = b->field;
374545480ffeSMatthew G. Knepley   (*bNew)->Nc    = b->Nc;
37469566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(b->Nc, &(*bNew)->comps));
37479566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy((*bNew)->comps, b->comps, b->Nc));
374845480ffeSMatthew G. Knepley   (*bNew)->func   = b->func;
374945480ffeSMatthew G. Knepley   (*bNew)->func_t = b->func_t;
375045480ffeSMatthew G. Knepley   (*bNew)->ctx    = b->ctx;
37513ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
375245480ffeSMatthew G. Knepley }
375345480ffeSMatthew G. Knepley 
37549252d075SMatthew G. Knepley /*@
37559252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
37569252d075SMatthew G. Knepley 
375720f4b53cSBarry Smith   Not Collective
37589252d075SMatthew G. Knepley 
375936951cb5SMatthew G. Knepley   Input Parameters:
3760dce8aebaSBarry Smith + ds        - The source `PetscDS` object
3761dce8aebaSBarry Smith . numFields - The number of selected fields, or `PETSC_DEFAULT` for all fields
376236951cb5SMatthew G. Knepley - fields    - The selected fields, or NULL for all fields
37639252d075SMatthew G. Knepley 
37649252d075SMatthew G. Knepley   Output Parameter:
3765dce8aebaSBarry Smith . newds     - The target `PetscDS`, now with a copy of the boundary conditions
37669252d075SMatthew G. Knepley 
37679252d075SMatthew G. Knepley   Level: intermediate
37689252d075SMatthew G. Knepley 
3769dce8aebaSBarry Smith .seealso: `PetscDS`, `DMBoundary`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
37709252d075SMatthew G. Knepley @*/
3771d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds)
3772d71ae5a4SJacob Faibussowitsch {
377345480ffeSMatthew G. Knepley   DSBoundary b, *lastnext;
3774dff059c6SToby Isaac 
3775dff059c6SToby Isaac   PetscFunctionBegin;
377636951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
377736951cb5SMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4);
37783ba16761SJacob Faibussowitsch   if (ds == newds) PetscFunctionReturn(PETSC_SUCCESS);
37799566063dSJacob Faibussowitsch   PetscCall(PetscDSDestroyBoundary(newds));
378036951cb5SMatthew G. Knepley   lastnext = &(newds->boundary);
378136951cb5SMatthew G. Knepley   for (b = ds->boundary; b; b = b->next) {
3782dff059c6SToby Isaac     DSBoundary bNew;
378336951cb5SMatthew G. Knepley     PetscInt   fieldNew = -1;
3784dff059c6SToby Isaac 
378536951cb5SMatthew G. Knepley     if (numFields > 0 && fields) {
378636951cb5SMatthew G. Knepley       PetscInt f;
378736951cb5SMatthew G. Knepley 
37889371c9d4SSatish Balay       for (f = 0; f < numFields; ++f)
37899371c9d4SSatish Balay         if (b->field == fields[f]) break;
379036951cb5SMatthew G. Knepley       if (f == numFields) continue;
379136951cb5SMatthew G. Knepley       fieldNew = f;
379236951cb5SMatthew G. Knepley     }
37939566063dSJacob Faibussowitsch     PetscCall(DSBoundaryDuplicate_Internal(b, &bNew));
379436951cb5SMatthew G. Knepley     bNew->field = fieldNew < 0 ? b->field : fieldNew;
3795dff059c6SToby Isaac     *lastnext   = bNew;
3796dff059c6SToby Isaac     lastnext    = &(bNew->next);
3797dff059c6SToby Isaac   }
37983ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3799dff059c6SToby Isaac }
3800dff059c6SToby Isaac 
38016c1eb96dSMatthew G. Knepley /*@
3802dce8aebaSBarry Smith   PetscDSDestroyBoundary - Remove all `DMBoundary` objects from the `PetscDS`
380345480ffeSMatthew G. Knepley 
380420f4b53cSBarry Smith   Not Collective
380545480ffeSMatthew G. Knepley 
380645480ffeSMatthew G. Knepley   Input Parameter:
3807dce8aebaSBarry Smith . ds - The `PetscDS` object
380845480ffeSMatthew G. Knepley 
380945480ffeSMatthew G. Knepley   Level: intermediate
381045480ffeSMatthew G. Knepley 
3811dce8aebaSBarry Smith .seealso: `PetscDS`, `DMBoundary`, `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`
381245480ffeSMatthew G. Knepley @*/
3813d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSDestroyBoundary(PetscDS ds)
3814d71ae5a4SJacob Faibussowitsch {
381545480ffeSMatthew G. Knepley   DSBoundary next = ds->boundary;
381645480ffeSMatthew G. Knepley 
381745480ffeSMatthew G. Knepley   PetscFunctionBegin;
381845480ffeSMatthew G. Knepley   while (next) {
381945480ffeSMatthew G. Knepley     DSBoundary b = next;
382045480ffeSMatthew G. Knepley 
382145480ffeSMatthew G. Knepley     next = b->next;
38229566063dSJacob Faibussowitsch     PetscCall(PetscWeakFormDestroy(&b->wf));
38239566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->name));
38249566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->lname));
38259566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->values));
38269566063dSJacob Faibussowitsch     PetscCall(PetscFree(b->comps));
38279566063dSJacob Faibussowitsch     PetscCall(PetscFree(b));
382845480ffeSMatthew G. Knepley   }
38293ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
383045480ffeSMatthew G. Knepley }
383145480ffeSMatthew G. Knepley 
383245480ffeSMatthew G. Knepley /*@
38336c1eb96dSMatthew G. Knepley   PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout
38346c1eb96dSMatthew G. Knepley 
383520f4b53cSBarry Smith   Not Collective
38366c1eb96dSMatthew G. Knepley 
3837d8d19677SJose E. Roman   Input Parameters:
3838dce8aebaSBarry Smith + prob - The `PetscDS` object
38396c1eb96dSMatthew G. Knepley . numFields - Number of new fields
38406c1eb96dSMatthew G. Knepley - fields - Old field number for each new field
38416c1eb96dSMatthew G. Knepley 
38426c1eb96dSMatthew G. Knepley   Output Parameter:
3843dce8aebaSBarry Smith . newprob - The `PetscDS` copy
38446c1eb96dSMatthew G. Knepley 
38456c1eb96dSMatthew G. Knepley   Level: intermediate
38466c1eb96dSMatthew G. Knepley 
3847dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSelectEquations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
38486c1eb96dSMatthew G. Knepley @*/
3849d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
3850d71ae5a4SJacob Faibussowitsch {
38516c1eb96dSMatthew G. Knepley   PetscInt Nf, Nfn, fn;
38526c1eb96dSMatthew G. Knepley 
38536c1eb96dSMatthew G. Knepley   PetscFunctionBegin;
38546c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3855dadcf809SJacob Faibussowitsch   if (fields) PetscValidIntPointer(fields, 3);
38566c1eb96dSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
38579566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
38589566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(newprob, &Nfn));
385945480ffeSMatthew G. Knepley   numFields = numFields < 0 ? Nf : numFields;
38606c1eb96dSMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
38616c1eb96dSMatthew G. Knepley     const PetscInt f = fields ? fields[fn] : fn;
38626c1eb96dSMatthew G. Knepley     PetscObject    disc;
38636c1eb96dSMatthew G. Knepley 
38646c1eb96dSMatthew G. Knepley     if (f >= Nf) continue;
38659566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(prob, f, &disc));
38669566063dSJacob Faibussowitsch     PetscCall(PetscDSSetDiscretization(newprob, fn, disc));
38676c1eb96dSMatthew G. Knepley   }
38683ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
38696c1eb96dSMatthew G. Knepley }
38706c1eb96dSMatthew G. Knepley 
38716c1eb96dSMatthew G. Knepley /*@
38729252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
38739252d075SMatthew G. Knepley 
387420f4b53cSBarry Smith   Not Collective
38759252d075SMatthew G. Knepley 
3876d8d19677SJose E. Roman   Input Parameters:
3877dce8aebaSBarry Smith + prob - The `PetscDS` object
38789252d075SMatthew G. Knepley . numFields - Number of new fields
38799252d075SMatthew G. Knepley - fields - Old field number for each new field
38809252d075SMatthew G. Knepley 
38819252d075SMatthew G. Knepley   Output Parameter:
3882dce8aebaSBarry Smith . newprob - The `PetscDS` copy
38839252d075SMatthew G. Knepley 
38849252d075SMatthew G. Knepley   Level: intermediate
38859252d075SMatthew G. Knepley 
3886dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSelectDiscretizations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
38879252d075SMatthew G. Knepley @*/
3888d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
3889d71ae5a4SJacob Faibussowitsch {
38909252d075SMatthew G. Knepley   PetscInt Nf, Nfn, fn, gn;
38919252d075SMatthew G. Knepley 
38929252d075SMatthew G. Knepley   PetscFunctionBegin;
38939252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3894dadcf809SJacob Faibussowitsch   if (fields) PetscValidIntPointer(fields, 3);
38959252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
38969566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
38979566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(newprob, &Nfn));
389863a3b9bcSJacob 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);
38999252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
39009252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
39019252d075SMatthew G. Knepley     PetscPointFunc   obj;
39029252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
39039252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
39049252d075SMatthew G. Knepley     PetscRiemannFunc r;
39059252d075SMatthew G. Knepley 
3906c52f1e13SMatthew G. Knepley     if (f >= Nf) continue;
39079566063dSJacob Faibussowitsch     PetscCall(PetscDSGetObjective(prob, f, &obj));
39089566063dSJacob Faibussowitsch     PetscCall(PetscDSGetResidual(prob, f, &f0, &f1));
39099566063dSJacob Faibussowitsch     PetscCall(PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd));
39109566063dSJacob Faibussowitsch     PetscCall(PetscDSGetRiemannSolver(prob, f, &r));
39119566063dSJacob Faibussowitsch     PetscCall(PetscDSSetObjective(newprob, fn, obj));
39129566063dSJacob Faibussowitsch     PetscCall(PetscDSSetResidual(newprob, fn, f0, f1));
39139566063dSJacob Faibussowitsch     PetscCall(PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd));
39149566063dSJacob Faibussowitsch     PetscCall(PetscDSSetRiemannSolver(newprob, fn, r));
39159252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
39169252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
39179252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
39189252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
39199252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
39209252d075SMatthew G. Knepley 
3921c52f1e13SMatthew G. Knepley       if (g >= Nf) continue;
39229566063dSJacob Faibussowitsch       PetscCall(PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3));
39239566063dSJacob Faibussowitsch       PetscCall(PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p));
39249566063dSJacob Faibussowitsch       PetscCall(PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd));
39259566063dSJacob Faibussowitsch       PetscCall(PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3));
39269566063dSJacob Faibussowitsch       PetscCall(PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p));
39279566063dSJacob Faibussowitsch       PetscCall(PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd));
39289252d075SMatthew G. Knepley     }
39299252d075SMatthew G. Knepley   }
39303ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
39319252d075SMatthew G. Knepley }
39329252d075SMatthew G. Knepley 
3933da51fcedSMatthew G. Knepley /*@
3934dce8aebaSBarry Smith   PetscDSCopyEquations - Copy all pointwise function pointers to another `PetscDS`
3935da51fcedSMatthew G. Knepley 
393620f4b53cSBarry Smith   Not Collective
3937da51fcedSMatthew G. Knepley 
3938da51fcedSMatthew G. Knepley   Input Parameter:
3939dce8aebaSBarry Smith . prob - The `PetscDS` object
3940da51fcedSMatthew G. Knepley 
3941da51fcedSMatthew G. Knepley   Output Parameter:
3942dce8aebaSBarry Smith . newprob - The `PetscDS` copy
3943da51fcedSMatthew G. Knepley 
3944da51fcedSMatthew G. Knepley   Level: intermediate
3945da51fcedSMatthew G. Knepley 
3946dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
3947da51fcedSMatthew G. Knepley @*/
3948d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
3949d71ae5a4SJacob Faibussowitsch {
3950b8025e53SMatthew G. Knepley   PetscWeakForm wf, newwf;
39519252d075SMatthew G. Knepley   PetscInt      Nf, Ng;
3952da51fcedSMatthew G. Knepley 
3953da51fcedSMatthew G. Knepley   PetscFunctionBegin;
3954da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3955da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
39569566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
39579566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(newprob, &Ng));
395863a3b9bcSJacob Faibussowitsch   PetscCheck(Nf == Ng, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %" PetscInt_FMT " != %" PetscInt_FMT, Nf, Ng);
39599566063dSJacob Faibussowitsch   PetscCall(PetscDSGetWeakForm(prob, &wf));
39609566063dSJacob Faibussowitsch   PetscCall(PetscDSGetWeakForm(newprob, &newwf));
39619566063dSJacob Faibussowitsch   PetscCall(PetscWeakFormCopy(wf, newwf));
39623ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
39639252d075SMatthew G. Knepley }
396445480ffeSMatthew G. Knepley 
39659252d075SMatthew G. Knepley /*@
3966dce8aebaSBarry Smith   PetscDSCopyConstants - Copy all constants to another `PetscDS`
3967da51fcedSMatthew G. Knepley 
396820f4b53cSBarry Smith   Not Collective
39699252d075SMatthew G. Knepley 
39709252d075SMatthew G. Knepley   Input Parameter:
3971dce8aebaSBarry Smith . prob - The `PetscDS` object
39729252d075SMatthew G. Knepley 
39739252d075SMatthew G. Knepley   Output Parameter:
3974dce8aebaSBarry Smith . newprob - The `PetscDS` copy
39759252d075SMatthew G. Knepley 
39769252d075SMatthew G. Knepley   Level: intermediate
39779252d075SMatthew G. Knepley 
3978dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
39799252d075SMatthew G. Knepley @*/
3980d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
3981d71ae5a4SJacob Faibussowitsch {
39829252d075SMatthew G. Knepley   PetscInt           Nc;
39839252d075SMatthew G. Knepley   const PetscScalar *constants;
39849252d075SMatthew G. Knepley 
39859252d075SMatthew G. Knepley   PetscFunctionBegin;
39869252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
39879252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
39889566063dSJacob Faibussowitsch   PetscCall(PetscDSGetConstants(prob, &Nc, &constants));
39899566063dSJacob Faibussowitsch   PetscCall(PetscDSSetConstants(newprob, Nc, (PetscScalar *)constants));
39903ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3991da51fcedSMatthew G. Knepley }
3992da51fcedSMatthew G. Knepley 
399345480ffeSMatthew G. Knepley /*@
3994dce8aebaSBarry Smith   PetscDSCopyExactSolutions - Copy all exact solutions to another `PetscDS`
399545480ffeSMatthew G. Knepley 
399620f4b53cSBarry Smith   Not Collective
399745480ffeSMatthew G. Knepley 
399845480ffeSMatthew G. Knepley   Input Parameter:
3999dce8aebaSBarry Smith . ds - The `PetscDS` object
400045480ffeSMatthew G. Knepley 
400145480ffeSMatthew G. Knepley   Output Parameter:
4002dce8aebaSBarry Smith . newds - The `PetscDS` copy
400345480ffeSMatthew G. Knepley 
400445480ffeSMatthew G. Knepley   Level: intermediate
400545480ffeSMatthew G. Knepley 
4006dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()`
400745480ffeSMatthew G. Knepley @*/
4008d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds)
4009d71ae5a4SJacob Faibussowitsch {
401045480ffeSMatthew G. Knepley   PetscSimplePointFunc sol;
401145480ffeSMatthew G. Knepley   void                *ctx;
401245480ffeSMatthew G. Knepley   PetscInt             Nf, f;
401345480ffeSMatthew G. Knepley 
401445480ffeSMatthew G. Knepley   PetscFunctionBegin;
401545480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
401645480ffeSMatthew G. Knepley   PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2);
40179566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(ds, &Nf));
401845480ffeSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
40199566063dSJacob Faibussowitsch     PetscCall(PetscDSGetExactSolution(ds, f, &sol, &ctx));
40209566063dSJacob Faibussowitsch     PetscCall(PetscDSSetExactSolution(newds, f, sol, ctx));
40219566063dSJacob Faibussowitsch     PetscCall(PetscDSGetExactSolutionTimeDerivative(ds, f, &sol, &ctx));
40229566063dSJacob Faibussowitsch     PetscCall(PetscDSSetExactSolutionTimeDerivative(newds, f, sol, ctx));
402345480ffeSMatthew G. Knepley   }
40243ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
402545480ffeSMatthew G. Knepley }
402645480ffeSMatthew G. Knepley 
4027*07218a29SMatthew G. Knepley PetscErrorCode PetscDSCopy(PetscDS ds, DM dmNew, PetscDS dsNew)
4028*07218a29SMatthew G. Knepley {
4029*07218a29SMatthew G. Knepley   DSBoundary b;
4030*07218a29SMatthew G. Knepley   PetscInt   cdim, Nf, f, d;
4031*07218a29SMatthew G. Knepley   PetscBool  isCohesive;
4032*07218a29SMatthew G. Knepley   void      *ctx;
4033*07218a29SMatthew G. Knepley 
4034*07218a29SMatthew G. Knepley   PetscFunctionBegin;
4035*07218a29SMatthew G. Knepley   PetscCall(PetscDSCopyConstants(ds, dsNew));
4036*07218a29SMatthew G. Knepley   PetscCall(PetscDSCopyExactSolutions(ds, dsNew));
4037*07218a29SMatthew G. Knepley   PetscCall(PetscDSSelectDiscretizations(ds, PETSC_DETERMINE, NULL, dsNew));
4038*07218a29SMatthew G. Knepley   PetscCall(PetscDSCopyEquations(ds, dsNew));
4039*07218a29SMatthew G. Knepley   PetscCall(PetscDSGetNumFields(ds, &Nf));
4040*07218a29SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
4041*07218a29SMatthew G. Knepley     PetscCall(PetscDSGetContext(ds, f, &ctx));
4042*07218a29SMatthew G. Knepley     PetscCall(PetscDSSetContext(dsNew, f, ctx));
4043*07218a29SMatthew G. Knepley     PetscCall(PetscDSGetCohesive(ds, f, &isCohesive));
4044*07218a29SMatthew G. Knepley     PetscCall(PetscDSSetCohesive(dsNew, f, isCohesive));
4045*07218a29SMatthew G. Knepley     PetscCall(PetscDSGetJetDegree(ds, f, &d));
4046*07218a29SMatthew G. Knepley     PetscCall(PetscDSSetJetDegree(dsNew, f, d));
4047*07218a29SMatthew G. Knepley   }
4048*07218a29SMatthew G. Knepley   if (Nf) {
4049*07218a29SMatthew G. Knepley     PetscCall(PetscDSGetCoordinateDimension(ds, &cdim));
4050*07218a29SMatthew G. Knepley     PetscCall(PetscDSSetCoordinateDimension(dsNew, cdim));
4051*07218a29SMatthew G. Knepley   }
4052*07218a29SMatthew G. Knepley   PetscCall(PetscDSCopyBoundary(ds, PETSC_DETERMINE, NULL, dsNew));
4053*07218a29SMatthew G. Knepley   for (b = dsNew->boundary; b; b = b->next) {
4054*07218a29SMatthew G. Knepley     PetscCall(DMGetLabel(dmNew, b->lname, &b->label));
4055*07218a29SMatthew G. Knepley     /* Do not check if label exists here, since p4est calls this for the reference tree which does not have the labels */
4056*07218a29SMatthew G. Knepley     //PetscCheck(b->label,PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Label %s missing in new DM", name);
4057*07218a29SMatthew G. Knepley   }
4058*07218a29SMatthew G. Knepley   PetscFunctionReturn(PETSC_SUCCESS);
4059*07218a29SMatthew G. Knepley }
4060*07218a29SMatthew G. Knepley 
4061d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
4062d71ae5a4SJacob Faibussowitsch {
4063df3a45bdSMatthew G. Knepley   PetscInt dim, Nf, f;
4064b1353e8eSMatthew G. Knepley 
4065b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
4066b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
4067b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
40689371c9d4SSatish Balay   if (height == 0) {
40699371c9d4SSatish Balay     *subprob = prob;
40703ba16761SJacob Faibussowitsch     PetscFunctionReturn(PETSC_SUCCESS);
40719371c9d4SSatish Balay   }
40729566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(prob, &Nf));
40739566063dSJacob Faibussowitsch   PetscCall(PetscDSGetSpatialDimension(prob, &dim));
407463a3b9bcSJacob 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);
40759566063dSJacob Faibussowitsch   if (!prob->subprobs) PetscCall(PetscCalloc1(dim, &prob->subprobs));
4076df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height - 1]) {
4077b1353e8eSMatthew G. Knepley     PetscInt cdim;
4078b1353e8eSMatthew G. Knepley 
40799566063dSJacob Faibussowitsch     PetscCall(PetscDSCreate(PetscObjectComm((PetscObject)prob), &prob->subprobs[height - 1]));
40809566063dSJacob Faibussowitsch     PetscCall(PetscDSGetCoordinateDimension(prob, &cdim));
40819566063dSJacob Faibussowitsch     PetscCall(PetscDSSetCoordinateDimension(prob->subprobs[height - 1], cdim));
4082b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
4083b1353e8eSMatthew G. Knepley       PetscFE      subfe;
4084b1353e8eSMatthew G. Knepley       PetscObject  obj;
4085b1353e8eSMatthew G. Knepley       PetscClassId id;
4086b1353e8eSMatthew G. Knepley 
40879566063dSJacob Faibussowitsch       PetscCall(PetscDSGetDiscretization(prob, f, &obj));
40889566063dSJacob Faibussowitsch       PetscCall(PetscObjectGetClassId(obj, &id));
40899566063dSJacob Faibussowitsch       if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetHeightSubspace((PetscFE)obj, height, &subfe));
409063a3b9bcSJacob Faibussowitsch       else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %" PetscInt_FMT, f);
40919566063dSJacob Faibussowitsch       PetscCall(PetscDSSetDiscretization(prob->subprobs[height - 1], f, (PetscObject)subfe));
4092b1353e8eSMatthew G. Knepley     }
4093b1353e8eSMatthew G. Knepley   }
4094df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height - 1];
40953ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
4096b1353e8eSMatthew G. Knepley }
4097b1353e8eSMatthew G. Knepley 
4098d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype)
4099d71ae5a4SJacob Faibussowitsch {
4100c7bd5f0bSMatthew G. Knepley   PetscObject  obj;
4101c7bd5f0bSMatthew G. Knepley   PetscClassId id;
4102c7bd5f0bSMatthew G. Knepley   PetscInt     Nf;
4103c7bd5f0bSMatthew G. Knepley 
4104c7bd5f0bSMatthew G. Knepley   PetscFunctionBegin;
4105c7bd5f0bSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
4106665f567fSMatthew G. Knepley   PetscValidPointer(disctype, 3);
4107665f567fSMatthew G. Knepley   *disctype = PETSC_DISC_NONE;
41089566063dSJacob Faibussowitsch   PetscCall(PetscDSGetNumFields(ds, &Nf));
410963a3b9bcSJacob Faibussowitsch   PetscCheck(f < Nf, PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_SIZ, "Field %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, Nf);
41109566063dSJacob Faibussowitsch   PetscCall(PetscDSGetDiscretization(ds, f, &obj));
4111665f567fSMatthew G. Knepley   if (obj) {
41129566063dSJacob Faibussowitsch     PetscCall(PetscObjectGetClassId(obj, &id));
4113665f567fSMatthew G. Knepley     if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE;
4114665f567fSMatthew G. Knepley     else *disctype = PETSC_DISC_FV;
4115665f567fSMatthew G. Knepley   }
41163ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
4117c7bd5f0bSMatthew G. Knepley }
4118c7bd5f0bSMatthew G. Knepley 
4119d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds)
4120d71ae5a4SJacob Faibussowitsch {
41212764a2aaSMatthew G. Knepley   PetscFunctionBegin;
41229566063dSJacob Faibussowitsch   PetscCall(PetscFree(ds->data));
41233ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
41242764a2aaSMatthew G. Knepley }
41252764a2aaSMatthew G. Knepley 
4126d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds)
4127d71ae5a4SJacob Faibussowitsch {
41282764a2aaSMatthew G. Knepley   PetscFunctionBegin;
41296528b96dSMatthew G. Knepley   ds->ops->setfromoptions = NULL;
41306528b96dSMatthew G. Knepley   ds->ops->setup          = NULL;
41316528b96dSMatthew G. Knepley   ds->ops->view           = NULL;
41326528b96dSMatthew G. Knepley   ds->ops->destroy        = PetscDSDestroy_Basic;
41333ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
41342764a2aaSMatthew G. Knepley }
41352764a2aaSMatthew G. Knepley 
41362764a2aaSMatthew G. Knepley /*MC
41372764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
41382764a2aaSMatthew G. Knepley 
41392764a2aaSMatthew G. Knepley   Level: intermediate
41402764a2aaSMatthew G. Knepley 
4141db781477SPatrick Sanan .seealso: `PetscDSType`, `PetscDSCreate()`, `PetscDSSetType()`
41422764a2aaSMatthew G. Knepley M*/
41432764a2aaSMatthew G. Knepley 
4144d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds)
4145d71ae5a4SJacob Faibussowitsch {
41462764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
41472764a2aaSMatthew G. Knepley 
41482764a2aaSMatthew G. Knepley   PetscFunctionBegin;
41496528b96dSMatthew G. Knepley   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
41504dfa11a4SJacob Faibussowitsch   PetscCall(PetscNew(&b));
41516528b96dSMatthew G. Knepley   ds->data = b;
41522764a2aaSMatthew G. Knepley 
41539566063dSJacob Faibussowitsch   PetscCall(PetscDSInitialize_Basic(ds));
41543ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
41552764a2aaSMatthew G. Knepley }
4156