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 242764a2aaSMatthew G. Knepley Not Collective 252764a2aaSMatthew G. Knepley 262764a2aaSMatthew G. Knepley Input Parameters: 272764a2aaSMatthew G. Knepley + name - The name of a new user-defined creation routine 282764a2aaSMatthew G. Knepley - create_func - The creation routine itself 292764a2aaSMatthew G. Knepley 302764a2aaSMatthew G. Knepley 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 Fortran Note: 51f5f57ec0SBarry Smith Not available from Fortran 52f5f57ec0SBarry Smith 53dce8aebaSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscDSRegisterAll()`, `PetscDSRegisterDestroy()` 542764a2aaSMatthew G. Knepley @*/ 55d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS)) 56d71ae5a4SJacob Faibussowitsch { 572764a2aaSMatthew G. Knepley PetscFunctionBegin; 589566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&PetscDSList, sname, function)); 592764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 602764a2aaSMatthew G. Knepley } 612764a2aaSMatthew G. Knepley 622764a2aaSMatthew G. Knepley /*@C 63dce8aebaSBarry Smith PetscDSSetType - Builds a particular `PetscDS` 642764a2aaSMatthew G. Knepley 65d083f849SBarry Smith Collective on prob 662764a2aaSMatthew G. Knepley 672764a2aaSMatthew G. Knepley Input Parameters: 68dce8aebaSBarry Smith + prob - The `PetscDS` object 69dce8aebaSBarry Smith - name - The `PetscDSType` 702764a2aaSMatthew G. Knepley 712764a2aaSMatthew G. Knepley Options Database Key: 722764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types 732764a2aaSMatthew G. Knepley 742764a2aaSMatthew G. Knepley Level: intermediate 752764a2aaSMatthew G. Knepley 76dce8aebaSBarry Smith Fortran Note: 77f5f57ec0SBarry Smith Not available from Fortran 78f5f57ec0SBarry Smith 79dce8aebaSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscDSGetType()`, `PetscDSCreate()` 802764a2aaSMatthew G. Knepley @*/ 81d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name) 82d71ae5a4SJacob Faibussowitsch { 832764a2aaSMatthew G. Knepley PetscErrorCode (*r)(PetscDS); 842764a2aaSMatthew G. Knepley PetscBool match; 852764a2aaSMatthew G. Knepley 862764a2aaSMatthew G. Knepley PetscFunctionBegin; 872764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 889566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)prob, name, &match)); 892764a2aaSMatthew G. Knepley if (match) PetscFunctionReturn(0); 902764a2aaSMatthew G. Knepley 919566063dSJacob Faibussowitsch PetscCall(PetscDSRegisterAll()); 929566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(PetscDSList, name, &r)); 9328b400f6SJacob Faibussowitsch PetscCheck(r, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name); 942764a2aaSMatthew G. Knepley 95dbbe0bcdSBarry Smith PetscTryTypeMethod(prob, destroy); 962764a2aaSMatthew G. Knepley prob->ops->destroy = NULL; 97dbbe0bcdSBarry Smith 989566063dSJacob Faibussowitsch PetscCall((*r)(prob)); 999566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)prob, name)); 1002764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 1012764a2aaSMatthew G. Knepley } 1022764a2aaSMatthew G. Knepley 1032764a2aaSMatthew G. Knepley /*@C 104dce8aebaSBarry Smith PetscDSGetType - Gets the `PetscDSType` name (as a string) from the `PetscDS` 1052764a2aaSMatthew G. Knepley 1062764a2aaSMatthew G. Knepley Not Collective 1072764a2aaSMatthew G. Knepley 1082764a2aaSMatthew G. Knepley Input Parameter: 109dce8aebaSBarry Smith . prob - The `PetscDS` 1102764a2aaSMatthew G. Knepley 1112764a2aaSMatthew G. Knepley Output Parameter: 112dce8aebaSBarry Smith . name - The `PetscDSType` name 1132764a2aaSMatthew G. Knepley 1142764a2aaSMatthew G. Knepley Level: intermediate 1152764a2aaSMatthew G. Knepley 116dce8aebaSBarry Smith Fortran Note: 117f5f57ec0SBarry Smith Not available from Fortran 118f5f57ec0SBarry Smith 119dce8aebaSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscDSSetType()`, `PetscDSCreate()` 1202764a2aaSMatthew G. Knepley @*/ 121d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name) 122d71ae5a4SJacob Faibussowitsch { 1232764a2aaSMatthew G. Knepley PetscFunctionBegin; 1242764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 125c959eef4SJed Brown PetscValidPointer(name, 2); 1269566063dSJacob Faibussowitsch PetscCall(PetscDSRegisterAll()); 1272764a2aaSMatthew G. Knepley *name = ((PetscObject)prob)->type_name; 1282764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 1292764a2aaSMatthew G. Knepley } 1302764a2aaSMatthew G. Knepley 131d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSView_Ascii(PetscDS ds, PetscViewer viewer) 132d71ae5a4SJacob Faibussowitsch { 1337d8a60eaSMatthew G. Knepley PetscViewerFormat format; 13497b6e6e8SMatthew G. Knepley const PetscScalar *constants; 1355fedec97SMatthew G. Knepley PetscInt Nf, numConstants, f; 1367d8a60eaSMatthew G. Knepley 1377d8a60eaSMatthew G. Knepley PetscFunctionBegin; 1389566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 1399566063dSJacob Faibussowitsch PetscCall(PetscViewerGetFormat(viewer, &format)); 14063a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Discrete System with %" PetscInt_FMT " fields\n", Nf)); 1419566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 14263a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " cell total dim %" PetscInt_FMT " total comp %" PetscInt_FMT "\n", ds->totDim, ds->totComp)); 1439566063dSJacob Faibussowitsch if (ds->isCohesive) PetscCall(PetscViewerASCIIPrintf(viewer, " cohesive cell\n")); 1445fedec97SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 14540967b3bSMatthew G. Knepley DSBoundary b; 1467d8a60eaSMatthew G. Knepley PetscObject obj; 1477d8a60eaSMatthew G. Knepley PetscClassId id; 148f35450b9SMatthew G. Knepley PetscQuadrature q; 1497d8a60eaSMatthew G. Knepley const char *name; 150f35450b9SMatthew G. Knepley PetscInt Nc, Nq, Nqc; 1517d8a60eaSMatthew G. Knepley 1529566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, f, &obj)); 1539566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 1549566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName(obj, &name)); 1559566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>")); 1569566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE)); 1577d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 1589566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents((PetscFE)obj, &Nc)); 1599566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature((PetscFE)obj, &q)); 1609566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " FEM")); 1617d8a60eaSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 1629566063dSJacob Faibussowitsch PetscCall(PetscFVGetNumComponents((PetscFV)obj, &Nc)); 1639566063dSJacob Faibussowitsch PetscCall(PetscFVGetQuadrature((PetscFV)obj, &q)); 1649566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " FVM")); 1659371c9d4SSatish Balay } else SETERRQ(PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %" PetscInt_FMT, f); 16663a3b9bcSJacob Faibussowitsch if (Nc > 1) PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT " components", Nc)); 16763a3b9bcSJacob Faibussowitsch else PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT " component ", Nc)); 1689566063dSJacob Faibussowitsch if (ds->implicit[f]) PetscCall(PetscViewerASCIIPrintf(viewer, " (implicit)")); 1699566063dSJacob Faibussowitsch else PetscCall(PetscViewerASCIIPrintf(viewer, " (explicit)")); 1703e60c2a6SMatthew G. Knepley if (q) { 1719566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL)); 17263a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " (Nq %" PetscInt_FMT " Nqc %" PetscInt_FMT ")", Nq, Nqc)); 1733e60c2a6SMatthew G. Knepley } 17463a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT "-jet", ds->jetDegree[f])); 1759566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "\n")); 1769566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE)); 1779566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 1789566063dSJacob Faibussowitsch if (id == PETSCFE_CLASSID) PetscCall(PetscFEView((PetscFE)obj, viewer)); 1799566063dSJacob Faibussowitsch else if (id == PETSCFV_CLASSID) PetscCall(PetscFVView((PetscFV)obj, viewer)); 1809566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 18140967b3bSMatthew G. Knepley 1825fedec97SMatthew G. Knepley for (b = ds->boundary; b; b = b->next) { 18306ad1575SMatthew G. Knepley char *name; 18440967b3bSMatthew G. Knepley PetscInt c, i; 18540967b3bSMatthew G. Knepley 18640967b3bSMatthew G. Knepley if (b->field != f) continue; 1879566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 1889566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->lname, DMBoundaryConditionTypes[b->type])); 18945480ffeSMatthew G. Knepley if (!b->Nc) { 1909566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " all components\n")); 19140967b3bSMatthew G. Knepley } else { 1929566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " components: ")); 1939566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE)); 19445480ffeSMatthew G. Knepley for (c = 0; c < b->Nc; ++c) { 1959566063dSJacob Faibussowitsch if (c > 0) PetscCall(PetscViewerASCIIPrintf(viewer, ", ")); 19663a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT, b->comps[c])); 19740967b3bSMatthew G. Knepley } 1989566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "\n")); 1999566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE)); 20040967b3bSMatthew G. Knepley } 2019566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " values: ")); 2029566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE)); 20345480ffeSMatthew G. Knepley for (i = 0; i < b->Nv; ++i) { 2049566063dSJacob Faibussowitsch if (i > 0) PetscCall(PetscViewerASCIIPrintf(viewer, ", ")); 20563a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT, b->values[i])); 20640967b3bSMatthew G. Knepley } 2079566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "\n")); 2089566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE)); 209*15943bb8SPierre Jolivet #if defined(__clang__) 210*15943bb8SPierre Jolivet #pragma clang diagnostic push 211*15943bb8SPierre Jolivet #pragma clang diagnostic ignored "-Wformat-pedantic" 212*15943bb8SPierre Jolivet #elif defined(__GNUC__) || defined(__GNUG__) 213*15943bb8SPierre Jolivet #pragma GCC diagnostic push 214*15943bb8SPierre Jolivet #pragma GCC diagnostic ignored "-Wformat" 215*15943bb8SPierre Jolivet #endif 2168e0d8d9cSMatthew G. Knepley if (b->func) { 2179566063dSJacob Faibussowitsch PetscCall(PetscDLAddr(b->func, &name)); 2189566063dSJacob Faibussowitsch if (name) PetscCall(PetscViewerASCIIPrintf(viewer, " func: %s\n", name)); 2199566063dSJacob Faibussowitsch else PetscCall(PetscViewerASCIIPrintf(viewer, " func: %p\n", b->func)); 2209566063dSJacob Faibussowitsch PetscCall(PetscFree(name)); 2218e0d8d9cSMatthew G. Knepley } 2228e0d8d9cSMatthew G. Knepley if (b->func_t) { 2239566063dSJacob Faibussowitsch PetscCall(PetscDLAddr(b->func_t, &name)); 2249566063dSJacob Faibussowitsch if (name) PetscCall(PetscViewerASCIIPrintf(viewer, " func_t: %s\n", name)); 2259566063dSJacob Faibussowitsch else PetscCall(PetscViewerASCIIPrintf(viewer, " func_t: %p\n", b->func_t)); 2269566063dSJacob Faibussowitsch PetscCall(PetscFree(name)); 2278e0d8d9cSMatthew G. Knepley } 228*15943bb8SPierre Jolivet #if defined(__clang__) 229*15943bb8SPierre Jolivet #pragma clang diagnostic pop 230*15943bb8SPierre Jolivet #elif defined(__GNUC__) || defined(__GNUG__) 231*15943bb8SPierre Jolivet #pragma GCC diagnostic pop 232*15943bb8SPierre Jolivet #endif 2339566063dSJacob Faibussowitsch PetscCall(PetscWeakFormView(b->wf, viewer)); 2349566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 23540967b3bSMatthew G. Knepley } 2367d8a60eaSMatthew G. Knepley } 2379566063dSJacob Faibussowitsch PetscCall(PetscDSGetConstants(ds, &numConstants, &constants)); 23897b6e6e8SMatthew G. Knepley if (numConstants) { 23963a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " constants\n", numConstants)); 2409566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 2419566063dSJacob Faibussowitsch for (f = 0; f < numConstants; ++f) PetscCall(PetscViewerASCIIPrintf(viewer, "%g\n", (double)PetscRealPart(constants[f]))); 2429566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 24397b6e6e8SMatthew G. Knepley } 2449566063dSJacob Faibussowitsch PetscCall(PetscWeakFormView(ds->wf, viewer)); 2459566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 2467d8a60eaSMatthew G. Knepley PetscFunctionReturn(0); 2477d8a60eaSMatthew G. Knepley } 2487d8a60eaSMatthew G. Knepley 2492764a2aaSMatthew G. Knepley /*@C 250dce8aebaSBarry Smith PetscDSViewFromOptions - View a `PetscDS` based on values in the options database 251fe2efc57SMark 252fe2efc57SMark Collective on PetscDS 253fe2efc57SMark 254fe2efc57SMark Input Parameters: 255dce8aebaSBarry Smith + A - the `PetscDS` object 256736c3998SJose E. Roman . obj - Optional object 257736c3998SJose E. Roman - name - command line option 258fe2efc57SMark 259fe2efc57SMark Level: intermediate 260dce8aebaSBarry Smith 261dce8aebaSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscDSView()`, `PetscObjectViewFromOptions()`, `PetscDSCreate()` 262fe2efc57SMark @*/ 263d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSViewFromOptions(PetscDS A, PetscObject obj, const char name[]) 264d71ae5a4SJacob Faibussowitsch { 265fe2efc57SMark PetscFunctionBegin; 266fe2efc57SMark PetscValidHeaderSpecific(A, PETSCDS_CLASSID, 1); 2679566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name)); 268fe2efc57SMark PetscFunctionReturn(0); 269fe2efc57SMark } 270fe2efc57SMark 271fe2efc57SMark /*@C 272dce8aebaSBarry Smith PetscDSView - Views a `PetscDS` 2732764a2aaSMatthew G. Knepley 274d083f849SBarry Smith Collective on prob 2752764a2aaSMatthew G. Knepley 276d8d19677SJose E. Roman Input Parameters: 277dce8aebaSBarry Smith + prob - the `PetscDS` object to view 2782764a2aaSMatthew G. Knepley - v - the viewer 2792764a2aaSMatthew G. Knepley 2802764a2aaSMatthew G. Knepley Level: developer 2812764a2aaSMatthew G. Knepley 282dce8aebaSBarry Smith .seealso: `PetscDSType`, `PetscDS`, `PetscViewer`, `PetscDSDestroy()` 2832764a2aaSMatthew G. Knepley @*/ 284d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v) 285d71ae5a4SJacob Faibussowitsch { 2867d8a60eaSMatthew G. Knepley PetscBool iascii; 2872764a2aaSMatthew G. Knepley 2882764a2aaSMatthew G. Knepley PetscFunctionBegin; 2892764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2909566063dSJacob Faibussowitsch if (!v) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)prob), &v)); 291ad540459SPierre Jolivet else PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2); 2929566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)v, PETSCVIEWERASCII, &iascii)); 2939566063dSJacob Faibussowitsch if (iascii) PetscCall(PetscDSView_Ascii(prob, v)); 294dbbe0bcdSBarry Smith PetscTryTypeMethod(prob, view, v); 2952764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 2962764a2aaSMatthew G. Knepley } 2972764a2aaSMatthew G. Knepley 2982764a2aaSMatthew G. Knepley /*@ 299dce8aebaSBarry Smith PetscDSSetFromOptions - sets parameters in a `PetscDS` from the options database 3002764a2aaSMatthew G. Knepley 301d083f849SBarry Smith Collective on prob 3022764a2aaSMatthew G. Knepley 3032764a2aaSMatthew G. Knepley Input Parameter: 304dce8aebaSBarry Smith . prob - the `PetscDS` object to set options for 3052764a2aaSMatthew G. Knepley 306dce8aebaSBarry Smith Options Database Keys: 307dce8aebaSBarry Smith + -petscds_type <type> - Set the `PetscDS` type 308dce8aebaSBarry Smith . -petscds_view <view opt> - View the `PetscDS` 309147403d9SBarry Smith . -petscds_jac_pre - Turn formation of a separate Jacobian preconditioner on or off 310147403d9SBarry Smith . -bc_<name> <ids> - Specify a list of label ids for a boundary condition 311147403d9SBarry Smith - -bc_<name>_comp <comps> - Specify a list of field components to constrain for a boundary condition 3122764a2aaSMatthew G. Knepley 313dce8aebaSBarry Smith Level: intermediate 3142764a2aaSMatthew G. Knepley 315dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSView()` 3162764a2aaSMatthew G. Knepley @*/ 317d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetFromOptions(PetscDS prob) 318d71ae5a4SJacob Faibussowitsch { 319f1fd5e65SToby Isaac DSBoundary b; 3202764a2aaSMatthew G. Knepley const char *defaultType; 3212764a2aaSMatthew G. Knepley char name[256]; 3222764a2aaSMatthew G. Knepley PetscBool flg; 3232764a2aaSMatthew G. Knepley 3242764a2aaSMatthew G. Knepley PetscFunctionBegin; 3252764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3262764a2aaSMatthew G. Knepley if (!((PetscObject)prob)->type_name) { 3272764a2aaSMatthew G. Knepley defaultType = PETSCDSBASIC; 3282764a2aaSMatthew G. Knepley } else { 3292764a2aaSMatthew G. Knepley defaultType = ((PetscObject)prob)->type_name; 3302764a2aaSMatthew G. Knepley } 3319566063dSJacob Faibussowitsch PetscCall(PetscDSRegisterAll()); 3322764a2aaSMatthew G. Knepley 333d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject)prob); 334f1fd5e65SToby Isaac for (b = prob->boundary; b; b = b->next) { 335f1fd5e65SToby Isaac char optname[1024]; 336f1fd5e65SToby Isaac PetscInt ids[1024], len = 1024; 337f1fd5e65SToby Isaac PetscBool flg; 338f1fd5e65SToby Isaac 3399566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name)); 3409566063dSJacob Faibussowitsch PetscCall(PetscMemzero(ids, sizeof(ids))); 3419566063dSJacob Faibussowitsch PetscCall(PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg)); 342f1fd5e65SToby Isaac if (flg) { 34345480ffeSMatthew G. Knepley b->Nv = len; 3449566063dSJacob Faibussowitsch PetscCall(PetscFree(b->values)); 3459566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(len, &b->values)); 3469566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(b->values, ids, len)); 3479566063dSJacob Faibussowitsch PetscCall(PetscWeakFormRewriteKeys(b->wf, b->label, len, b->values)); 348f1fd5e65SToby Isaac } 349e7b0402cSSander Arens len = 1024; 3509566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name)); 3519566063dSJacob Faibussowitsch PetscCall(PetscMemzero(ids, sizeof(ids))); 3529566063dSJacob Faibussowitsch PetscCall(PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg)); 353f1fd5e65SToby Isaac if (flg) { 35445480ffeSMatthew G. Knepley b->Nc = len; 3559566063dSJacob Faibussowitsch PetscCall(PetscFree(b->comps)); 3569566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(len, &b->comps)); 3579566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(b->comps, ids, len)); 358f1fd5e65SToby Isaac } 359f1fd5e65SToby Isaac } 3609566063dSJacob Faibussowitsch PetscCall(PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg)); 3612764a2aaSMatthew G. Knepley if (flg) { 3629566063dSJacob Faibussowitsch PetscCall(PetscDSSetType(prob, name)); 3632764a2aaSMatthew G. Knepley } else if (!((PetscObject)prob)->type_name) { 3649566063dSJacob Faibussowitsch PetscCall(PetscDSSetType(prob, defaultType)); 3652764a2aaSMatthew G. Knepley } 3669566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg)); 367dbbe0bcdSBarry Smith PetscTryTypeMethod(prob, setfromoptions); 3682764a2aaSMatthew G. Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 369dbbe0bcdSBarry Smith PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)prob, PetscOptionsObject)); 370d0609cedSBarry Smith PetscOptionsEnd(); 3719566063dSJacob Faibussowitsch if (prob->Nf) PetscCall(PetscDSViewFromOptions(prob, NULL, "-petscds_view")); 3722764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 3732764a2aaSMatthew G. Knepley } 3742764a2aaSMatthew G. Knepley 3752764a2aaSMatthew G. Knepley /*@C 376dce8aebaSBarry Smith PetscDSSetUp - Construct data structures for the `PetscDS` 3772764a2aaSMatthew G. Knepley 378d083f849SBarry Smith Collective on prob 3792764a2aaSMatthew G. Knepley 3802764a2aaSMatthew G. Knepley Input Parameter: 381dce8aebaSBarry Smith . prob - the `PetscDS` object to setup 3822764a2aaSMatthew G. Knepley 3832764a2aaSMatthew G. Knepley Level: developer 3842764a2aaSMatthew G. Knepley 385dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSView()`, `PetscDSDestroy()` 3862764a2aaSMatthew G. Knepley @*/ 387d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetUp(PetscDS prob) 388d71ae5a4SJacob Faibussowitsch { 3892764a2aaSMatthew G. Knepley const PetscInt Nf = prob->Nf; 390f9244615SMatthew G. Knepley PetscBool hasH = PETSC_FALSE; 3914bee2e38SMatthew G. Knepley PetscInt dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f; 3922764a2aaSMatthew G. Knepley 3932764a2aaSMatthew G. Knepley PetscFunctionBegin; 3942764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3952764a2aaSMatthew G. Knepley if (prob->setup) PetscFunctionReturn(0); 3962764a2aaSMatthew G. Knepley /* Calculate sizes */ 3979566063dSJacob Faibussowitsch PetscCall(PetscDSGetSpatialDimension(prob, &dim)); 3989566063dSJacob Faibussowitsch PetscCall(PetscDSGetCoordinateDimension(prob, &dimEmbed)); 399f744cafaSSander Arens prob->totDim = prob->totComp = 0; 4009566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(Nf, &prob->Nc, Nf, &prob->Nb)); 4019566063dSJacob Faibussowitsch PetscCall(PetscCalloc2(Nf + 1, &prob->off, Nf + 1, &prob->offDer)); 4029566063dSJacob 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])); 4039566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(Nf, &prob->T, Nf, &prob->Tf)); 4042764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 4059de99aefSMatthew G. Knepley PetscObject obj; 4069de99aefSMatthew G. Knepley PetscClassId id; 407665f567fSMatthew G. Knepley PetscQuadrature q = NULL; 4089de99aefSMatthew G. Knepley PetscInt Nq = 0, Nb, Nc; 4092764a2aaSMatthew G. Knepley 4109566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, f, &obj)); 411f9244615SMatthew G. Knepley if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE; 412665f567fSMatthew G. Knepley if (!obj) { 413665f567fSMatthew G. Knepley /* Empty mesh */ 414665f567fSMatthew G. Knepley Nb = Nc = 0; 415665f567fSMatthew G. Knepley prob->T[f] = prob->Tf[f] = NULL; 416665f567fSMatthew G. Knepley } else { 4179566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 4189de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 4199de99aefSMatthew G. Knepley PetscFE fe = (PetscFE)obj; 4209de99aefSMatthew G. Knepley 4219566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &q)); 4229566063dSJacob Faibussowitsch PetscCall(PetscFEGetDimension(fe, &Nb)); 4239566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &Nc)); 4249566063dSJacob Faibussowitsch PetscCall(PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f])); 4259566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f])); 4269de99aefSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 4279de99aefSMatthew G. Knepley PetscFV fv = (PetscFV)obj; 4289de99aefSMatthew G. Knepley 4299566063dSJacob Faibussowitsch PetscCall(PetscFVGetQuadrature(fv, &q)); 4309566063dSJacob Faibussowitsch PetscCall(PetscFVGetNumComponents(fv, &Nc)); 4319c3cf19fSMatthew G. Knepley Nb = Nc; 4329566063dSJacob Faibussowitsch PetscCall(PetscFVGetCellTabulation(fv, &prob->T[f])); 4334d0b9603SSander Arens /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */ 43463a3b9bcSJacob Faibussowitsch } else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %" PetscInt_FMT, f); 435665f567fSMatthew G. Knepley } 43647e57110SSander Arens prob->Nc[f] = Nc; 43747e57110SSander Arens prob->Nb[f] = Nb; 438194d53e6SMatthew G. Knepley prob->off[f + 1] = Nc + prob->off[f]; 439194d53e6SMatthew G. Knepley prob->offDer[f + 1] = Nc * dim + prob->offDer[f]; 4409ee2af8cSMatthew G. Knepley prob->offCohesive[0][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) + prob->offCohesive[0][f]; 4419ee2af8cSMatthew G. Knepley prob->offDerCohesive[0][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) * dimEmbed + prob->offDerCohesive[0][f]; 4429ee2af8cSMatthew G. Knepley prob->offCohesive[1][f] = (prob->cohesive[f] ? 0 : Nc) + prob->offCohesive[0][f]; 4439ee2af8cSMatthew G. Knepley prob->offDerCohesive[1][f] = (prob->cohesive[f] ? 0 : Nc) * dimEmbed + prob->offDerCohesive[0][f]; 4449ee2af8cSMatthew G. Knepley prob->offCohesive[2][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) + prob->offCohesive[2][f]; 4459ee2af8cSMatthew G. Knepley prob->offDerCohesive[2][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) * dimEmbed + prob->offDerCohesive[2][f]; 4469566063dSJacob Faibussowitsch if (q) PetscCall(PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL)); 4472764a2aaSMatthew G. Knepley NqMax = PetscMax(NqMax, Nq); 4484bee2e38SMatthew G. Knepley NbMax = PetscMax(NbMax, Nb); 4492764a2aaSMatthew G. Knepley NcMax = PetscMax(NcMax, Nc); 4509c3cf19fSMatthew G. Knepley prob->totDim += Nb; 4512764a2aaSMatthew G. Knepley prob->totComp += Nc; 4525fedec97SMatthew G. Knepley /* There are two faces for all fields on a cohesive cell, except for cohesive fields */ 4535fedec97SMatthew G. Knepley if (prob->isCohesive && !prob->cohesive[f]) prob->totDim += Nb; 4542764a2aaSMatthew G. Knepley } 4559ee2af8cSMatthew G. Knepley prob->offCohesive[1][Nf] = prob->offCohesive[0][Nf]; 4569ee2af8cSMatthew G. Knepley prob->offDerCohesive[1][Nf] = prob->offDerCohesive[0][Nf]; 4572764a2aaSMatthew G. Knepley /* Allocate works space */ 4585fedec97SMatthew G. Knepley NsMax = 2; /* A non-cohesive discretizations can be used on a cohesive cell, so we need this extra workspace for all DS */ 4599566063dSJacob 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)); 4609566063dSJacob Faibussowitsch PetscCall(PetscMalloc5(dimEmbed, &prob->x, NbMax * NcMax, &prob->basisReal, NbMax * NcMax * dimEmbed, &prob->basisDerReal, NbMax * NcMax, &prob->testReal, NbMax * NcMax * dimEmbed, &prob->testDerReal)); 4619371c9d4SSatish 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, 4629371c9d4SSatish Balay &prob->g2, NsMax * NsMax * NqMax * NcMax * NcMax * dimEmbed * dimEmbed, &prob->g3)); 463dbbe0bcdSBarry Smith PetscTryTypeMethod(prob, setup); 4642764a2aaSMatthew G. Knepley prob->setup = PETSC_TRUE; 4652764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4662764a2aaSMatthew G. Knepley } 4672764a2aaSMatthew G. Knepley 468d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob) 469d71ae5a4SJacob Faibussowitsch { 4702764a2aaSMatthew G. Knepley PetscFunctionBegin; 4719566063dSJacob Faibussowitsch PetscCall(PetscFree2(prob->Nc, prob->Nb)); 4729566063dSJacob Faibussowitsch PetscCall(PetscFree2(prob->off, prob->offDer)); 4739566063dSJacob Faibussowitsch PetscCall(PetscFree6(prob->offCohesive[0], prob->offCohesive[1], prob->offCohesive[2], prob->offDerCohesive[0], prob->offDerCohesive[1], prob->offDerCohesive[2])); 4749566063dSJacob Faibussowitsch PetscCall(PetscFree2(prob->T, prob->Tf)); 4759566063dSJacob Faibussowitsch PetscCall(PetscFree3(prob->u, prob->u_t, prob->u_x)); 4769566063dSJacob Faibussowitsch PetscCall(PetscFree5(prob->x, prob->basisReal, prob->basisDerReal, prob->testReal, prob->testDerReal)); 4779566063dSJacob Faibussowitsch PetscCall(PetscFree6(prob->f0, prob->f1, prob->g0, prob->g1, prob->g2, prob->g3)); 4782764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4792764a2aaSMatthew G. Knepley } 4802764a2aaSMatthew G. Knepley 481d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew) 482d71ae5a4SJacob Faibussowitsch { 483f744cafaSSander Arens PetscObject *tmpd; 48434aa8a36SMatthew G. Knepley PetscBool *tmpi; 485f9244615SMatthew G. Knepley PetscInt *tmpk; 4865fedec97SMatthew G. Knepley PetscBool *tmpc; 4876528b96dSMatthew G. Knepley PetscPointFunc *tmpup; 488f2cacb80SMatthew G. Knepley PetscSimplePointFunc *tmpexactSol, *tmpexactSol_t; 489f2cacb80SMatthew G. Knepley void **tmpexactCtx, **tmpexactCtx_t; 4900c2f2876SMatthew G. Knepley void **tmpctx; 49134aa8a36SMatthew G. Knepley PetscInt Nf = prob->Nf, f; 4922764a2aaSMatthew G. Knepley 4932764a2aaSMatthew G. Knepley PetscFunctionBegin; 4942764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 4952764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 4969566063dSJacob Faibussowitsch PetscCall(PetscDSDestroyStructs_Static(prob)); 4979566063dSJacob Faibussowitsch PetscCall(PetscMalloc4(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpc, NfNew, &tmpk)); 4989371c9d4SSatish Balay for (f = 0; f < Nf; ++f) { 4999371c9d4SSatish Balay tmpd[f] = prob->disc[f]; 5009371c9d4SSatish Balay tmpi[f] = prob->implicit[f]; 5019371c9d4SSatish Balay tmpc[f] = prob->cohesive[f]; 5029371c9d4SSatish Balay tmpk[f] = prob->jetDegree[f]; 5039371c9d4SSatish Balay } 5049371c9d4SSatish Balay for (f = Nf; f < NfNew; ++f) { 5059371c9d4SSatish Balay tmpd[f] = NULL; 5069371c9d4SSatish Balay tmpi[f] = PETSC_TRUE, tmpc[f] = PETSC_FALSE; 5079371c9d4SSatish Balay tmpk[f] = 1; 5089371c9d4SSatish Balay } 5099566063dSJacob Faibussowitsch PetscCall(PetscFree4(prob->disc, prob->implicit, prob->cohesive, prob->jetDegree)); 5109566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetNumFields(prob->wf, NfNew)); 5112764a2aaSMatthew G. Knepley prob->Nf = NfNew; 5122764a2aaSMatthew G. Knepley prob->disc = tmpd; 513249df284SMatthew G. Knepley prob->implicit = tmpi; 5145fedec97SMatthew G. Knepley prob->cohesive = tmpc; 515f9244615SMatthew G. Knepley prob->jetDegree = tmpk; 5169566063dSJacob Faibussowitsch PetscCall(PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx)); 51732d2bbc9SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f]; 5180c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f]; 51932d2bbc9SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL; 5200c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL; 5219566063dSJacob Faibussowitsch PetscCall(PetscFree2(prob->update, prob->ctx)); 52232d2bbc9SMatthew G. Knepley prob->update = tmpup; 5230c2f2876SMatthew G. Knepley prob->ctx = tmpctx; 5249566063dSJacob Faibussowitsch PetscCall(PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t)); 525c371a6d1SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f]; 52695cbbfd3SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f]; 527f2cacb80SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f]; 528f2cacb80SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f]; 529c371a6d1SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL; 53095cbbfd3SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL; 531f2cacb80SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL; 532f2cacb80SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL; 5339566063dSJacob Faibussowitsch PetscCall(PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t)); 534c371a6d1SMatthew G. Knepley prob->exactSol = tmpexactSol; 53595cbbfd3SMatthew G. Knepley prob->exactCtx = tmpexactCtx; 536f2cacb80SMatthew G. Knepley prob->exactSol_t = tmpexactSol_t; 537f2cacb80SMatthew G. Knepley prob->exactCtx_t = tmpexactCtx_t; 5382764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5392764a2aaSMatthew G. Knepley } 5402764a2aaSMatthew G. Knepley 5412764a2aaSMatthew G. Knepley /*@ 5422764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 5432764a2aaSMatthew G. Knepley 544d083f849SBarry Smith Collective on prob 5452764a2aaSMatthew G. Knepley 5462764a2aaSMatthew G. Knepley Input Parameter: 5472764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 5482764a2aaSMatthew G. Knepley 5492764a2aaSMatthew G. Knepley Level: developer 5502764a2aaSMatthew G. Knepley 551dce8aebaSBarry Smith .seealso: `PetscDSView()` 5522764a2aaSMatthew G. Knepley @*/ 553d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSDestroy(PetscDS *ds) 554d71ae5a4SJacob Faibussowitsch { 5552764a2aaSMatthew G. Knepley PetscInt f; 5562764a2aaSMatthew G. Knepley 5572764a2aaSMatthew G. Knepley PetscFunctionBegin; 5586528b96dSMatthew G. Knepley if (!*ds) PetscFunctionReturn(0); 5596528b96dSMatthew G. Knepley PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1); 5602764a2aaSMatthew G. Knepley 5619371c9d4SSatish Balay if (--((PetscObject)(*ds))->refct > 0) { 5629371c9d4SSatish Balay *ds = NULL; 5639371c9d4SSatish Balay PetscFunctionReturn(0); 5649371c9d4SSatish Balay } 5656528b96dSMatthew G. Knepley ((PetscObject)(*ds))->refct = 0; 5666528b96dSMatthew G. Knepley if ((*ds)->subprobs) { 567df3a45bdSMatthew G. Knepley PetscInt dim, d; 568df3a45bdSMatthew G. Knepley 5699566063dSJacob Faibussowitsch PetscCall(PetscDSGetSpatialDimension(*ds, &dim)); 5709566063dSJacob Faibussowitsch for (d = 0; d < dim; ++d) PetscCall(PetscDSDestroy(&(*ds)->subprobs[d])); 571df3a45bdSMatthew G. Knepley } 5729566063dSJacob Faibussowitsch PetscCall(PetscFree((*ds)->subprobs)); 5739566063dSJacob Faibussowitsch PetscCall(PetscDSDestroyStructs_Static(*ds)); 57448a46eb9SPierre Jolivet for (f = 0; f < (*ds)->Nf; ++f) PetscCall(PetscObjectDereference((*ds)->disc[f])); 5759566063dSJacob Faibussowitsch PetscCall(PetscFree4((*ds)->disc, (*ds)->implicit, (*ds)->cohesive, (*ds)->jetDegree)); 5769566063dSJacob Faibussowitsch PetscCall(PetscWeakFormDestroy(&(*ds)->wf)); 5779566063dSJacob Faibussowitsch PetscCall(PetscFree2((*ds)->update, (*ds)->ctx)); 5789566063dSJacob Faibussowitsch PetscCall(PetscFree4((*ds)->exactSol, (*ds)->exactCtx, (*ds)->exactSol_t, (*ds)->exactCtx_t)); 579dbbe0bcdSBarry Smith PetscTryTypeMethod((*ds), destroy); 5809566063dSJacob Faibussowitsch PetscCall(PetscDSDestroyBoundary(*ds)); 5819566063dSJacob Faibussowitsch PetscCall(PetscFree((*ds)->constants)); 5829566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(ds)); 5832764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5842764a2aaSMatthew G. Knepley } 5852764a2aaSMatthew G. Knepley 5862764a2aaSMatthew G. Knepley /*@ 587dce8aebaSBarry Smith PetscDSCreate - Creates an empty `PetscDS` object. The type can then be set with `PetscDSSetType()`. 5882764a2aaSMatthew G. Knepley 589d083f849SBarry Smith Collective 5902764a2aaSMatthew G. Knepley 5912764a2aaSMatthew G. Knepley Input Parameter: 592dce8aebaSBarry Smith . comm - The communicator for the `PetscDS` object 5932764a2aaSMatthew G. Knepley 5942764a2aaSMatthew G. Knepley Output Parameter: 595dce8aebaSBarry Smith . ds - The `PetscDS` object 5962764a2aaSMatthew G. Knepley 5972764a2aaSMatthew G. Knepley Level: beginner 5982764a2aaSMatthew G. Knepley 599dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetType()`, `PETSCDSBASIC`, `PetscDSType` 6002764a2aaSMatthew G. Knepley @*/ 601d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds) 602d71ae5a4SJacob Faibussowitsch { 6032764a2aaSMatthew G. Knepley PetscDS p; 6042764a2aaSMatthew G. Knepley 6052764a2aaSMatthew G. Knepley PetscFunctionBegin; 6066528b96dSMatthew G. Knepley PetscValidPointer(ds, 2); 6076528b96dSMatthew G. Knepley *ds = NULL; 6089566063dSJacob Faibussowitsch PetscCall(PetscDSInitializePackage()); 6092764a2aaSMatthew G. Knepley 6109566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView)); 6112764a2aaSMatthew G. Knepley 6122764a2aaSMatthew G. Knepley p->Nf = 0; 6132764a2aaSMatthew G. Knepley p->setup = PETSC_FALSE; 61497b6e6e8SMatthew G. Knepley p->numConstants = 0; 61597b6e6e8SMatthew G. Knepley p->constants = NULL; 616a859676bSMatthew G. Knepley p->dimEmbed = -1; 61755c1f793SMatthew G. Knepley p->useJacPre = PETSC_TRUE; 6189566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCreate(comm, &p->wf)); 6192764a2aaSMatthew G. Knepley 6206528b96dSMatthew G. Knepley *ds = p; 6212764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6222764a2aaSMatthew G. Knepley } 6232764a2aaSMatthew G. Knepley 624bc4ae4beSMatthew G. Knepley /*@ 625dce8aebaSBarry Smith PetscDSGetNumFields - Returns the number of fields in the `PetscDS` 626bc4ae4beSMatthew G. Knepley 627bc4ae4beSMatthew G. Knepley Not collective 628bc4ae4beSMatthew G. Knepley 629bc4ae4beSMatthew G. Knepley Input Parameter: 630bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 631bc4ae4beSMatthew G. Knepley 632bc4ae4beSMatthew G. Knepley Output Parameter: 633bc4ae4beSMatthew G. Knepley . Nf - The number of fields 634bc4ae4beSMatthew G. Knepley 635bc4ae4beSMatthew G. Knepley Level: beginner 636bc4ae4beSMatthew G. Knepley 637dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetSpatialDimension()`, `PetscDSCreate()` 638bc4ae4beSMatthew G. Knepley @*/ 639d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) 640d71ae5a4SJacob Faibussowitsch { 6412764a2aaSMatthew G. Knepley PetscFunctionBegin; 6422764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 643dadcf809SJacob Faibussowitsch PetscValidIntPointer(Nf, 2); 6442764a2aaSMatthew G. Knepley *Nf = prob->Nf; 6452764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6462764a2aaSMatthew G. Knepley } 6472764a2aaSMatthew G. Knepley 648bc4ae4beSMatthew G. Knepley /*@ 649dce8aebaSBarry Smith PetscDSGetSpatialDimension - Returns the spatial dimension of the `PetscDS`, meaning the topological dimension of the discretizations 650bc4ae4beSMatthew G. Knepley 651bc4ae4beSMatthew G. Knepley Not collective 652bc4ae4beSMatthew G. Knepley 653bc4ae4beSMatthew G. Knepley Input Parameter: 654dce8aebaSBarry Smith . prob - The `PetscDS` object 655bc4ae4beSMatthew G. Knepley 656bc4ae4beSMatthew G. Knepley Output Parameter: 657bc4ae4beSMatthew G. Knepley . dim - The spatial dimension 658bc4ae4beSMatthew G. Knepley 659bc4ae4beSMatthew G. Knepley Level: beginner 660bc4ae4beSMatthew G. Knepley 661dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetCoordinateDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 662bc4ae4beSMatthew G. Knepley @*/ 663d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) 664d71ae5a4SJacob Faibussowitsch { 6652764a2aaSMatthew G. Knepley PetscFunctionBegin; 6662764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 667dadcf809SJacob Faibussowitsch PetscValidIntPointer(dim, 2); 6682764a2aaSMatthew G. Knepley *dim = 0; 6699de99aefSMatthew G. Knepley if (prob->Nf) { 6709de99aefSMatthew G. Knepley PetscObject obj; 6719de99aefSMatthew G. Knepley PetscClassId id; 6729de99aefSMatthew G. Knepley 6739566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, 0, &obj)); 674665f567fSMatthew G. Knepley if (obj) { 6759566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 6769566063dSJacob Faibussowitsch if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetSpatialDimension((PetscFE)obj, dim)); 6779566063dSJacob Faibussowitsch else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetSpatialDimension((PetscFV)obj, dim)); 67898921bdaSJacob Faibussowitsch else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 6799de99aefSMatthew G. Knepley } 680665f567fSMatthew G. Knepley } 6812764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6822764a2aaSMatthew G. Knepley } 6832764a2aaSMatthew G. Knepley 684bc4ae4beSMatthew G. Knepley /*@ 685dce8aebaSBarry Smith PetscDSGetCoordinateDimension - Returns the coordinate dimension of the `PetscDS`, meaning the dimension of the space into which the discretiaztions are embedded 686a859676bSMatthew G. Knepley 687a859676bSMatthew G. Knepley Not collective 688a859676bSMatthew G. Knepley 689a859676bSMatthew G. Knepley Input Parameter: 690dce8aebaSBarry Smith . prob - The `PetscDS` object 691a859676bSMatthew G. Knepley 692a859676bSMatthew G. Knepley Output Parameter: 693a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension 694a859676bSMatthew G. Knepley 695a859676bSMatthew G. Knepley Level: beginner 696a859676bSMatthew G. Knepley 697dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 698a859676bSMatthew G. Knepley @*/ 699d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed) 700d71ae5a4SJacob Faibussowitsch { 701a859676bSMatthew G. Knepley PetscFunctionBegin; 702a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 703dadcf809SJacob Faibussowitsch PetscValidIntPointer(dimEmbed, 2); 70408401ef6SPierre Jolivet PetscCheck(prob->dimEmbed >= 0, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS"); 705a859676bSMatthew G. Knepley *dimEmbed = prob->dimEmbed; 706a859676bSMatthew G. Knepley PetscFunctionReturn(0); 707a859676bSMatthew G. Knepley } 708a859676bSMatthew G. Knepley 709a859676bSMatthew G. Knepley /*@ 710dce8aebaSBarry Smith PetscDSSetCoordinateDimension - Set the coordinate dimension of the `PetscDS`, meaning the dimension of the space into which the discretiaztions are embedded 711a859676bSMatthew G. Knepley 712d083f849SBarry Smith Logically collective on prob 713a859676bSMatthew G. Knepley 714a859676bSMatthew G. Knepley Input Parameters: 715dce8aebaSBarry Smith + prob - The `PetscDS` object 716a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension 717a859676bSMatthew G. Knepley 718a859676bSMatthew G. Knepley Level: beginner 719a859676bSMatthew G. Knepley 720dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 721a859676bSMatthew G. Knepley @*/ 722d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed) 723d71ae5a4SJacob Faibussowitsch { 724a859676bSMatthew G. Knepley PetscFunctionBegin; 725a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 72663a3b9bcSJacob Faibussowitsch PetscCheck(dimEmbed >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %" PetscInt_FMT, dimEmbed); 727a859676bSMatthew G. Knepley prob->dimEmbed = dimEmbed; 728a859676bSMatthew G. Knepley PetscFunctionReturn(0); 729a859676bSMatthew G. Knepley } 730a859676bSMatthew G. Knepley 731a859676bSMatthew G. Knepley /*@ 732dce8aebaSBarry Smith PetscDSIsCohesive - Returns the flag indicating that this `PetscDS` is for a cohesive cell 7338edf6225SMatthew G. Knepley 7348edf6225SMatthew G. Knepley Not collective 7358edf6225SMatthew G. Knepley 7368edf6225SMatthew G. Knepley Input Parameter: 737dce8aebaSBarry Smith . ds - The `PetscDS` object 7388edf6225SMatthew G. Knepley 7398edf6225SMatthew G. Knepley Output Parameter: 7405fedec97SMatthew G. Knepley . isCohesive - The flag 7418edf6225SMatthew G. Knepley 7428edf6225SMatthew G. Knepley Level: developer 7438edf6225SMatthew G. Knepley 744dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumCohesive()`, `PetscDSGetCohesive()`, `PetscDSSetCohesive()`, `PetscDSCreate()` 7458edf6225SMatthew G. Knepley @*/ 746d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSIsCohesive(PetscDS ds, PetscBool *isCohesive) 747d71ae5a4SJacob Faibussowitsch { 7488edf6225SMatthew G. Knepley PetscFunctionBegin; 7495fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 750dadcf809SJacob Faibussowitsch PetscValidBoolPointer(isCohesive, 2); 7515fedec97SMatthew G. Knepley *isCohesive = ds->isCohesive; 7528edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7538edf6225SMatthew G. Knepley } 7548edf6225SMatthew G. Knepley 7558edf6225SMatthew G. Knepley /*@ 7565fedec97SMatthew G. Knepley PetscDSGetNumCohesive - Returns the numer of cohesive fields, meaning those defined on the interior of a cohesive cell 7575fedec97SMatthew G. Knepley 7585fedec97SMatthew G. Knepley Not collective 7595fedec97SMatthew G. Knepley 7605fedec97SMatthew G. Knepley Input Parameter: 761dce8aebaSBarry Smith . ds - The `PetscDS` object 7625fedec97SMatthew G. Knepley 7635fedec97SMatthew G. Knepley Output Parameter: 7645fedec97SMatthew G. Knepley . numCohesive - The number of cohesive fields 7655fedec97SMatthew G. Knepley 7665fedec97SMatthew G. Knepley Level: developer 7675fedec97SMatthew G. Knepley 768dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetCohesive()`, `PetscDSCreate()` 7695fedec97SMatthew G. Knepley @*/ 770d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumCohesive(PetscDS ds, PetscInt *numCohesive) 771d71ae5a4SJacob Faibussowitsch { 7725fedec97SMatthew G. Knepley PetscInt f; 7735fedec97SMatthew G. Knepley 7745fedec97SMatthew G. Knepley PetscFunctionBegin; 7755fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 776dadcf809SJacob Faibussowitsch PetscValidIntPointer(numCohesive, 2); 7775fedec97SMatthew G. Knepley *numCohesive = 0; 7785fedec97SMatthew G. Knepley for (f = 0; f < ds->Nf; ++f) *numCohesive += ds->cohesive[f] ? 1 : 0; 7795fedec97SMatthew G. Knepley PetscFunctionReturn(0); 7805fedec97SMatthew G. Knepley } 7815fedec97SMatthew G. Knepley 7825fedec97SMatthew G. Knepley /*@ 7835fedec97SMatthew G. Knepley PetscDSGetCohesive - Returns the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell 7845fedec97SMatthew G. Knepley 7855fedec97SMatthew G. Knepley Not collective 7865fedec97SMatthew G. Knepley 787f1a722f8SMatthew G. Knepley Input Parameters: 788dce8aebaSBarry Smith + ds - The `PetscDS` object 7895fedec97SMatthew G. Knepley - f - The field index 7905fedec97SMatthew G. Knepley 7915fedec97SMatthew G. Knepley Output Parameter: 7925fedec97SMatthew G. Knepley . isCohesive - The flag 7935fedec97SMatthew G. Knepley 7945fedec97SMatthew G. Knepley Level: developer 7955fedec97SMatthew G. Knepley 796dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()` 7975fedec97SMatthew G. Knepley @*/ 798d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetCohesive(PetscDS ds, PetscInt f, PetscBool *isCohesive) 799d71ae5a4SJacob Faibussowitsch { 8005fedec97SMatthew G. Knepley PetscFunctionBegin; 8015fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 802dadcf809SJacob Faibussowitsch PetscValidBoolPointer(isCohesive, 3); 80363a3b9bcSJacob 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); 8045fedec97SMatthew G. Knepley *isCohesive = ds->cohesive[f]; 8055fedec97SMatthew G. Knepley PetscFunctionReturn(0); 8065fedec97SMatthew G. Knepley } 8075fedec97SMatthew G. Knepley 8085fedec97SMatthew G. Knepley /*@ 8095fedec97SMatthew G. Knepley PetscDSSetCohesive - Set the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell 8108edf6225SMatthew G. Knepley 8118edf6225SMatthew G. Knepley Not collective 8128edf6225SMatthew G. Knepley 8138edf6225SMatthew G. Knepley Input Parameters: 814dce8aebaSBarry Smith + ds - The `PetscDS` object 8155fedec97SMatthew G. Knepley . f - The field index 8165fedec97SMatthew G. Knepley - isCohesive - The flag for a cohesive field 8178edf6225SMatthew G. Knepley 8188edf6225SMatthew G. Knepley Level: developer 8198edf6225SMatthew G. Knepley 820dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()` 8218edf6225SMatthew G. Knepley @*/ 822d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetCohesive(PetscDS ds, PetscInt f, PetscBool isCohesive) 823d71ae5a4SJacob Faibussowitsch { 8245fedec97SMatthew G. Knepley PetscInt i; 8255fedec97SMatthew G. Knepley 8268edf6225SMatthew G. Knepley PetscFunctionBegin; 8275fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 82863a3b9bcSJacob 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); 8295fedec97SMatthew G. Knepley ds->cohesive[f] = isCohesive; 8305fedec97SMatthew G. Knepley ds->isCohesive = PETSC_FALSE; 8315fedec97SMatthew G. Knepley for (i = 0; i < ds->Nf; ++i) ds->isCohesive = ds->isCohesive || ds->cohesive[f] ? PETSC_TRUE : PETSC_FALSE; 8328edf6225SMatthew G. Knepley PetscFunctionReturn(0); 8338edf6225SMatthew G. Knepley } 8348edf6225SMatthew G. Knepley 8358edf6225SMatthew G. Knepley /*@ 836bc4ae4beSMatthew G. Knepley PetscDSGetTotalDimension - Returns the total size of the approximation space for this system 837bc4ae4beSMatthew G. Knepley 838bc4ae4beSMatthew G. Knepley Not collective 839bc4ae4beSMatthew G. Knepley 840bc4ae4beSMatthew G. Knepley Input Parameter: 841dce8aebaSBarry Smith . prob - The `PetscDS` object 842bc4ae4beSMatthew G. Knepley 843bc4ae4beSMatthew G. Knepley Output Parameter: 844bc4ae4beSMatthew G. Knepley . dim - The total problem dimension 845bc4ae4beSMatthew G. Knepley 846bc4ae4beSMatthew G. Knepley Level: beginner 847bc4ae4beSMatthew G. Knepley 848dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()` 849bc4ae4beSMatthew G. Knepley @*/ 850d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) 851d71ae5a4SJacob Faibussowitsch { 8522764a2aaSMatthew G. Knepley PetscFunctionBegin; 8532764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8549566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 855dadcf809SJacob Faibussowitsch PetscValidIntPointer(dim, 2); 8562764a2aaSMatthew G. Knepley *dim = prob->totDim; 8572764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8582764a2aaSMatthew G. Knepley } 8592764a2aaSMatthew G. Knepley 860bc4ae4beSMatthew G. Knepley /*@ 861bc4ae4beSMatthew G. Knepley PetscDSGetTotalComponents - Returns the total number of components in this system 862bc4ae4beSMatthew G. Knepley 863bc4ae4beSMatthew G. Knepley Not collective 864bc4ae4beSMatthew G. Knepley 865bc4ae4beSMatthew G. Knepley Input Parameter: 866dce8aebaSBarry Smith . prob - The `PetscDS` object 867bc4ae4beSMatthew G. Knepley 868bc4ae4beSMatthew G. Knepley Output Parameter: 869bc4ae4beSMatthew G. Knepley . dim - The total number of components 870bc4ae4beSMatthew G. Knepley 871bc4ae4beSMatthew G. Knepley Level: beginner 872bc4ae4beSMatthew G. Knepley 873dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()` 874bc4ae4beSMatthew G. Knepley @*/ 875d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) 876d71ae5a4SJacob Faibussowitsch { 8772764a2aaSMatthew G. Knepley PetscFunctionBegin; 8782764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8799566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 880dadcf809SJacob Faibussowitsch PetscValidIntPointer(Nc, 2); 8812764a2aaSMatthew G. Knepley *Nc = prob->totComp; 8822764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8832764a2aaSMatthew G. Knepley } 8842764a2aaSMatthew G. Knepley 885bc4ae4beSMatthew G. Knepley /*@ 886bc4ae4beSMatthew G. Knepley PetscDSGetDiscretization - Returns the discretization object for the given field 887bc4ae4beSMatthew G. Knepley 888bc4ae4beSMatthew G. Knepley Not collective 889bc4ae4beSMatthew G. Knepley 890bc4ae4beSMatthew G. Knepley Input Parameters: 891dce8aebaSBarry Smith + prob - The `PetscDS` object 892bc4ae4beSMatthew G. Knepley - f - The field number 893bc4ae4beSMatthew G. Knepley 894bc4ae4beSMatthew G. Knepley Output Parameter: 895bc4ae4beSMatthew G. Knepley . disc - The discretization object 896bc4ae4beSMatthew G. Knepley 897bc4ae4beSMatthew G. Knepley Level: beginner 898bc4ae4beSMatthew G. Knepley 899dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscFE`, `PetscFV`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 900bc4ae4beSMatthew G. Knepley @*/ 901d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 902d71ae5a4SJacob Faibussowitsch { 9036528b96dSMatthew G. Knepley PetscFunctionBeginHot; 9042764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 9052764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 90663a3b9bcSJacob 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); 9072764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 9082764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9092764a2aaSMatthew G. Knepley } 9102764a2aaSMatthew G. Knepley 911bc4ae4beSMatthew G. Knepley /*@ 912bc4ae4beSMatthew G. Knepley PetscDSSetDiscretization - Sets the discretization object for the given field 913bc4ae4beSMatthew G. Knepley 914bc4ae4beSMatthew G. Knepley Not collective 915bc4ae4beSMatthew G. Knepley 916bc4ae4beSMatthew G. Knepley Input Parameters: 917dce8aebaSBarry Smith + prob - The `PetscDS` object 918bc4ae4beSMatthew G. Knepley . f - The field number 919bc4ae4beSMatthew G. Knepley - disc - The discretization object 920bc4ae4beSMatthew G. Knepley 921bc4ae4beSMatthew G. Knepley Level: beginner 922bc4ae4beSMatthew G. Knepley 923dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscFE`, `PetscFV`, `PetscDSGetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 924bc4ae4beSMatthew G. Knepley @*/ 925d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 926d71ae5a4SJacob Faibussowitsch { 9272764a2aaSMatthew G. Knepley PetscFunctionBegin; 9282764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 929665f567fSMatthew G. Knepley if (disc) PetscValidPointer(disc, 3); 93063a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 9319566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(prob, f + 1)); 9329566063dSJacob Faibussowitsch PetscCall(PetscObjectDereference(prob->disc[f])); 9332764a2aaSMatthew G. Knepley prob->disc[f] = disc; 9349566063dSJacob Faibussowitsch PetscCall(PetscObjectReference(disc)); 935665f567fSMatthew G. Knepley if (disc) { 936249df284SMatthew G. Knepley PetscClassId id; 937249df284SMatthew G. Knepley 9389566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(disc, &id)); 9391cf84007SMatthew G. Knepley if (id == PETSCFE_CLASSID) { 9409566063dSJacob Faibussowitsch PetscCall(PetscDSSetImplicit(prob, f, PETSC_TRUE)); 9411cf84007SMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 9429566063dSJacob Faibussowitsch PetscCall(PetscDSSetImplicit(prob, f, PETSC_FALSE)); 943a6cbbb48SMatthew G. Knepley } 9449566063dSJacob Faibussowitsch PetscCall(PetscDSSetJetDegree(prob, f, 1)); 945249df284SMatthew G. Knepley } 9462764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9472764a2aaSMatthew G. Knepley } 9482764a2aaSMatthew G. Knepley 949bc4ae4beSMatthew G. Knepley /*@ 9506528b96dSMatthew G. Knepley PetscDSGetWeakForm - Returns the weak form object 9516528b96dSMatthew G. Knepley 9526528b96dSMatthew G. Knepley Not collective 9536528b96dSMatthew G. Knepley 9546528b96dSMatthew G. Knepley Input Parameter: 955dce8aebaSBarry Smith . ds - The `PetscDS` object 9566528b96dSMatthew G. Knepley 9576528b96dSMatthew G. Knepley Output Parameter: 9586528b96dSMatthew G. Knepley . wf - The weak form object 9596528b96dSMatthew G. Knepley 9606528b96dSMatthew G. Knepley Level: beginner 9616528b96dSMatthew G. Knepley 962dce8aebaSBarry Smith .seealso: `PetscWeakForm`, `PetscDSSetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 9636528b96dSMatthew G. Knepley @*/ 964d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf) 965d71ae5a4SJacob Faibussowitsch { 9666528b96dSMatthew G. Knepley PetscFunctionBegin; 9676528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 9686528b96dSMatthew G. Knepley PetscValidPointer(wf, 2); 9696528b96dSMatthew G. Knepley *wf = ds->wf; 9706528b96dSMatthew G. Knepley PetscFunctionReturn(0); 9716528b96dSMatthew G. Knepley } 9726528b96dSMatthew G. Knepley 9736528b96dSMatthew G. Knepley /*@ 9746528b96dSMatthew G. Knepley PetscDSSetWeakForm - Sets the weak form object 9756528b96dSMatthew G. Knepley 9766528b96dSMatthew G. Knepley Not collective 9776528b96dSMatthew G. Knepley 9786528b96dSMatthew G. Knepley Input Parameters: 979dce8aebaSBarry Smith + ds - The `PetscDS` object 9806528b96dSMatthew G. Knepley - wf - The weak form object 9816528b96dSMatthew G. Knepley 9826528b96dSMatthew G. Knepley Level: beginner 9836528b96dSMatthew G. Knepley 984dce8aebaSBarry Smith .seealso: `PetscWeakForm`, `PetscDSGetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 9856528b96dSMatthew G. Knepley @*/ 986d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf) 987d71ae5a4SJacob Faibussowitsch { 9886528b96dSMatthew G. Knepley PetscFunctionBegin; 9896528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 9906528b96dSMatthew G. Knepley PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2); 9919566063dSJacob Faibussowitsch PetscCall(PetscObjectDereference((PetscObject)ds->wf)); 9926528b96dSMatthew G. Knepley ds->wf = wf; 9939566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)wf)); 9949566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetNumFields(wf, ds->Nf)); 9956528b96dSMatthew G. Knepley PetscFunctionReturn(0); 9966528b96dSMatthew G. Knepley } 9976528b96dSMatthew G. Knepley 9986528b96dSMatthew G. Knepley /*@ 999bc4ae4beSMatthew G. Knepley PetscDSAddDiscretization - Adds a discretization object 1000bc4ae4beSMatthew G. Knepley 1001bc4ae4beSMatthew G. Knepley Not collective 1002bc4ae4beSMatthew G. Knepley 1003bc4ae4beSMatthew G. Knepley Input Parameters: 1004dce8aebaSBarry Smith + prob - The `PetscDS` object 1005bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object 1006bc4ae4beSMatthew G. Knepley 1007bc4ae4beSMatthew G. Knepley Level: beginner 1008bc4ae4beSMatthew G. Knepley 1009dce8aebaSBarry Smith .seealso: `PetscWeakForm`, `PetscDSGetDiscretization()`, `PetscDSSetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1010bc4ae4beSMatthew G. Knepley @*/ 1011d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) 1012d71ae5a4SJacob Faibussowitsch { 10132764a2aaSMatthew G. Knepley PetscFunctionBegin; 10149566063dSJacob Faibussowitsch PetscCall(PetscDSSetDiscretization(prob, prob->Nf, disc)); 10152764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10162764a2aaSMatthew G. Knepley } 10172764a2aaSMatthew G. Knepley 1018249df284SMatthew G. Knepley /*@ 1019dce8aebaSBarry Smith PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the `PetscDS` 1020083401c6SMatthew G. Knepley 1021083401c6SMatthew G. Knepley Not collective 1022083401c6SMatthew G. Knepley 1023083401c6SMatthew G. Knepley Input Parameter: 1024dce8aebaSBarry Smith . prob - The `PetscDS` object 1025083401c6SMatthew G. Knepley 1026083401c6SMatthew G. Knepley Output Parameter: 1027083401c6SMatthew G. Knepley . q - The quadrature object 1028083401c6SMatthew G. Knepley 1029083401c6SMatthew G. Knepley Level: intermediate 1030083401c6SMatthew G. Knepley 1031dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscQuadrature`, `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1032083401c6SMatthew G. Knepley @*/ 1033d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q) 1034d71ae5a4SJacob Faibussowitsch { 1035083401c6SMatthew G. Knepley PetscObject obj; 1036083401c6SMatthew G. Knepley PetscClassId id; 1037083401c6SMatthew G. Knepley 1038083401c6SMatthew G. Knepley PetscFunctionBegin; 1039083401c6SMatthew G. Knepley *q = NULL; 1040083401c6SMatthew G. Knepley if (!prob->Nf) PetscFunctionReturn(0); 10419566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, 0, &obj)); 10429566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 10439566063dSJacob Faibussowitsch if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetQuadrature((PetscFE)obj, q)); 10449566063dSJacob Faibussowitsch else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetQuadrature((PetscFV)obj, q)); 104598921bdaSJacob Faibussowitsch else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 1046083401c6SMatthew G. Knepley PetscFunctionReturn(0); 1047083401c6SMatthew G. Knepley } 1048083401c6SMatthew G. Knepley 1049083401c6SMatthew G. Knepley /*@ 1050dce8aebaSBarry Smith PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for `TSIMEX` 1051249df284SMatthew G. Knepley 1052249df284SMatthew G. Knepley Not collective 1053249df284SMatthew G. Knepley 1054249df284SMatthew G. Knepley Input Parameters: 1055dce8aebaSBarry Smith + prob - The `PetscDS` object 1056249df284SMatthew G. Knepley - f - The field number 1057249df284SMatthew G. Knepley 1058249df284SMatthew G. Knepley Output Parameter: 1059249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field 1060249df284SMatthew G. Knepley 1061249df284SMatthew G. Knepley Level: developer 1062249df284SMatthew G. Knepley 1063dce8aebaSBarry Smith .seealso: `TSIMEX`, `PetscDS`, `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1064249df284SMatthew G. Knepley @*/ 1065d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit) 1066d71ae5a4SJacob Faibussowitsch { 1067249df284SMatthew G. Knepley PetscFunctionBegin; 1068249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1069dadcf809SJacob Faibussowitsch PetscValidBoolPointer(implicit, 3); 107063a3b9bcSJacob 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); 1071249df284SMatthew G. Knepley *implicit = prob->implicit[f]; 1072249df284SMatthew G. Knepley PetscFunctionReturn(0); 1073249df284SMatthew G. Knepley } 1074249df284SMatthew G. Knepley 1075249df284SMatthew G. Knepley /*@ 1076dce8aebaSBarry Smith PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for `TSIMEX` 1077249df284SMatthew G. Knepley 1078249df284SMatthew G. Knepley Not collective 1079249df284SMatthew G. Knepley 1080249df284SMatthew G. Knepley Input Parameters: 1081dce8aebaSBarry Smith + prob - The `PetscDS` object 1082249df284SMatthew G. Knepley . f - The field number 1083249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field 1084249df284SMatthew G. Knepley 1085249df284SMatthew G. Knepley Level: developer 1086249df284SMatthew G. Knepley 1087dce8aebaSBarry Smith .seealso: `TSIMEX`, `PetscDSGetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1088249df284SMatthew G. Knepley @*/ 1089d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit) 1090d71ae5a4SJacob Faibussowitsch { 1091249df284SMatthew G. Knepley PetscFunctionBegin; 1092249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 109363a3b9bcSJacob 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); 1094249df284SMatthew G. Knepley prob->implicit[f] = implicit; 1095249df284SMatthew G. Knepley PetscFunctionReturn(0); 1096249df284SMatthew G. Knepley } 1097249df284SMatthew G. Knepley 1098f9244615SMatthew G. Knepley /*@ 1099f9244615SMatthew G. Knepley PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate. 1100f9244615SMatthew G. Knepley 1101f9244615SMatthew G. Knepley Not collective 1102f9244615SMatthew G. Knepley 1103f9244615SMatthew G. Knepley Input Parameters: 1104dce8aebaSBarry Smith + ds - The `PetscDS` object 1105f9244615SMatthew G. Knepley - f - The field number 1106f9244615SMatthew G. Knepley 1107f9244615SMatthew G. Knepley Output Parameter: 1108f9244615SMatthew G. Knepley . k - The highest derivative we need to tabulate 1109f9244615SMatthew G. Knepley 1110f9244615SMatthew G. Knepley Level: developer 1111f9244615SMatthew G. Knepley 1112dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1113f9244615SMatthew G. Knepley @*/ 1114d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k) 1115d71ae5a4SJacob Faibussowitsch { 1116f9244615SMatthew G. Knepley PetscFunctionBegin; 1117f9244615SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1118dadcf809SJacob Faibussowitsch PetscValidIntPointer(k, 3); 111963a3b9bcSJacob 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); 1120f9244615SMatthew G. Knepley *k = ds->jetDegree[f]; 1121f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1122f9244615SMatthew G. Knepley } 1123f9244615SMatthew G. Knepley 1124f9244615SMatthew G. Knepley /*@ 1125f9244615SMatthew G. Knepley PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate. 1126f9244615SMatthew G. Knepley 1127f9244615SMatthew G. Knepley Not collective 1128f9244615SMatthew G. Knepley 1129f9244615SMatthew G. Knepley Input Parameters: 1130dce8aebaSBarry Smith + ds - The `PetscDS` object 1131f9244615SMatthew G. Knepley . f - The field number 1132f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate 1133f9244615SMatthew G. Knepley 1134f9244615SMatthew G. Knepley Level: developer 1135f9244615SMatthew G. Knepley 1136dce8aebaSBarry Smith .seealso: ``PetscDS`, PetscDSGetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1137f9244615SMatthew G. Knepley @*/ 1138d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k) 1139d71ae5a4SJacob Faibussowitsch { 1140f9244615SMatthew G. Knepley PetscFunctionBegin; 1141f9244615SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 114263a3b9bcSJacob 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); 1143f9244615SMatthew G. Knepley ds->jetDegree[f] = k; 1144f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1145f9244615SMatthew G. Knepley } 1146f9244615SMatthew G. Knepley 1147d71ae5a4SJacob 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[])) 1148d71ae5a4SJacob Faibussowitsch { 11496528b96dSMatthew G. Knepley PetscPointFunc *tmp; 11506528b96dSMatthew G. Knepley PetscInt n; 11516528b96dSMatthew G. Knepley 11522764a2aaSMatthew G. Knepley PetscFunctionBegin; 11536528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 11546528b96dSMatthew G. Knepley PetscValidPointer(obj, 3); 115563a3b9bcSJacob 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); 11569566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetObjective(ds->wf, NULL, 0, f, 0, &n, &tmp)); 11576528b96dSMatthew G. Knepley *obj = tmp ? tmp[0] : NULL; 11582764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11592764a2aaSMatthew G. Knepley } 11602764a2aaSMatthew G. Knepley 1161d71ae5a4SJacob 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[])) 1162d71ae5a4SJacob Faibussowitsch { 11632764a2aaSMatthew G. Knepley PetscFunctionBegin; 11646528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 11656528b96dSMatthew G. Knepley if (obj) PetscValidFunction(obj, 3); 116663a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 11679566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, 0, obj)); 11682764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11692764a2aaSMatthew G. Knepley } 11702764a2aaSMatthew G. Knepley 1171194d53e6SMatthew G. Knepley /*@C 1172194d53e6SMatthew G. Knepley PetscDSGetResidual - Get the pointwise residual function for a given test field 1173194d53e6SMatthew G. Knepley 1174194d53e6SMatthew G. Knepley Not collective 1175194d53e6SMatthew G. Knepley 1176194d53e6SMatthew G. Knepley Input Parameters: 1177dce8aebaSBarry Smith + ds - The `PetscDS` 1178194d53e6SMatthew G. Knepley - f - The test field number 1179194d53e6SMatthew G. Knepley 1180194d53e6SMatthew G. Knepley Output Parameters: 1181194d53e6SMatthew G. Knepley + f0 - integrand for the test function term 1182194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1183194d53e6SMatthew G. Knepley 1184dce8aebaSBarry Smith Calling sequence for the callbacks f0 and f1: 1185dce8aebaSBarry Smith .vb 1186dce8aebaSBarry Smith f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1187dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1188dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1189dce8aebaSBarry Smith PetscReal t, const PetscReal x[], PetscScalar f0[]) 1190dce8aebaSBarry Smith .ve 1191194d53e6SMatthew G. Knepley + dim - the spatial dimension 1192194d53e6SMatthew G. Knepley . Nf - the number of fields 1193194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1194194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1195194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1196194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1197194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1198194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1199194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1200194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1201194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1202194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1203194d53e6SMatthew G. Knepley . t - current time 1204194d53e6SMatthew G. Knepley . x - coordinates of the current point 120597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 120697b6e6e8SMatthew G. Knepley . constants - constant parameters 1207194d53e6SMatthew G. Knepley - f0 - output values at the current point 1208194d53e6SMatthew G. Knepley 1209194d53e6SMatthew G. Knepley Level: intermediate 1210194d53e6SMatthew G. Knepley 1211dce8aebaSBarry Smith Note: 1212dce8aebaSBarry 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) 1213dce8aebaSBarry Smith 1214dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetResidual()` 1215194d53e6SMatthew G. Knepley @*/ 1216d71ae5a4SJacob 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[])) 1217d71ae5a4SJacob Faibussowitsch { 12186528b96dSMatthew G. Knepley PetscPointFunc *tmp0, *tmp1; 12196528b96dSMatthew G. Knepley PetscInt n0, n1; 12206528b96dSMatthew G. Knepley 12212764a2aaSMatthew G. Knepley PetscFunctionBegin; 12226528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 122363a3b9bcSJacob 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); 12249566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1)); 12256528b96dSMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 12266528b96dSMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 12272764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 12282764a2aaSMatthew G. Knepley } 12292764a2aaSMatthew G. Knepley 1230194d53e6SMatthew G. Knepley /*@C 1231194d53e6SMatthew G. Knepley PetscDSSetResidual - Set the pointwise residual function for a given test field 1232194d53e6SMatthew G. Knepley 1233194d53e6SMatthew G. Knepley Not collective 1234194d53e6SMatthew G. Knepley 1235194d53e6SMatthew G. Knepley Input Parameters: 1236dce8aebaSBarry Smith + ds - The `PetscDS` 1237194d53e6SMatthew G. Knepley . f - The test field number 1238194d53e6SMatthew G. Knepley . f0 - integrand for the test function term 1239194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1240194d53e6SMatthew G. Knepley 1241dce8aebaSBarry Smith Calling sequence for the callbacks f0 and f1: 1242dce8aebaSBarry Smith .vb 1243dce8aebaSBarry Smith f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1244dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1245dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1246dce8aebaSBarry Smith PetscReal t, const PetscReal x[], PetscScalar f0[]) 1247dce8aebaSBarry Smith .ve 1248194d53e6SMatthew G. Knepley + dim - the spatial dimension 1249194d53e6SMatthew G. Knepley . Nf - the number of fields 1250194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1251194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1252194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1253194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1254194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1255194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1256194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1257194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1258194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1259194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1260194d53e6SMatthew G. Knepley . t - current time 1261194d53e6SMatthew G. Knepley . x - coordinates of the current point 126297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 126397b6e6e8SMatthew G. Knepley . constants - constant parameters 1264194d53e6SMatthew G. Knepley - f0 - output values at the current point 1265194d53e6SMatthew G. Knepley 1266194d53e6SMatthew G. Knepley Level: intermediate 1267194d53e6SMatthew G. Knepley 1268dce8aebaSBarry Smith Note: 1269dce8aebaSBarry 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) 1270dce8aebaSBarry Smith 1271dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetResidual()` 1272194d53e6SMatthew G. Knepley @*/ 1273d71ae5a4SJacob 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[])) 1274d71ae5a4SJacob Faibussowitsch { 12752764a2aaSMatthew G. Knepley PetscFunctionBegin; 12766528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1277f866a1d0SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1278f866a1d0SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 127963a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 12809566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1)); 12812764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 12822764a2aaSMatthew G. Knepley } 12832764a2aaSMatthew G. Knepley 12843e75805dSMatthew G. Knepley /*@C 1285cb36c0f9SMatthew G. Knepley PetscDSGetRHSResidual - Get the pointwise RHS residual function for explicit timestepping for a given test field 1286cb36c0f9SMatthew G. Knepley 1287cb36c0f9SMatthew G. Knepley Not collective 1288cb36c0f9SMatthew G. Knepley 1289cb36c0f9SMatthew G. Knepley Input Parameters: 1290dce8aebaSBarry Smith + ds - The `PetscDS` 1291cb36c0f9SMatthew G. Knepley - f - The test field number 1292cb36c0f9SMatthew G. Knepley 1293cb36c0f9SMatthew G. Knepley Output Parameters: 1294cb36c0f9SMatthew G. Knepley + f0 - integrand for the test function term 1295cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term 1296cb36c0f9SMatthew G. Knepley 1297dce8aebaSBarry Smith Calling sequence for the callbacks f0 and f1: 1298dce8aebaSBarry Smith .vb 1299dce8aebaSBarry Smith f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1300dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1301dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1302dce8aebaSBarry Smith PetscReal t, const PetscReal x[], PetscScalar f0[]) 1303dce8aebaSBarry Smith .ve 1304cb36c0f9SMatthew G. Knepley + dim - the spatial dimension 1305cb36c0f9SMatthew G. Knepley . Nf - the number of fields 1306cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1307cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1308cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point 1309cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1310cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1311cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1312cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1313cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1314cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1315cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1316cb36c0f9SMatthew G. Knepley . t - current time 1317cb36c0f9SMatthew G. Knepley . x - coordinates of the current point 1318cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters 1319cb36c0f9SMatthew G. Knepley . constants - constant parameters 1320cb36c0f9SMatthew G. Knepley - f0 - output values at the current point 1321cb36c0f9SMatthew G. Knepley 1322cb36c0f9SMatthew G. Knepley Level: intermediate 1323cb36c0f9SMatthew G. Knepley 1324dce8aebaSBarry Smith Note: 1325dce8aebaSBarry 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) 1326dce8aebaSBarry Smith 1327dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetRHSResidual()` 1328cb36c0f9SMatthew G. Knepley @*/ 1329d71ae5a4SJacob 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[])) 1330d71ae5a4SJacob Faibussowitsch { 1331cb36c0f9SMatthew G. Knepley PetscPointFunc *tmp0, *tmp1; 1332cb36c0f9SMatthew G. Knepley PetscInt n0, n1; 1333cb36c0f9SMatthew G. Knepley 1334cb36c0f9SMatthew G. Knepley PetscFunctionBegin; 1335cb36c0f9SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 133663a3b9bcSJacob 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); 13379566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 100, &n0, &tmp0, &n1, &tmp1)); 1338cb36c0f9SMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 1339cb36c0f9SMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 1340cb36c0f9SMatthew G. Knepley PetscFunctionReturn(0); 1341cb36c0f9SMatthew G. Knepley } 1342cb36c0f9SMatthew G. Knepley 1343cb36c0f9SMatthew G. Knepley /*@C 1344cb36c0f9SMatthew G. Knepley PetscDSSetRHSResidual - Set the pointwise residual function for explicit timestepping for a given test field 1345cb36c0f9SMatthew G. Knepley 1346cb36c0f9SMatthew G. Knepley Not collective 1347cb36c0f9SMatthew G. Knepley 1348cb36c0f9SMatthew G. Knepley Input Parameters: 1349dce8aebaSBarry Smith + ds - The `PetscDS` 1350cb36c0f9SMatthew G. Knepley . f - The test field number 1351cb36c0f9SMatthew G. Knepley . f0 - integrand for the test function term 1352cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term 1353cb36c0f9SMatthew G. Knepley 1354dce8aebaSBarry Smith Clling sequence for the callbacks f0 and f1: 1355dce8aebaSBarry Smith .vb 1356dce8aebaSBarry Smith f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1357dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1358dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1359dce8aebaSBarry Smith PetscReal t, const PetscReal x[], PetscScalar f0[]) 1360dce8aebaSBarry Smith .ve 1361cb36c0f9SMatthew G. Knepley + dim - the spatial dimension 1362cb36c0f9SMatthew G. Knepley . Nf - the number of fields 1363cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1364cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1365cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point 1366cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1367cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1368cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1369cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1370cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1371cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1372cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1373cb36c0f9SMatthew G. Knepley . t - current time 1374cb36c0f9SMatthew G. Knepley . x - coordinates of the current point 1375cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters 1376cb36c0f9SMatthew G. Knepley . constants - constant parameters 1377cb36c0f9SMatthew G. Knepley - f0 - output values at the current point 1378cb36c0f9SMatthew G. Knepley 1379cb36c0f9SMatthew G. Knepley Level: intermediate 1380cb36c0f9SMatthew G. Knepley 1381dce8aebaSBarry Smith Note: 1382dce8aebaSBarry 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) 1383dce8aebaSBarry Smith 1384dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetResidual()` 1385cb36c0f9SMatthew G. Knepley @*/ 1386d71ae5a4SJacob 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[])) 1387d71ae5a4SJacob Faibussowitsch { 1388cb36c0f9SMatthew G. Knepley PetscFunctionBegin; 1389cb36c0f9SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1390cb36c0f9SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1391cb36c0f9SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 139263a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 13939566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 100, 0, f0, 0, f1)); 1394cb36c0f9SMatthew G. Knepley PetscFunctionReturn(0); 1395cb36c0f9SMatthew G. Knepley } 1396cb36c0f9SMatthew G. Knepley 1397cb36c0f9SMatthew G. Knepley /*@C 1398dce8aebaSBarry Smith PetscDSHasJacobian - Checks that the Jacobian functions have been set 13993e75805dSMatthew G. Knepley 14003e75805dSMatthew G. Knepley Not collective 14013e75805dSMatthew G. Knepley 14023e75805dSMatthew G. Knepley Input Parameter: 1403dce8aebaSBarry Smith . prob - The `PetscDS` 14043e75805dSMatthew G. Knepley 14053e75805dSMatthew G. Knepley Output Parameter: 14063e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set 14073e75805dSMatthew G. Knepley 14083e75805dSMatthew G. Knepley Level: intermediate 14093e75805dSMatthew G. Knepley 1410dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()` 14113e75805dSMatthew G. Knepley @*/ 1412d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac) 1413d71ae5a4SJacob Faibussowitsch { 14143e75805dSMatthew G. Knepley PetscFunctionBegin; 14156528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14169566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasJacobian(ds->wf, hasJac)); 14173e75805dSMatthew G. Knepley PetscFunctionReturn(0); 14183e75805dSMatthew G. Knepley } 14193e75805dSMatthew G. Knepley 1420194d53e6SMatthew G. Knepley /*@C 1421194d53e6SMatthew G. Knepley PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field 1422194d53e6SMatthew G. Knepley 1423194d53e6SMatthew G. Knepley Not collective 1424194d53e6SMatthew G. Knepley 1425194d53e6SMatthew G. Knepley Input Parameters: 1426dce8aebaSBarry Smith + ds - The `PetscDS` 1427194d53e6SMatthew G. Knepley . f - The test field number 1428194d53e6SMatthew G. Knepley - g - The field number 1429194d53e6SMatthew G. Knepley 1430194d53e6SMatthew G. Knepley Output Parameters: 1431194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1432194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1433194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1434194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1435194d53e6SMatthew G. Knepley 1436dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 1437dce8aebaSBarry Smith .vb 1438dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1439dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1440dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1441dce8aebaSBarry Smith PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1442dce8aebaSBarry Smith .ve 1443194d53e6SMatthew G. Knepley + dim - the spatial dimension 1444194d53e6SMatthew G. Knepley . Nf - the number of fields 1445194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1446194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1447194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1448194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1449194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1450194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1451194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1452194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1453194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1454194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1455194d53e6SMatthew G. Knepley . t - current time 14562aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1457194d53e6SMatthew G. Knepley . x - coordinates of the current point 145897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 145997b6e6e8SMatthew G. Knepley . constants - constant parameters 1460194d53e6SMatthew G. Knepley - g0 - output values at the current point 1461194d53e6SMatthew G. Knepley 1462194d53e6SMatthew G. Knepley Level: intermediate 1463194d53e6SMatthew G. Knepley 1464dce8aebaSBarry Smith Note: 1465dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 1466dce8aebaSBarry 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 1467dce8aebaSBarry Smith 1468dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJacobian()` 1469194d53e6SMatthew G. Knepley @*/ 1470d71ae5a4SJacob 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[])) 1471d71ae5a4SJacob Faibussowitsch { 14726528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 14736528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 14746528b96dSMatthew G. Knepley 14752764a2aaSMatthew G. Knepley PetscFunctionBegin; 14766528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 147763a3b9bcSJacob 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); 147863a3b9bcSJacob 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); 14799566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 14806528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 14816528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 14826528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 14836528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 14842764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 14852764a2aaSMatthew G. Knepley } 14862764a2aaSMatthew G. Knepley 1487194d53e6SMatthew G. Knepley /*@C 1488194d53e6SMatthew G. Knepley PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields 1489194d53e6SMatthew G. Knepley 1490194d53e6SMatthew G. Knepley Not collective 1491194d53e6SMatthew G. Knepley 1492194d53e6SMatthew G. Knepley Input Parameters: 1493dce8aebaSBarry Smith + ds - The `PetscDS` 1494194d53e6SMatthew G. Knepley . f - The test field number 1495194d53e6SMatthew G. Knepley . g - The field number 1496194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1497194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1498194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1499194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1500194d53e6SMatthew G. Knepley 1501dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 1502dce8aebaSBarry Smith .vb 1503dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1504dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1505dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1506dce8aebaSBarry Smith PetscReal t, const PetscReal x[], PetscScalar g0[]) 1507dce8aebaSBarry Smith .ve 1508194d53e6SMatthew G. Knepley + dim - the spatial dimension 1509194d53e6SMatthew G. Knepley . Nf - the number of fields 1510194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1511194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1512194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1513194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1514194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1515194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1516194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1517194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1518194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1519194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1520194d53e6SMatthew G. Knepley . t - current time 15212aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1522194d53e6SMatthew G. Knepley . x - coordinates of the current point 152397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 152497b6e6e8SMatthew G. Knepley . constants - constant parameters 1525194d53e6SMatthew G. Knepley - g0 - output values at the current point 1526194d53e6SMatthew G. Knepley 1527194d53e6SMatthew G. Knepley Level: intermediate 1528194d53e6SMatthew G. Knepley 1529dce8aebaSBarry Smith Note: 1530dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 1531dce8aebaSBarry 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 1532dce8aebaSBarry Smith 1533dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobian()` 1534194d53e6SMatthew G. Knepley @*/ 1535d71ae5a4SJacob 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[])) 1536d71ae5a4SJacob Faibussowitsch { 15372764a2aaSMatthew G. Knepley PetscFunctionBegin; 15386528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 15392764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 15402764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 15412764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 15422764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 154363a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 154463a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 15459566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 15462764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 15472764a2aaSMatthew G. Knepley } 15482764a2aaSMatthew G. Knepley 1549475e0ac9SMatthew G. Knepley /*@C 1550dce8aebaSBarry Smith PetscDSUseJacobianPreconditioner - Set whether to construct a Jacobian preconditioner 155155c1f793SMatthew G. Knepley 155255c1f793SMatthew G. Knepley Not collective 155355c1f793SMatthew G. Knepley 155455c1f793SMatthew G. Knepley Input Parameters: 1555dce8aebaSBarry Smith + prob - The `PetscDS` 155655c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner 155755c1f793SMatthew G. Knepley 155855c1f793SMatthew G. Knepley Level: intermediate 155955c1f793SMatthew G. Knepley 1560dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()` 156155c1f793SMatthew G. Knepley @*/ 1562d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre) 1563d71ae5a4SJacob Faibussowitsch { 156455c1f793SMatthew G. Knepley PetscFunctionBegin; 156555c1f793SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 156655c1f793SMatthew G. Knepley prob->useJacPre = useJacPre; 156755c1f793SMatthew G. Knepley PetscFunctionReturn(0); 156855c1f793SMatthew G. Knepley } 156955c1f793SMatthew G. Knepley 157055c1f793SMatthew G. Knepley /*@C 1571dce8aebaSBarry Smith PetscDSHasJacobianPreconditioner - Checks if a Jacobian preconditioner matrix has been set 1572475e0ac9SMatthew G. Knepley 1573475e0ac9SMatthew G. Knepley Not collective 1574475e0ac9SMatthew G. Knepley 1575475e0ac9SMatthew G. Knepley Input Parameter: 1576dce8aebaSBarry Smith . prob - The `PetscDS` 1577475e0ac9SMatthew G. Knepley 1578475e0ac9SMatthew G. Knepley Output Parameter: 1579475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set 1580475e0ac9SMatthew G. Knepley 1581475e0ac9SMatthew G. Knepley Level: intermediate 1582475e0ac9SMatthew G. Knepley 1583dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()` 1584475e0ac9SMatthew G. Knepley @*/ 1585d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre) 1586d71ae5a4SJacob Faibussowitsch { 1587475e0ac9SMatthew G. Knepley PetscFunctionBegin; 15886528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1589475e0ac9SMatthew G. Knepley *hasJacPre = PETSC_FALSE; 15906528b96dSMatthew G. Knepley if (!ds->useJacPre) PetscFunctionReturn(0); 15919566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre)); 1592475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1593475e0ac9SMatthew G. Knepley } 1594475e0ac9SMatthew G. Knepley 1595475e0ac9SMatthew G. Knepley /*@C 1596dce8aebaSBarry Smith PetscDSGetJacobianPreconditioner - Get the pointwise Jacobian preconditioner function for given test and basis field. If this is missing, 1597dce8aebaSBarry Smith the system matrix is used to build the preconditioner. 1598475e0ac9SMatthew G. Knepley 1599475e0ac9SMatthew G. Knepley Not collective 1600475e0ac9SMatthew G. Knepley 1601475e0ac9SMatthew G. Knepley Input Parameters: 1602dce8aebaSBarry Smith + ds - The `PetscDS` 1603475e0ac9SMatthew G. Knepley . f - The test field number 1604475e0ac9SMatthew G. Knepley - g - The field number 1605475e0ac9SMatthew G. Knepley 1606475e0ac9SMatthew G. Knepley Output Parameters: 1607475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term 1608475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1609475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1610475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1611475e0ac9SMatthew G. Knepley 1612dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 1613dce8aebaSBarry Smith .vb 1614dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1615dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1616dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1617dce8aebaSBarry Smith PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1618dce8aebaSBarry Smith .ve 1619475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1620475e0ac9SMatthew G. Knepley . Nf - the number of fields 1621475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1622475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1623475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1624475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1625475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1626475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1627475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1628475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1629475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1630475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1631475e0ac9SMatthew G. Knepley . t - current time 1632475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1633475e0ac9SMatthew G. Knepley . x - coordinates of the current point 163497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 163597b6e6e8SMatthew G. Knepley . constants - constant parameters 1636475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1637475e0ac9SMatthew G. Knepley 1638475e0ac9SMatthew G. Knepley Level: intermediate 1639475e0ac9SMatthew G. Knepley 1640dce8aebaSBarry Smith Note: 1641dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 1642dce8aebaSBarry 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 1643dce8aebaSBarry Smith 1644dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()` 1645475e0ac9SMatthew G. Knepley @*/ 1646d71ae5a4SJacob 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[])) 1647d71ae5a4SJacob Faibussowitsch { 16486528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 16496528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 16506528b96dSMatthew G. Knepley 1651475e0ac9SMatthew G. Knepley PetscFunctionBegin; 16526528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 165363a3b9bcSJacob 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); 165463a3b9bcSJacob 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); 16559566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 16566528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 16576528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 16586528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 16596528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 1660475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1661475e0ac9SMatthew G. Knepley } 1662475e0ac9SMatthew G. Knepley 1663475e0ac9SMatthew G. Knepley /*@C 1664dce8aebaSBarry Smith PetscDSSetJacobianPreconditioner - Set the pointwise Jacobian preconditioner function for given test and basis fields. 1665dce8aebaSBarry Smith If this is missing, the system matrix is used to build the preconditioner. 1666475e0ac9SMatthew G. Knepley 1667475e0ac9SMatthew G. Knepley Not collective 1668475e0ac9SMatthew G. Knepley 1669475e0ac9SMatthew G. Knepley Input Parameters: 1670dce8aebaSBarry Smith + ds - The `PetscDS` 1671475e0ac9SMatthew G. Knepley . f - The test field number 1672475e0ac9SMatthew G. Knepley . g - The field number 1673475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term 1674475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1675475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1676475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1677475e0ac9SMatthew G. Knepley 1678dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 1679dce8aebaSBarry Smith .vb 1680dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1681dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1682dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1683dce8aebaSBarry Smith PetscReal t, const PetscReal x[], PetscScalar g0[]) 1684dce8aebaSBarry Smith .ve 1685475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1686475e0ac9SMatthew G. Knepley . Nf - the number of fields 1687475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1688475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1689475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1690475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1691475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1692475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1693475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1694475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1695475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1696475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1697475e0ac9SMatthew G. Knepley . t - current time 1698475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1699475e0ac9SMatthew G. Knepley . x - coordinates of the current point 170097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 170197b6e6e8SMatthew G. Knepley . constants - constant parameters 1702475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1703475e0ac9SMatthew G. Knepley 1704475e0ac9SMatthew G. Knepley Level: intermediate 1705475e0ac9SMatthew G. Knepley 1706dce8aebaSBarry Smith Note: 1707dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 1708dce8aebaSBarry 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 1709dce8aebaSBarry Smith 1710dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobian()` 1711475e0ac9SMatthew G. Knepley @*/ 1712d71ae5a4SJacob 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[])) 1713d71ae5a4SJacob Faibussowitsch { 1714475e0ac9SMatthew G. Knepley PetscFunctionBegin; 17156528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1716475e0ac9SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1717475e0ac9SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1718475e0ac9SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1719475e0ac9SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 172063a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 172163a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 17229566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 1723475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1724475e0ac9SMatthew G. Knepley } 1725475e0ac9SMatthew G. Knepley 1726b7e05686SMatthew G. Knepley /*@C 1727b7e05686SMatthew G. Knepley PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set 1728b7e05686SMatthew G. Knepley 1729b7e05686SMatthew G. Knepley Not collective 1730b7e05686SMatthew G. Knepley 1731b7e05686SMatthew G. Knepley Input Parameter: 1732dce8aebaSBarry Smith . ds - The `PetscDS` 1733b7e05686SMatthew G. Knepley 1734b7e05686SMatthew G. Knepley Output Parameter: 1735b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set 1736b7e05686SMatthew G. Knepley 1737b7e05686SMatthew G. Knepley Level: intermediate 1738b7e05686SMatthew G. Knepley 1739dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetDynamicJacobian()`, `PetscDSSetDynamicJacobian()`, `PetscDSGetJacobian()` 1740b7e05686SMatthew G. Knepley @*/ 1741d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac) 1742d71ae5a4SJacob Faibussowitsch { 1743b7e05686SMatthew G. Knepley PetscFunctionBegin; 17446528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 17459566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac)); 1746b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1747b7e05686SMatthew G. Knepley } 1748b7e05686SMatthew G. Knepley 1749b7e05686SMatthew G. Knepley /*@C 1750b7e05686SMatthew G. Knepley PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field 1751b7e05686SMatthew G. Knepley 1752b7e05686SMatthew G. Knepley Not collective 1753b7e05686SMatthew G. Knepley 1754b7e05686SMatthew G. Knepley Input Parameters: 1755dce8aebaSBarry Smith + ds - The `PetscDS` 1756b7e05686SMatthew G. Knepley . f - The test field number 1757b7e05686SMatthew G. Knepley - g - The field number 1758b7e05686SMatthew G. Knepley 1759b7e05686SMatthew G. Knepley Output Parameters: 1760b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term 1761b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1762b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1763b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1764b7e05686SMatthew G. Knepley 1765dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 1766dce8aebaSBarry Smith .vb 1767dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1768dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1769dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1770dce8aebaSBarry Smith PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1771dce8aebaSBarry Smith .ve 1772b7e05686SMatthew G. Knepley + dim - the spatial dimension 1773b7e05686SMatthew G. Knepley . Nf - the number of fields 1774b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1775b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1776b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1777b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1778b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1779b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1780b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1781b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1782b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1783b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1784b7e05686SMatthew G. Knepley . t - current time 1785b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1786b7e05686SMatthew G. Knepley . x - coordinates of the current point 178797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 178897b6e6e8SMatthew G. Knepley . constants - constant parameters 1789b7e05686SMatthew G. Knepley - g0 - output values at the current point 1790b7e05686SMatthew G. Knepley 1791b7e05686SMatthew G. Knepley Level: intermediate 1792b7e05686SMatthew G. Knepley 1793dce8aebaSBarry Smith Note: 1794dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 1795dce8aebaSBarry 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 1796dce8aebaSBarry Smith 1797dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetJacobian()` 1798b7e05686SMatthew G. Knepley @*/ 1799d71ae5a4SJacob 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[])) 1800d71ae5a4SJacob Faibussowitsch { 18016528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 18026528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 18036528b96dSMatthew G. Knepley 1804b7e05686SMatthew G. Knepley PetscFunctionBegin; 18056528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 180663a3b9bcSJacob 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); 180763a3b9bcSJacob 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); 18089566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 18096528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 18106528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 18116528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 18126528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 1813b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1814b7e05686SMatthew G. Knepley } 1815b7e05686SMatthew G. Knepley 1816b7e05686SMatthew G. Knepley /*@C 1817b7e05686SMatthew G. Knepley PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields 1818b7e05686SMatthew G. Knepley 1819b7e05686SMatthew G. Knepley Not collective 1820b7e05686SMatthew G. Knepley 1821b7e05686SMatthew G. Knepley Input Parameters: 1822dce8aebaSBarry Smith + ds - The `PetscDS` 1823b7e05686SMatthew G. Knepley . f - The test field number 1824b7e05686SMatthew G. Knepley . g - The field number 1825b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term 1826b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1827b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1828b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1829b7e05686SMatthew G. Knepley 1830dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 1831dce8aebaSBarry Smith .vb 1832dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1833dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1834dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1835dce8aebaSBarry Smith PetscReal t, const PetscReal x[], PetscScalar g0[]) 1836dce8aebaSBarry Smith .ve 1837b7e05686SMatthew G. Knepley + dim - the spatial dimension 1838b7e05686SMatthew G. Knepley . Nf - the number of fields 1839b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1840b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1841b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1842b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1843b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1844b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1845b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1846b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1847b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1848b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1849b7e05686SMatthew G. Knepley . t - current time 1850b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1851b7e05686SMatthew G. Knepley . x - coordinates of the current point 185297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 185397b6e6e8SMatthew G. Knepley . constants - constant parameters 1854b7e05686SMatthew G. Knepley - g0 - output values at the current point 1855b7e05686SMatthew G. Knepley 1856b7e05686SMatthew G. Knepley Level: intermediate 1857b7e05686SMatthew G. Knepley 1858dce8aebaSBarry Smith Note: 1859dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 1860dce8aebaSBarry 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 1861dce8aebaSBarry Smith 1862dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetJacobian()` 1863b7e05686SMatthew G. Knepley @*/ 1864d71ae5a4SJacob 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[])) 1865d71ae5a4SJacob Faibussowitsch { 1866b7e05686SMatthew G. Knepley PetscFunctionBegin; 18676528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1868b7e05686SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1869b7e05686SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1870b7e05686SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1871b7e05686SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 187263a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 187363a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 18749566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 1875b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1876b7e05686SMatthew G. Knepley } 1877b7e05686SMatthew G. Knepley 18780c2f2876SMatthew G. Knepley /*@C 18790c2f2876SMatthew G. Knepley PetscDSGetRiemannSolver - Returns the Riemann solver for the given field 18800c2f2876SMatthew G. Knepley 18810c2f2876SMatthew G. Knepley Not collective 18820c2f2876SMatthew G. Knepley 18834165533cSJose E. Roman Input Parameters: 1884dce8aebaSBarry Smith + ds - The `PetscDS` object 18850c2f2876SMatthew G. Knepley - f - The field number 18860c2f2876SMatthew G. Knepley 18874165533cSJose E. Roman Output Parameter: 18880c2f2876SMatthew G. Knepley . r - Riemann solver 18890c2f2876SMatthew G. Knepley 18900c2f2876SMatthew G. Knepley Calling sequence for r: 1891dce8aebaSBarry Smith .vb 1892dce8aebaSBarry Smith r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 1893dce8aebaSBarry Smith .ve 18945db36cf9SMatthew G. Knepley + dim - The spatial dimension 18955db36cf9SMatthew G. Knepley . Nf - The number of fields 18965db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 18970c2f2876SMatthew G. Knepley . n - The normal vector to the interface 18980c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 18990c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 19000c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 190197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 190297b6e6e8SMatthew G. Knepley . constants - constant parameters 19030c2f2876SMatthew G. Knepley - ctx - optional user context 19040c2f2876SMatthew G. Knepley 19050c2f2876SMatthew G. Knepley Level: intermediate 19060c2f2876SMatthew G. Knepley 1907dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetRiemannSolver()` 19080c2f2876SMatthew G. Knepley @*/ 1909d71ae5a4SJacob 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)) 1910d71ae5a4SJacob Faibussowitsch { 19116528b96dSMatthew G. Knepley PetscRiemannFunc *tmp; 19126528b96dSMatthew G. Knepley PetscInt n; 19136528b96dSMatthew G. Knepley 19140c2f2876SMatthew G. Knepley PetscFunctionBegin; 19156528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 19160c2f2876SMatthew G. Knepley PetscValidPointer(r, 3); 191763a3b9bcSJacob 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); 19189566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, 0, &n, &tmp)); 19196528b96dSMatthew G. Knepley *r = tmp ? tmp[0] : NULL; 19200c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19210c2f2876SMatthew G. Knepley } 19220c2f2876SMatthew G. Knepley 19230c2f2876SMatthew G. Knepley /*@C 19240c2f2876SMatthew G. Knepley PetscDSSetRiemannSolver - Sets the Riemann solver for the given field 19250c2f2876SMatthew G. Knepley 19260c2f2876SMatthew G. Knepley Not collective 19270c2f2876SMatthew G. Knepley 19284165533cSJose E. Roman Input Parameters: 1929dce8aebaSBarry Smith + ds - The `PetscDS` object 19300c2f2876SMatthew G. Knepley . f - The field number 19310c2f2876SMatthew G. Knepley - r - Riemann solver 19320c2f2876SMatthew G. Knepley 19330c2f2876SMatthew G. Knepley Calling sequence for r: 1934dce8aebaSBarry Smith .vb 1935dce8aebaSBarry Smith r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 1936dce8aebaSBarry Smith .ve 19375db36cf9SMatthew G. Knepley + dim - The spatial dimension 19385db36cf9SMatthew G. Knepley . Nf - The number of fields 19395db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 19400c2f2876SMatthew G. Knepley . n - The normal vector to the interface 19410c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 19420c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 19430c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 194497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 194597b6e6e8SMatthew G. Knepley . constants - constant parameters 19460c2f2876SMatthew G. Knepley - ctx - optional user context 19470c2f2876SMatthew G. Knepley 19480c2f2876SMatthew G. Knepley Level: intermediate 19490c2f2876SMatthew G. Knepley 1950dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetRiemannSolver()` 19510c2f2876SMatthew G. Knepley @*/ 1952d71ae5a4SJacob 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)) 1953d71ae5a4SJacob Faibussowitsch { 19540c2f2876SMatthew G. Knepley PetscFunctionBegin; 19556528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1956de716cbcSToby Isaac if (r) PetscValidFunction(r, 3); 195763a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 19589566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, 0, r)); 19590c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19600c2f2876SMatthew G. Knepley } 19610c2f2876SMatthew G. Knepley 196232d2bbc9SMatthew G. Knepley /*@C 196332d2bbc9SMatthew G. Knepley PetscDSGetUpdate - Get the pointwise update function for a given field 196432d2bbc9SMatthew G. Knepley 196532d2bbc9SMatthew G. Knepley Not collective 196632d2bbc9SMatthew G. Knepley 196732d2bbc9SMatthew G. Knepley Input Parameters: 1968dce8aebaSBarry Smith + ds - The `PetscDS` 196932d2bbc9SMatthew G. Knepley - f - The field number 197032d2bbc9SMatthew G. Knepley 1971f899ff85SJose E. Roman Output Parameter: 1972a2b725a8SWilliam Gropp . update - update function 197332d2bbc9SMatthew G. Knepley 1974dce8aebaSBarry Smith Calling sequence for the callback update: 1975dce8aebaSBarry Smith .vb 1976dce8aebaSBarry Smith update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1977dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1978dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1979dce8aebaSBarry Smith PetscReal t, const PetscReal x[], PetscScalar uNew[]) 1980dce8aebaSBarry Smith .ve 198132d2bbc9SMatthew G. Knepley + dim - the spatial dimension 198232d2bbc9SMatthew G. Knepley . Nf - the number of fields 198332d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 198432d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 198532d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 198632d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 198732d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 198832d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 198932d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 199032d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 199132d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 199232d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 199332d2bbc9SMatthew G. Knepley . t - current time 199432d2bbc9SMatthew G. Knepley . x - coordinates of the current point 199532d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point 199632d2bbc9SMatthew G. Knepley 199732d2bbc9SMatthew G. Knepley Level: intermediate 199832d2bbc9SMatthew G. Knepley 1999dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetUpdate()`, `PetscDSSetResidual()` 200032d2bbc9SMatthew G. Knepley @*/ 2001d71ae5a4SJacob 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[])) 2002d71ae5a4SJacob Faibussowitsch { 200332d2bbc9SMatthew G. Knepley PetscFunctionBegin; 20046528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 200563a3b9bcSJacob 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); 20069371c9d4SSatish Balay if (update) { 20079371c9d4SSatish Balay PetscValidPointer(update, 3); 20089371c9d4SSatish Balay *update = ds->update[f]; 20099371c9d4SSatish Balay } 201032d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 201132d2bbc9SMatthew G. Knepley } 201232d2bbc9SMatthew G. Knepley 201332d2bbc9SMatthew G. Knepley /*@C 20143fa77dffSMatthew G. Knepley PetscDSSetUpdate - Set the pointwise update function for a given field 201532d2bbc9SMatthew G. Knepley 201632d2bbc9SMatthew G. Knepley Not collective 201732d2bbc9SMatthew G. Knepley 201832d2bbc9SMatthew G. Knepley Input Parameters: 2019dce8aebaSBarry Smith + ds - The `PetscDS` 202032d2bbc9SMatthew G. Knepley . f - The field number 202132d2bbc9SMatthew G. Knepley - update - update function 202232d2bbc9SMatthew G. Knepley 2023dce8aebaSBarry Smith Calling sequence for the callback update: 2024dce8aebaSBarry Smith .vb 2025dce8aebaSBarry Smith update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2026dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2027dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 2028dce8aebaSBarry Smith PetscReal t, const PetscReal x[], PetscScalar uNew[]) 2029dce8aebaSBarry Smith .ve 203032d2bbc9SMatthew G. Knepley + dim - the spatial dimension 203132d2bbc9SMatthew G. Knepley . Nf - the number of fields 203232d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 203332d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 203432d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 203532d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 203632d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 203732d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 203832d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 203932d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 204032d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 204132d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 204232d2bbc9SMatthew G. Knepley . t - current time 204332d2bbc9SMatthew G. Knepley . x - coordinates of the current point 204432d2bbc9SMatthew G. Knepley - uNew - new field values at the current point 204532d2bbc9SMatthew G. Knepley 204632d2bbc9SMatthew G. Knepley Level: intermediate 204732d2bbc9SMatthew G. Knepley 2048dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetResidual()` 204932d2bbc9SMatthew G. Knepley @*/ 2050d71ae5a4SJacob 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[])) 2051d71ae5a4SJacob Faibussowitsch { 205232d2bbc9SMatthew G. Knepley PetscFunctionBegin; 20536528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 205432d2bbc9SMatthew G. Knepley if (update) PetscValidFunction(update, 3); 205563a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 20569566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(ds, f + 1)); 20576528b96dSMatthew G. Knepley ds->update[f] = update; 205832d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 205932d2bbc9SMatthew G. Knepley } 206032d2bbc9SMatthew G. Knepley 2061d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void *ctx) 2062d71ae5a4SJacob Faibussowitsch { 20630c2f2876SMatthew G. Knepley PetscFunctionBegin; 20646528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 206563a3b9bcSJacob 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); 20660c2f2876SMatthew G. Knepley PetscValidPointer(ctx, 3); 20673ec1f749SStefano Zampini *(void **)ctx = ds->ctx[f]; 20680c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 20690c2f2876SMatthew G. Knepley } 20700c2f2876SMatthew G. Knepley 2071d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx) 2072d71ae5a4SJacob Faibussowitsch { 20730c2f2876SMatthew G. Knepley PetscFunctionBegin; 20746528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 207563a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 20769566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(ds, f + 1)); 20776528b96dSMatthew G. Knepley ds->ctx[f] = ctx; 20780c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 20790c2f2876SMatthew G. Knepley } 20800c2f2876SMatthew G. Knepley 2081194d53e6SMatthew G. Knepley /*@C 2082194d53e6SMatthew G. Knepley PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field 2083194d53e6SMatthew G. Knepley 2084194d53e6SMatthew G. Knepley Not collective 2085194d53e6SMatthew G. Knepley 2086194d53e6SMatthew G. Knepley Input Parameters: 20876528b96dSMatthew G. Knepley + ds - The PetscDS 2088194d53e6SMatthew G. Knepley - f - The test field number 2089194d53e6SMatthew G. Knepley 2090194d53e6SMatthew G. Knepley Output Parameters: 2091194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term 2092194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2093194d53e6SMatthew G. Knepley 2094dce8aebaSBarry Smith Calling sequence for the callbacks f0 and f1: 2095dce8aebaSBarry Smith .vb 2096dce8aebaSBarry Smith f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2097dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2098dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 2099dce8aebaSBarry Smith PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2100dce8aebaSBarry Smith .ve 2101194d53e6SMatthew G. Knepley + dim - the spatial dimension 2102194d53e6SMatthew G. Knepley . Nf - the number of fields 2103194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2104194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2105194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2106194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2107194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2108194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2109194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2110194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2111194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2112194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2113194d53e6SMatthew G. Knepley . t - current time 2114194d53e6SMatthew G. Knepley . x - coordinates of the current point 2115194d53e6SMatthew G. Knepley . n - unit normal at the current point 211697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 211797b6e6e8SMatthew G. Knepley . constants - constant parameters 2118194d53e6SMatthew G. Knepley - f0 - output values at the current point 2119194d53e6SMatthew G. Knepley 2120194d53e6SMatthew G. Knepley Level: intermediate 2121194d53e6SMatthew G. Knepley 2122dce8aebaSBarry Smith Note: 2123dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 2124dce8aebaSBarry 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 2125dce8aebaSBarry Smith 2126dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetBdResidual()` 2127194d53e6SMatthew G. Knepley @*/ 2128d71ae5a4SJacob 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[])) 2129d71ae5a4SJacob Faibussowitsch { 21306528b96dSMatthew G. Knepley PetscBdPointFunc *tmp0, *tmp1; 21316528b96dSMatthew G. Knepley PetscInt n0, n1; 21326528b96dSMatthew G. Knepley 21332764a2aaSMatthew G. Knepley PetscFunctionBegin; 21346528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 213563a3b9bcSJacob 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); 21369566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1)); 21376528b96dSMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 21386528b96dSMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 21392764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21402764a2aaSMatthew G. Knepley } 21412764a2aaSMatthew G. Knepley 2142194d53e6SMatthew G. Knepley /*@C 2143194d53e6SMatthew G. Knepley PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field 2144194d53e6SMatthew G. Knepley 2145194d53e6SMatthew G. Knepley Not collective 2146194d53e6SMatthew G. Knepley 2147194d53e6SMatthew G. Knepley Input Parameters: 2148dce8aebaSBarry Smith + ds - The `PetscDS` 2149194d53e6SMatthew G. Knepley . f - The test field number 2150194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term 2151194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2152194d53e6SMatthew G. Knepley 2153dce8aebaSBarry Smith Calling sequence for the callbacks f0 and f1: 2154dce8aebaSBarry Smith .vb 2155dce8aebaSBarry Smith f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2156dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2157dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 2158dce8aebaSBarry Smith PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2159dce8aebaSBarry Smith .ve 2160194d53e6SMatthew G. Knepley + dim - the spatial dimension 2161194d53e6SMatthew G. Knepley . Nf - the number of fields 2162194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2163194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2164194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2165194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2166194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2167194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2168194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2169194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2170194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2171194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2172194d53e6SMatthew G. Knepley . t - current time 2173194d53e6SMatthew G. Knepley . x - coordinates of the current point 2174194d53e6SMatthew G. Knepley . n - unit normal at the current point 217597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 217697b6e6e8SMatthew G. Knepley . constants - constant parameters 2177194d53e6SMatthew G. Knepley - f0 - output values at the current point 2178194d53e6SMatthew G. Knepley 2179194d53e6SMatthew G. Knepley Level: intermediate 2180194d53e6SMatthew G. Knepley 2181dce8aebaSBarry Smith Note: 2182dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 2183dce8aebaSBarry 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 2184dce8aebaSBarry Smith 2185dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetBdResidual()` 2186194d53e6SMatthew G. Knepley @*/ 2187d71ae5a4SJacob 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[])) 2188d71ae5a4SJacob Faibussowitsch { 21892764a2aaSMatthew G. Knepley PetscFunctionBegin; 21906528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 219163a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 21929566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1)); 21932764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21942764a2aaSMatthew G. Knepley } 21952764a2aaSMatthew G. Knepley 219627f02ce8SMatthew G. Knepley /*@ 2197dce8aebaSBarry Smith PetscDSHasBdJacobian - Indicates that boundary Jacobian functions have been set 219827f02ce8SMatthew G. Knepley 219927f02ce8SMatthew G. Knepley Not collective 220027f02ce8SMatthew G. Knepley 220127f02ce8SMatthew G. Knepley Input Parameter: 2202dce8aebaSBarry Smith . ds - The `PetscDS` 220327f02ce8SMatthew G. Knepley 220427f02ce8SMatthew G. Knepley Output Parameter: 220527f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set 220627f02ce8SMatthew G. Knepley 220727f02ce8SMatthew G. Knepley Level: intermediate 220827f02ce8SMatthew G. Knepley 2209dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()` 221027f02ce8SMatthew G. Knepley @*/ 2211d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac) 2212d71ae5a4SJacob Faibussowitsch { 221327f02ce8SMatthew G. Knepley PetscFunctionBegin; 22146528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 22156528b96dSMatthew G. Knepley PetscValidBoolPointer(hasBdJac, 2); 22169566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasBdJacobian(ds->wf, hasBdJac)); 221727f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 221827f02ce8SMatthew G. Knepley } 221927f02ce8SMatthew G. Knepley 2220194d53e6SMatthew G. Knepley /*@C 2221194d53e6SMatthew G. Knepley PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field 2222194d53e6SMatthew G. Knepley 2223194d53e6SMatthew G. Knepley Not collective 2224194d53e6SMatthew G. Knepley 2225194d53e6SMatthew G. Knepley Input Parameters: 2226dce8aebaSBarry Smith + ds - The `PetscDS` 2227194d53e6SMatthew G. Knepley . f - The test field number 2228194d53e6SMatthew G. Knepley - g - The field number 2229194d53e6SMatthew G. Knepley 2230194d53e6SMatthew G. Knepley Output Parameters: 2231194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 2232194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2233194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2234194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2235194d53e6SMatthew G. Knepley 2236dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 2237dce8aebaSBarry Smith .vb 2238dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2239dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2240dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 2241dce8aebaSBarry Smith PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2242dce8aebaSBarry Smith .ve 2243194d53e6SMatthew G. Knepley + dim - the spatial dimension 2244194d53e6SMatthew G. Knepley . Nf - the number of fields 2245194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2246194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2247194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2248194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2249194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2250194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2251194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2252194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2253194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2254194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2255194d53e6SMatthew G. Knepley . t - current time 22562aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2257194d53e6SMatthew G. Knepley . x - coordinates of the current point 2258194d53e6SMatthew G. Knepley . n - normal at the current point 225997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 226097b6e6e8SMatthew G. Knepley . constants - constant parameters 2261194d53e6SMatthew G. Knepley - g0 - output values at the current point 2262194d53e6SMatthew G. Knepley 2263194d53e6SMatthew G. Knepley Level: intermediate 2264194d53e6SMatthew G. Knepley 2265dce8aebaSBarry Smith Note: 2266dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 2267dce8aebaSBarry 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 2268dce8aebaSBarry Smith 2269dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetBdJacobian()` 2270194d53e6SMatthew G. Knepley @*/ 2271d71ae5a4SJacob 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[])) 2272d71ae5a4SJacob Faibussowitsch { 22736528b96dSMatthew G. Knepley PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3; 22746528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 22756528b96dSMatthew G. Knepley 22762764a2aaSMatthew G. Knepley PetscFunctionBegin; 22776528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 227863a3b9bcSJacob 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); 227963a3b9bcSJacob 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); 22809566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 22816528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 22826528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 22836528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 22846528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 22852764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22862764a2aaSMatthew G. Knepley } 22872764a2aaSMatthew G. Knepley 2288194d53e6SMatthew G. Knepley /*@C 2289194d53e6SMatthew G. Knepley PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field 2290194d53e6SMatthew G. Knepley 2291194d53e6SMatthew G. Knepley Not collective 2292194d53e6SMatthew G. Knepley 2293194d53e6SMatthew G. Knepley Input Parameters: 22946528b96dSMatthew G. Knepley + ds - The PetscDS 2295194d53e6SMatthew G. Knepley . f - The test field number 2296194d53e6SMatthew G. Knepley . g - The field number 2297194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 2298194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2299194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2300194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2301194d53e6SMatthew G. Knepley 2302dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 2303dce8aebaSBarry Smith .vb 2304dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2305dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2306dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 2307dce8aebaSBarry Smith PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2308dce8aebaSBarry Smith .ve 2309194d53e6SMatthew G. Knepley + dim - the spatial dimension 2310194d53e6SMatthew G. Knepley . Nf - the number of fields 2311194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2312194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2313194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2314194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2315194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2316194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2317194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2318194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2319194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2320194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2321194d53e6SMatthew G. Knepley . t - current time 23222aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2323194d53e6SMatthew G. Knepley . x - coordinates of the current point 2324194d53e6SMatthew G. Knepley . n - normal at the current point 232597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 232697b6e6e8SMatthew G. Knepley . constants - constant parameters 2327194d53e6SMatthew G. Knepley - g0 - output values at the current point 2328194d53e6SMatthew G. Knepley 2329194d53e6SMatthew G. Knepley Level: intermediate 2330194d53e6SMatthew G. Knepley 2331dce8aebaSBarry Smith Note: 2332dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 2333dce8aebaSBarry Smith \int_\Gamma \phi {\vec 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 2334dce8aebaSBarry Smith 2335dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetBdJacobian()` 2336194d53e6SMatthew G. Knepley @*/ 2337d71ae5a4SJacob 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[])) 2338d71ae5a4SJacob Faibussowitsch { 23392764a2aaSMatthew G. Knepley PetscFunctionBegin; 23406528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 23412764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 23422764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 23432764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 23442764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 234563a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 234663a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 23479566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 23482764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 23492764a2aaSMatthew G. Knepley } 23502764a2aaSMatthew G. Knepley 235127f02ce8SMatthew G. Knepley /*@ 235227f02ce8SMatthew G. Knepley PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set 235327f02ce8SMatthew G. Knepley 235427f02ce8SMatthew G. Knepley Not collective 235527f02ce8SMatthew G. Knepley 235627f02ce8SMatthew G. Knepley Input Parameter: 2357dce8aebaSBarry Smith . ds - The `PetscDS` 235827f02ce8SMatthew G. Knepley 235927f02ce8SMatthew G. Knepley Output Parameter: 236027f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set 236127f02ce8SMatthew G. Knepley 236227f02ce8SMatthew G. Knepley Level: intermediate 236327f02ce8SMatthew G. Knepley 2364dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()` 236527f02ce8SMatthew G. Knepley @*/ 2366d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre) 2367d71ae5a4SJacob Faibussowitsch { 236827f02ce8SMatthew G. Knepley PetscFunctionBegin; 23696528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 23706528b96dSMatthew G. Knepley PetscValidBoolPointer(hasBdJacPre, 2); 23719566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre)); 237227f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 237327f02ce8SMatthew G. Knepley } 237427f02ce8SMatthew G. Knepley 237527f02ce8SMatthew G. Knepley /*@C 237627f02ce8SMatthew G. Knepley PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field 237727f02ce8SMatthew G. Knepley 237827f02ce8SMatthew G. Knepley Not collective 237927f02ce8SMatthew G. Knepley 238027f02ce8SMatthew G. Knepley Input Parameters: 2381dce8aebaSBarry Smith + ds - The `PetscDS` 238227f02ce8SMatthew G. Knepley . f - The test field number 238327f02ce8SMatthew G. Knepley - g - The field number 238427f02ce8SMatthew G. Knepley 238527f02ce8SMatthew G. Knepley Output Parameters: 238627f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term 238727f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 238827f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 238927f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 239027f02ce8SMatthew G. Knepley 2391dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 2392dce8aebaSBarry Smith .vb 2393dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2394dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2395dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 2396dce8aebaSBarry Smith PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 2397dce8aebaSBarry Smith .ve 239827f02ce8SMatthew G. Knepley + dim - the spatial dimension 239927f02ce8SMatthew G. Knepley . Nf - the number of fields 240027f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 240127f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 240227f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 240327f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 240427f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 240527f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 240627f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 240727f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 240827f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 240927f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 241027f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 241127f02ce8SMatthew G. Knepley . t - current time 241227f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 241327f02ce8SMatthew G. Knepley . x - coordinates of the current point 241427f02ce8SMatthew G. Knepley . n - normal at the current point 241527f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 241627f02ce8SMatthew G. Knepley . constants - constant parameters 241727f02ce8SMatthew G. Knepley - g0 - output values at the current point 241827f02ce8SMatthew G. Knepley 241927f02ce8SMatthew G. Knepley Level: intermediate 242027f02ce8SMatthew G. Knepley 2421dce8aebaSBarry Smith Note: 2422dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 2423dce8aebaSBarry 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 2424dce8aebaSBarry Smith 2425dce8aebaSBarry Smith Fortran Note: 2426dce8aebaSBarry Smith This is not yet available in Fortran. 2427dce8aebaSBarry Smith 2428dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetBdJacobianPreconditioner()` 242927f02ce8SMatthew G. Knepley @*/ 2430d71ae5a4SJacob 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[])) 2431d71ae5a4SJacob Faibussowitsch { 24326528b96dSMatthew G. Knepley PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3; 24336528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 24346528b96dSMatthew G. Knepley 243527f02ce8SMatthew G. Knepley PetscFunctionBegin; 24366528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 243763a3b9bcSJacob 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); 243863a3b9bcSJacob 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); 24399566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 24406528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 24416528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 24426528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 24436528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 244427f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 244527f02ce8SMatthew G. Knepley } 244627f02ce8SMatthew G. Knepley 244727f02ce8SMatthew G. Knepley /*@C 244827f02ce8SMatthew G. Knepley PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field 244927f02ce8SMatthew G. Knepley 245027f02ce8SMatthew G. Knepley Not collective 245127f02ce8SMatthew G. Knepley 245227f02ce8SMatthew G. Knepley Input Parameters: 2453dce8aebaSBarry Smith + ds - The `PetscDS` 245427f02ce8SMatthew G. Knepley . f - The test field number 245527f02ce8SMatthew G. Knepley . g - The field number 245627f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term 245727f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 245827f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 245927f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 246027f02ce8SMatthew G. Knepley 2461dce8aebaSBarry Smith Calling sequence for the callbacks g0, g1, g2 and g3: 2462dce8aebaSBarry Smith .vb 2463dce8aebaSBarry Smith g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2464dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2465dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 2466dce8aebaSBarry Smith PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 2467dce8aebaSBarry Smith .ve 246827f02ce8SMatthew G. Knepley + dim - the spatial dimension 246927f02ce8SMatthew G. Knepley . Nf - the number of fields 247027f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 247127f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 247227f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 247327f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 247427f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 247527f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 247627f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 247727f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 247827f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 247927f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 248027f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 248127f02ce8SMatthew G. Knepley . t - current time 248227f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 248327f02ce8SMatthew G. Knepley . x - coordinates of the current point 248427f02ce8SMatthew G. Knepley . n - normal at the current point 248527f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 248627f02ce8SMatthew G. Knepley . constants - constant parameters 248727f02ce8SMatthew G. Knepley - g0 - output values at the current point 248827f02ce8SMatthew G. Knepley 248927f02ce8SMatthew G. Knepley Level: intermediate 249027f02ce8SMatthew G. Knepley 2491dce8aebaSBarry Smith Note: 2492dce8aebaSBarry Smith We are using a first order FEM model for the weak form: 2493dce8aebaSBarry 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 2494dce8aebaSBarry Smith 2495dce8aebaSBarry Smith Fortran Note: 2496dce8aebaSBarry Smith This is not yet available in Fortran. 2497dce8aebaSBarry Smith 2498dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetBdJacobianPreconditioner()` 249927f02ce8SMatthew G. Knepley @*/ 2500d71ae5a4SJacob 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[])) 2501d71ae5a4SJacob Faibussowitsch { 250227f02ce8SMatthew G. Knepley PetscFunctionBegin; 25036528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 250427f02ce8SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 250527f02ce8SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 250627f02ce8SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 250727f02ce8SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 250863a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 250963a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 25109566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 251127f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 251227f02ce8SMatthew G. Knepley } 251327f02ce8SMatthew G. Knepley 25140d3e9b51SMatthew G. Knepley /*@C 2515c371a6d1SMatthew G. Knepley PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field 2516c371a6d1SMatthew G. Knepley 2517c371a6d1SMatthew G. Knepley Not collective 2518c371a6d1SMatthew G. Knepley 2519c371a6d1SMatthew G. Knepley Input Parameters: 2520c371a6d1SMatthew G. Knepley + prob - The PetscDS 2521c371a6d1SMatthew G. Knepley - f - The test field number 2522c371a6d1SMatthew G. Knepley 2523d8d19677SJose E. Roman Output Parameters: 252495cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field 252595cbbfd3SMatthew G. Knepley - exactCtx - exact solution context 2526c371a6d1SMatthew G. Knepley 2527dce8aebaSBarry Smith Calling sequence for the solution functions: 2528dce8aebaSBarry Smith .vb 2529dce8aebaSBarry Smith sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2530dce8aebaSBarry Smith .ve 2531c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2532c371a6d1SMatthew G. Knepley . t - current time 2533c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2534c371a6d1SMatthew G. Knepley . Nc - the number of field components 2535c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2536c371a6d1SMatthew G. Knepley - ctx - a user context 2537c371a6d1SMatthew G. Knepley 2538c371a6d1SMatthew G. Knepley Level: intermediate 2539c371a6d1SMatthew G. Knepley 2540dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetExactSolution()`, `PetscDSGetExactSolutionTimeDerivative()` 2541c371a6d1SMatthew G. Knepley @*/ 2542d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx) 2543d71ae5a4SJacob Faibussowitsch { 2544c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2545c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 254663a3b9bcSJacob 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); 25479371c9d4SSatish Balay if (sol) { 25489371c9d4SSatish Balay PetscValidPointer(sol, 3); 25499371c9d4SSatish Balay *sol = prob->exactSol[f]; 25509371c9d4SSatish Balay } 25519371c9d4SSatish Balay if (ctx) { 25529371c9d4SSatish Balay PetscValidPointer(ctx, 4); 25539371c9d4SSatish Balay *ctx = prob->exactCtx[f]; 25549371c9d4SSatish Balay } 2555c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2556c371a6d1SMatthew G. Knepley } 2557c371a6d1SMatthew G. Knepley 2558c371a6d1SMatthew G. Knepley /*@C 2559578a5ef5SMatthew Knepley PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field 2560c371a6d1SMatthew G. Knepley 2561c371a6d1SMatthew G. Knepley Not collective 2562c371a6d1SMatthew G. Knepley 2563c371a6d1SMatthew G. Knepley Input Parameters: 2564dce8aebaSBarry Smith + prob - The `PetscDS` 2565c371a6d1SMatthew G. Knepley . f - The test field number 256695cbbfd3SMatthew G. Knepley . sol - solution function for the test fields 256795cbbfd3SMatthew G. Knepley - ctx - solution context or NULL 2568c371a6d1SMatthew G. Knepley 2569dce8aebaSBarry Smith Calling sequence for solution functions: 2570dce8aebaSBarry Smith .vb 2571dce8aebaSBarry Smith sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2572dce8aebaSBarry Smith .ve 2573c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2574c371a6d1SMatthew G. Knepley . t - current time 2575c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2576c371a6d1SMatthew G. Knepley . Nc - the number of field components 2577c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2578c371a6d1SMatthew G. Knepley - ctx - a user context 2579c371a6d1SMatthew G. Knepley 2580c371a6d1SMatthew G. Knepley Level: intermediate 2581c371a6d1SMatthew G. Knepley 2582dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetExactSolution()` 2583c371a6d1SMatthew G. Knepley @*/ 2584d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx) 2585d71ae5a4SJacob Faibussowitsch { 2586c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2587c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 258863a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 25899566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(prob, f + 1)); 25909371c9d4SSatish Balay if (sol) { 25919371c9d4SSatish Balay PetscValidFunction(sol, 3); 25929371c9d4SSatish Balay prob->exactSol[f] = sol; 25939371c9d4SSatish Balay } 25949371c9d4SSatish Balay if (ctx) { 25959371c9d4SSatish Balay PetscValidFunction(ctx, 4); 25969371c9d4SSatish Balay prob->exactCtx[f] = ctx; 25979371c9d4SSatish Balay } 2598c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2599c371a6d1SMatthew G. Knepley } 2600c371a6d1SMatthew G. Knepley 26015638fd0eSMatthew G. Knepley /*@C 2602f2cacb80SMatthew G. Knepley PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field 2603f2cacb80SMatthew G. Knepley 2604f2cacb80SMatthew G. Knepley Not collective 2605f2cacb80SMatthew G. Knepley 2606f2cacb80SMatthew G. Knepley Input Parameters: 2607dce8aebaSBarry Smith + prob - The `PetscDS` 2608f2cacb80SMatthew G. Knepley - f - The test field number 2609f2cacb80SMatthew G. Knepley 2610d8d19677SJose E. Roman Output Parameters: 2611f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field 2612f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context 2613f2cacb80SMatthew G. Knepley 2614dce8aebaSBarry Smith Calling sequence for the solution functions: 2615dce8aebaSBarry Smith .vb 2616dce8aebaSBarry Smith sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2617dce8aebaSBarry Smith .ve 2618f2cacb80SMatthew G. Knepley + dim - the spatial dimension 2619f2cacb80SMatthew G. Knepley . t - current time 2620f2cacb80SMatthew G. Knepley . x - coordinates of the current point 2621f2cacb80SMatthew G. Knepley . Nc - the number of field components 2622f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point 2623f2cacb80SMatthew G. Knepley - ctx - a user context 2624f2cacb80SMatthew G. Knepley 2625f2cacb80SMatthew G. Knepley Level: intermediate 2626f2cacb80SMatthew G. Knepley 2627dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetExactSolutionTimeDerivative()`, `PetscDSGetExactSolution()` 2628f2cacb80SMatthew G. Knepley @*/ 2629d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx) 2630d71ae5a4SJacob Faibussowitsch { 2631f2cacb80SMatthew G. Knepley PetscFunctionBegin; 2632f2cacb80SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 263363a3b9bcSJacob 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); 26349371c9d4SSatish Balay if (sol) { 26359371c9d4SSatish Balay PetscValidPointer(sol, 3); 26369371c9d4SSatish Balay *sol = prob->exactSol_t[f]; 26379371c9d4SSatish Balay } 26389371c9d4SSatish Balay if (ctx) { 26399371c9d4SSatish Balay PetscValidPointer(ctx, 4); 26409371c9d4SSatish Balay *ctx = prob->exactCtx_t[f]; 26419371c9d4SSatish Balay } 2642f2cacb80SMatthew G. Knepley PetscFunctionReturn(0); 2643f2cacb80SMatthew G. Knepley } 2644f2cacb80SMatthew G. Knepley 2645f2cacb80SMatthew G. Knepley /*@C 2646f2cacb80SMatthew G. Knepley PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field 2647f2cacb80SMatthew G. Knepley 2648f2cacb80SMatthew G. Knepley Not collective 2649f2cacb80SMatthew G. Knepley 2650f2cacb80SMatthew G. Knepley Input Parameters: 2651dce8aebaSBarry Smith + prob - The `PetscDS` 2652f2cacb80SMatthew G. Knepley . f - The test field number 2653f2cacb80SMatthew G. Knepley . sol - time derivative of the solution function for the test fields 2654f2cacb80SMatthew G. Knepley - ctx - time derivative of the solution context or NULL 2655f2cacb80SMatthew G. Knepley 2656dce8aebaSBarry Smith Calling sequence for solution functions: 2657dce8aebaSBarry Smith .vb 2658dce8aebaSBarry Smith sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2659dce8aebaSBarry Smith .ve 2660f2cacb80SMatthew G. Knepley + dim - the spatial dimension 2661f2cacb80SMatthew G. Knepley . t - current time 2662f2cacb80SMatthew G. Knepley . x - coordinates of the current point 2663f2cacb80SMatthew G. Knepley . Nc - the number of field components 2664f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point 2665f2cacb80SMatthew G. Knepley - ctx - a user context 2666f2cacb80SMatthew G. Knepley 2667f2cacb80SMatthew G. Knepley Level: intermediate 2668f2cacb80SMatthew G. Knepley 2669dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetExactSolutionTimeDerivative()`, `PetscDSSetExactSolution()` 2670f2cacb80SMatthew G. Knepley @*/ 2671d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx) 2672d71ae5a4SJacob Faibussowitsch { 2673f2cacb80SMatthew G. Knepley PetscFunctionBegin; 2674f2cacb80SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 267563a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 26769566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(prob, f + 1)); 26779371c9d4SSatish Balay if (sol) { 26789371c9d4SSatish Balay PetscValidFunction(sol, 3); 26799371c9d4SSatish Balay prob->exactSol_t[f] = sol; 26809371c9d4SSatish Balay } 26819371c9d4SSatish Balay if (ctx) { 26829371c9d4SSatish Balay PetscValidFunction(ctx, 4); 26839371c9d4SSatish Balay prob->exactCtx_t[f] = ctx; 26849371c9d4SSatish Balay } 2685f2cacb80SMatthew G. Knepley PetscFunctionReturn(0); 2686f2cacb80SMatthew G. Knepley } 2687f2cacb80SMatthew G. Knepley 2688f2cacb80SMatthew G. Knepley /*@C 268997b6e6e8SMatthew G. Knepley PetscDSGetConstants - Returns the array of constants passed to point functions 269097b6e6e8SMatthew G. Knepley 269197b6e6e8SMatthew G. Knepley Not collective 269297b6e6e8SMatthew G. Knepley 269397b6e6e8SMatthew G. Knepley Input Parameter: 2694dce8aebaSBarry Smith . prob - The `PetscDS` object 269597b6e6e8SMatthew G. Knepley 269697b6e6e8SMatthew G. Knepley Output Parameters: 269797b6e6e8SMatthew G. Knepley + numConstants - The number of constants 269897b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 269997b6e6e8SMatthew G. Knepley 270097b6e6e8SMatthew G. Knepley Level: intermediate 270197b6e6e8SMatthew G. Knepley 2702dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSetConstants()`, `PetscDSCreate()` 270397b6e6e8SMatthew G. Knepley @*/ 2704d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[]) 2705d71ae5a4SJacob Faibussowitsch { 270697b6e6e8SMatthew G. Knepley PetscFunctionBegin; 270797b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 27089371c9d4SSatish Balay if (numConstants) { 27099371c9d4SSatish Balay PetscValidIntPointer(numConstants, 2); 27109371c9d4SSatish Balay *numConstants = prob->numConstants; 27119371c9d4SSatish Balay } 27129371c9d4SSatish Balay if (constants) { 27139371c9d4SSatish Balay PetscValidPointer(constants, 3); 27149371c9d4SSatish Balay *constants = prob->constants; 27159371c9d4SSatish Balay } 271697b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 271797b6e6e8SMatthew G. Knepley } 271897b6e6e8SMatthew G. Knepley 27190d3e9b51SMatthew G. Knepley /*@C 272097b6e6e8SMatthew G. Knepley PetscDSSetConstants - Set the array of constants passed to point functions 272197b6e6e8SMatthew G. Knepley 272297b6e6e8SMatthew G. Knepley Not collective 272397b6e6e8SMatthew G. Knepley 272497b6e6e8SMatthew G. Knepley Input Parameters: 2725dce8aebaSBarry Smith + prob - The `PetscDS` object 272697b6e6e8SMatthew G. Knepley . numConstants - The number of constants 272797b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 272897b6e6e8SMatthew G. Knepley 272997b6e6e8SMatthew G. Knepley Level: intermediate 273097b6e6e8SMatthew G. Knepley 2731dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetConstants()`, `PetscDSCreate()` 273297b6e6e8SMatthew G. Knepley @*/ 2733d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[]) 2734d71ae5a4SJacob Faibussowitsch { 273597b6e6e8SMatthew G. Knepley PetscFunctionBegin; 273697b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 273797b6e6e8SMatthew G. Knepley if (numConstants != prob->numConstants) { 27389566063dSJacob Faibussowitsch PetscCall(PetscFree(prob->constants)); 273997b6e6e8SMatthew G. Knepley prob->numConstants = numConstants; 274097b6e6e8SMatthew G. Knepley if (prob->numConstants) { 27419566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(prob->numConstants, &prob->constants)); 274220be0f5bSMatthew G. Knepley } else { 274320be0f5bSMatthew G. Knepley prob->constants = NULL; 274420be0f5bSMatthew G. Knepley } 274520be0f5bSMatthew G. Knepley } 274620be0f5bSMatthew G. Knepley if (prob->numConstants) { 2747dadcf809SJacob Faibussowitsch PetscValidScalarPointer(constants, 3); 27489566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(prob->constants, constants, prob->numConstants)); 274997b6e6e8SMatthew G. Knepley } 275097b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 275197b6e6e8SMatthew G. Knepley } 275297b6e6e8SMatthew G. Knepley 27534cd1e086SMatthew G. Knepley /*@ 27544cd1e086SMatthew G. Knepley PetscDSGetFieldIndex - Returns the index of the given field 27554cd1e086SMatthew G. Knepley 27564cd1e086SMatthew G. Knepley Not collective 27574cd1e086SMatthew G. Knepley 27584cd1e086SMatthew G. Knepley Input Parameters: 2759dce8aebaSBarry Smith + prob - The `PetscDS` object 27604cd1e086SMatthew G. Knepley - disc - The discretization object 27614cd1e086SMatthew G. Knepley 27624cd1e086SMatthew G. Knepley Output Parameter: 27634cd1e086SMatthew G. Knepley . f - The field number 27644cd1e086SMatthew G. Knepley 27654cd1e086SMatthew G. Knepley Level: beginner 27664cd1e086SMatthew G. Knepley 2767dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscGetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 27684cd1e086SMatthew G. Knepley @*/ 2769d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f) 2770d71ae5a4SJacob Faibussowitsch { 27714cd1e086SMatthew G. Knepley PetscInt g; 27724cd1e086SMatthew G. Knepley 27734cd1e086SMatthew G. Knepley PetscFunctionBegin; 27744cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2775dadcf809SJacob Faibussowitsch PetscValidIntPointer(f, 3); 27764cd1e086SMatthew G. Knepley *f = -1; 27779371c9d4SSatish Balay for (g = 0; g < prob->Nf; ++g) { 27789371c9d4SSatish Balay if (disc == prob->disc[g]) break; 27799371c9d4SSatish Balay } 278008401ef6SPierre Jolivet PetscCheck(g != prob->Nf, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS."); 27814cd1e086SMatthew G. Knepley *f = g; 27824cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 27834cd1e086SMatthew G. Knepley } 27844cd1e086SMatthew G. Knepley 27854cd1e086SMatthew G. Knepley /*@ 27864cd1e086SMatthew G. Knepley PetscDSGetFieldSize - Returns the size of the given field in the full space basis 27874cd1e086SMatthew G. Knepley 27884cd1e086SMatthew G. Knepley Not collective 27894cd1e086SMatthew G. Knepley 27904cd1e086SMatthew G. Knepley Input Parameters: 2791dce8aebaSBarry Smith + prob - The `PetscDS` object 27924cd1e086SMatthew G. Knepley - f - The field number 27934cd1e086SMatthew G. Knepley 27944cd1e086SMatthew G. Knepley Output Parameter: 27954cd1e086SMatthew G. Knepley . size - The size 27964cd1e086SMatthew G. Knepley 27974cd1e086SMatthew G. Knepley Level: beginner 27984cd1e086SMatthew G. Knepley 2799dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetFieldOffset()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 28004cd1e086SMatthew G. Knepley @*/ 2801d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size) 2802d71ae5a4SJacob Faibussowitsch { 28034cd1e086SMatthew G. Knepley PetscFunctionBegin; 28044cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2805dadcf809SJacob Faibussowitsch PetscValidIntPointer(size, 3); 280663a3b9bcSJacob 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); 28079566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 2808d4742ddaSMatthew G. Knepley *size = prob->Nb[f]; 28094cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 28104cd1e086SMatthew G. Knepley } 28114cd1e086SMatthew G. Knepley 2812bc4ae4beSMatthew G. Knepley /*@ 2813bc4ae4beSMatthew G. Knepley PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis 2814bc4ae4beSMatthew G. Knepley 2815bc4ae4beSMatthew G. Knepley Not collective 2816bc4ae4beSMatthew G. Knepley 2817bc4ae4beSMatthew G. Knepley Input Parameters: 2818dce8aebaSBarry Smith + prob - The `PetscDS` object 2819bc4ae4beSMatthew G. Knepley - f - The field number 2820bc4ae4beSMatthew G. Knepley 2821bc4ae4beSMatthew G. Knepley Output Parameter: 2822bc4ae4beSMatthew G. Knepley . off - The offset 2823bc4ae4beSMatthew G. Knepley 2824bc4ae4beSMatthew G. Knepley Level: beginner 2825bc4ae4beSMatthew G. Knepley 2826dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 2827bc4ae4beSMatthew G. Knepley @*/ 2828d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 2829d71ae5a4SJacob Faibussowitsch { 28304cd1e086SMatthew G. Knepley PetscInt size, g; 28312764a2aaSMatthew G. Knepley 28322764a2aaSMatthew G. Knepley PetscFunctionBegin; 28332764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2834dadcf809SJacob Faibussowitsch PetscValidIntPointer(off, 3); 283563a3b9bcSJacob 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); 28362764a2aaSMatthew G. Knepley *off = 0; 28372764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 28389566063dSJacob Faibussowitsch PetscCall(PetscDSGetFieldSize(prob, g, &size)); 28394cd1e086SMatthew G. Knepley *off += size; 28402764a2aaSMatthew G. Knepley } 28412764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 28422764a2aaSMatthew G. Knepley } 28432764a2aaSMatthew G. Knepley 2844bc4ae4beSMatthew G. Knepley /*@ 28455fedec97SMatthew G. Knepley PetscDSGetFieldOffsetCohesive - Returns the offset of the given field in the full space basis on a cohesive cell 28465fedec97SMatthew G. Knepley 28475fedec97SMatthew G. Knepley Not collective 28485fedec97SMatthew G. Knepley 28495fedec97SMatthew G. Knepley Input Parameters: 2850dce8aebaSBarry Smith + prob - The `PetscDS` object 28515fedec97SMatthew G. Knepley - f - The field number 28525fedec97SMatthew G. Knepley 28535fedec97SMatthew G. Knepley Output Parameter: 28545fedec97SMatthew G. Knepley . off - The offset 28555fedec97SMatthew G. Knepley 28565fedec97SMatthew G. Knepley Level: beginner 28575fedec97SMatthew G. Knepley 2858dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 28595fedec97SMatthew G. Knepley @*/ 2860d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFieldOffsetCohesive(PetscDS ds, PetscInt f, PetscInt *off) 2861d71ae5a4SJacob Faibussowitsch { 28625fedec97SMatthew G. Knepley PetscInt size, g; 28635fedec97SMatthew G. Knepley 28645fedec97SMatthew G. Knepley PetscFunctionBegin; 28655fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 2866dadcf809SJacob Faibussowitsch PetscValidIntPointer(off, 3); 286763a3b9bcSJacob 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); 28685fedec97SMatthew G. Knepley *off = 0; 28695fedec97SMatthew G. Knepley for (g = 0; g < f; ++g) { 28705fedec97SMatthew G. Knepley PetscBool cohesive; 28715fedec97SMatthew G. Knepley 28729566063dSJacob Faibussowitsch PetscCall(PetscDSGetCohesive(ds, g, &cohesive)); 28739566063dSJacob Faibussowitsch PetscCall(PetscDSGetFieldSize(ds, g, &size)); 28745fedec97SMatthew G. Knepley *off += cohesive ? size : size * 2; 28755fedec97SMatthew G. Knepley } 28765fedec97SMatthew G. Knepley PetscFunctionReturn(0); 28775fedec97SMatthew G. Knepley } 28785fedec97SMatthew G. Knepley 28795fedec97SMatthew G. Knepley /*@ 288047e57110SSander Arens PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point 2881bc4ae4beSMatthew G. Knepley 2882bc4ae4beSMatthew G. Knepley Not collective 2883bc4ae4beSMatthew G. Knepley 288447e57110SSander Arens Input Parameter: 2885dce8aebaSBarry Smith . prob - The `PetscDS` object 2886bc4ae4beSMatthew G. Knepley 2887bc4ae4beSMatthew G. Knepley Output Parameter: 288847e57110SSander Arens . dimensions - The number of dimensions 2889bc4ae4beSMatthew G. Knepley 2890bc4ae4beSMatthew G. Knepley Level: beginner 2891bc4ae4beSMatthew G. Knepley 2892dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 2893bc4ae4beSMatthew G. Knepley @*/ 2894d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[]) 2895d71ae5a4SJacob Faibussowitsch { 28962764a2aaSMatthew G. Knepley PetscFunctionBegin; 28972764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 28989566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 289947e57110SSander Arens PetscValidPointer(dimensions, 2); 290047e57110SSander Arens *dimensions = prob->Nb; 290147e57110SSander Arens PetscFunctionReturn(0); 29026ce16762SMatthew G. Knepley } 290347e57110SSander Arens 290447e57110SSander Arens /*@ 290547e57110SSander Arens PetscDSGetComponents - Returns the number of components for each field on an evaluation point 290647e57110SSander Arens 290747e57110SSander Arens Not collective 290847e57110SSander Arens 290947e57110SSander Arens Input Parameter: 2910dce8aebaSBarry Smith . prob - The `PetscDS` object 291147e57110SSander Arens 291247e57110SSander Arens Output Parameter: 291347e57110SSander Arens . components - The number of components 291447e57110SSander Arens 291547e57110SSander Arens Level: beginner 291647e57110SSander Arens 2917dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 291847e57110SSander Arens @*/ 2919d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[]) 2920d71ae5a4SJacob Faibussowitsch { 292147e57110SSander Arens PetscFunctionBegin; 292247e57110SSander Arens PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 29239566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 292447e57110SSander Arens PetscValidPointer(components, 2); 292547e57110SSander Arens *components = prob->Nc; 29266ce16762SMatthew G. Knepley PetscFunctionReturn(0); 29276ce16762SMatthew G. Knepley } 29286ce16762SMatthew G. Knepley 29296ce16762SMatthew G. Knepley /*@ 29306ce16762SMatthew G. Knepley PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point 29316ce16762SMatthew G. Knepley 29326ce16762SMatthew G. Knepley Not collective 29336ce16762SMatthew G. Knepley 29346ce16762SMatthew G. Knepley Input Parameters: 2935dce8aebaSBarry Smith + prob - The `PetscDS` object 29366ce16762SMatthew G. Knepley - f - The field number 29376ce16762SMatthew G. Knepley 29386ce16762SMatthew G. Knepley Output Parameter: 29396ce16762SMatthew G. Knepley . off - The offset 29406ce16762SMatthew G. Knepley 29416ce16762SMatthew G. Knepley Level: beginner 29426ce16762SMatthew G. Knepley 2943dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()` 29446ce16762SMatthew G. Knepley @*/ 2945d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off) 2946d71ae5a4SJacob Faibussowitsch { 29476ce16762SMatthew G. Knepley PetscFunctionBegin; 29486ce16762SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2949dadcf809SJacob Faibussowitsch PetscValidIntPointer(off, 3); 295063a3b9bcSJacob 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); 29519566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 295247e57110SSander Arens *off = prob->off[f]; 29532764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 29542764a2aaSMatthew G. Knepley } 29552764a2aaSMatthew G. Knepley 2956194d53e6SMatthew G. Knepley /*@ 2957194d53e6SMatthew G. Knepley PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point 2958194d53e6SMatthew G. Knepley 2959194d53e6SMatthew G. Knepley Not collective 2960194d53e6SMatthew G. Knepley 2961194d53e6SMatthew G. Knepley Input Parameter: 2962dce8aebaSBarry Smith . prob - The `PetscDS` object 2963194d53e6SMatthew G. Knepley 2964194d53e6SMatthew G. Knepley Output Parameter: 2965194d53e6SMatthew G. Knepley . offsets - The offsets 2966194d53e6SMatthew G. Knepley 2967194d53e6SMatthew G. Knepley Level: beginner 2968194d53e6SMatthew G. Knepley 2969dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()` 2970194d53e6SMatthew G. Knepley @*/ 2971d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[]) 2972d71ae5a4SJacob Faibussowitsch { 2973194d53e6SMatthew G. Knepley PetscFunctionBegin; 2974194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2975194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 29769566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 2977194d53e6SMatthew G. Knepley *offsets = prob->off; 2978194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2979194d53e6SMatthew G. Knepley } 2980194d53e6SMatthew G. Knepley 2981194d53e6SMatthew G. Knepley /*@ 2982194d53e6SMatthew G. Knepley PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point 2983194d53e6SMatthew G. Knepley 2984194d53e6SMatthew G. Knepley Not collective 2985194d53e6SMatthew G. Knepley 2986194d53e6SMatthew G. Knepley Input Parameter: 2987dce8aebaSBarry Smith . prob - The `PetscDS` object 2988194d53e6SMatthew G. Knepley 2989194d53e6SMatthew G. Knepley Output Parameter: 2990194d53e6SMatthew G. Knepley . offsets - The offsets 2991194d53e6SMatthew G. Knepley 2992194d53e6SMatthew G. Knepley Level: beginner 2993194d53e6SMatthew G. Knepley 2994dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()` 2995194d53e6SMatthew G. Knepley @*/ 2996d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[]) 2997d71ae5a4SJacob Faibussowitsch { 2998194d53e6SMatthew G. Knepley PetscFunctionBegin; 2999194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3000194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 30019566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 3002194d53e6SMatthew G. Knepley *offsets = prob->offDer; 3003194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 3004194d53e6SMatthew G. Knepley } 3005194d53e6SMatthew G. Knepley 30069ee2af8cSMatthew G. Knepley /*@ 30079ee2af8cSMatthew G. Knepley PetscDSGetComponentOffsetsCohesive - Returns the offset of each field on an evaluation point 30089ee2af8cSMatthew G. Knepley 30099ee2af8cSMatthew G. Knepley Not collective 30109ee2af8cSMatthew G. Knepley 30119ee2af8cSMatthew G. Knepley Input Parameters: 3012dce8aebaSBarry Smith + ds - The `PetscDS` object 30139ee2af8cSMatthew G. Knepley - s - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive 30149ee2af8cSMatthew G. Knepley 30159ee2af8cSMatthew G. Knepley Output Parameter: 30169ee2af8cSMatthew G. Knepley . offsets - The offsets 30179ee2af8cSMatthew G. Knepley 30189ee2af8cSMatthew G. Knepley Level: beginner 30199ee2af8cSMatthew G. Knepley 3020dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()` 30219ee2af8cSMatthew G. Knepley @*/ 3022d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[]) 3023d71ae5a4SJacob Faibussowitsch { 30249ee2af8cSMatthew G. Knepley PetscFunctionBegin; 30259ee2af8cSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 30269ee2af8cSMatthew G. Knepley PetscValidPointer(offsets, 3); 302728b400f6SJacob Faibussowitsch PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS"); 302863a3b9bcSJacob Faibussowitsch PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s); 30299566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(ds)); 30309ee2af8cSMatthew G. Knepley *offsets = ds->offCohesive[s]; 30319ee2af8cSMatthew G. Knepley PetscFunctionReturn(0); 30329ee2af8cSMatthew G. Knepley } 30339ee2af8cSMatthew G. Knepley 30349ee2af8cSMatthew G. Knepley /*@ 30359ee2af8cSMatthew G. Knepley PetscDSGetComponentDerivativeOffsetsCohesive - Returns the offset of each field derivative on an evaluation point 30369ee2af8cSMatthew G. Knepley 30379ee2af8cSMatthew G. Knepley Not collective 30389ee2af8cSMatthew G. Knepley 30399ee2af8cSMatthew G. Knepley Input Parameters: 3040dce8aebaSBarry Smith + ds - The `PetscDS` object 30419ee2af8cSMatthew G. Knepley - s - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive 30429ee2af8cSMatthew G. Knepley 30439ee2af8cSMatthew G. Knepley Output Parameter: 30449ee2af8cSMatthew G. Knepley . offsets - The offsets 30459ee2af8cSMatthew G. Knepley 30469ee2af8cSMatthew G. Knepley Level: beginner 30479ee2af8cSMatthew G. Knepley 3048dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSGetNumFields()`, `PetscDSCreate()` 30499ee2af8cSMatthew G. Knepley @*/ 3050d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetComponentDerivativeOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[]) 3051d71ae5a4SJacob Faibussowitsch { 30529ee2af8cSMatthew G. Knepley PetscFunctionBegin; 30539ee2af8cSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 30549ee2af8cSMatthew G. Knepley PetscValidPointer(offsets, 3); 305528b400f6SJacob Faibussowitsch PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS"); 305663a3b9bcSJacob Faibussowitsch PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s); 30579566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(ds)); 30589ee2af8cSMatthew G. Knepley *offsets = ds->offDerCohesive[s]; 30599ee2af8cSMatthew G. Knepley PetscFunctionReturn(0); 30609ee2af8cSMatthew G. Knepley } 30619ee2af8cSMatthew G. Knepley 306268c9edb9SMatthew G. Knepley /*@C 306368c9edb9SMatthew G. Knepley PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization 306468c9edb9SMatthew G. Knepley 306568c9edb9SMatthew G. Knepley Not collective 306668c9edb9SMatthew G. Knepley 306768c9edb9SMatthew G. Knepley Input Parameter: 3068dce8aebaSBarry Smith . prob - The `PetscDS` object 306968c9edb9SMatthew G. Knepley 3070ef0bb6c7SMatthew G. Knepley Output Parameter: 3071ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field 307268c9edb9SMatthew G. Knepley 307368c9edb9SMatthew G. Knepley Level: intermediate 307468c9edb9SMatthew G. Knepley 3075dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscTabulation`, `PetscDSCreate()` 307668c9edb9SMatthew G. Knepley @*/ 3077d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[]) 3078d71ae5a4SJacob Faibussowitsch { 30792764a2aaSMatthew G. Knepley PetscFunctionBegin; 30802764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3081ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 2); 30829566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 3083ef0bb6c7SMatthew G. Knepley *T = prob->T; 30842764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30852764a2aaSMatthew G. Knepley } 30862764a2aaSMatthew G. Knepley 308768c9edb9SMatthew G. Knepley /*@C 30884d0b9603SSander Arens PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces 308968c9edb9SMatthew G. Knepley 309068c9edb9SMatthew G. Knepley Not collective 309168c9edb9SMatthew G. Knepley 309268c9edb9SMatthew G. Knepley Input Parameter: 3093dce8aebaSBarry Smith . prob - The `PetscDS` object 309468c9edb9SMatthew G. Knepley 3095ef0bb6c7SMatthew G. Knepley Output Parameter: 3096a5b23f4aSJose E. Roman . Tf - The basis function and derivative tabulation on each local face at quadrature points for each and field 309768c9edb9SMatthew G. Knepley 309868c9edb9SMatthew G. Knepley Level: intermediate 309968c9edb9SMatthew G. Knepley 3100dce8aebaSBarry Smith .seealso: `PetscTabulation`, `PetscDS`, `PetscDSGetTabulation()`, `PetscDSCreate()` 310168c9edb9SMatthew G. Knepley @*/ 3102d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[]) 3103d71ae5a4SJacob Faibussowitsch { 31042764a2aaSMatthew G. Knepley PetscFunctionBegin; 31052764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3106ef0bb6c7SMatthew G. Knepley PetscValidPointer(Tf, 2); 31079566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 3108ef0bb6c7SMatthew G. Knepley *Tf = prob->Tf; 31092764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31102764a2aaSMatthew G. Knepley } 31112764a2aaSMatthew G. Knepley 3112d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) 3113d71ae5a4SJacob Faibussowitsch { 31142764a2aaSMatthew G. Knepley PetscFunctionBegin; 31152764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 31169566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 31179371c9d4SSatish Balay if (u) { 31189371c9d4SSatish Balay PetscValidPointer(u, 2); 31199371c9d4SSatish Balay *u = prob->u; 31209371c9d4SSatish Balay } 31219371c9d4SSatish Balay if (u_t) { 31229371c9d4SSatish Balay PetscValidPointer(u_t, 3); 31239371c9d4SSatish Balay *u_t = prob->u_t; 31249371c9d4SSatish Balay } 31259371c9d4SSatish Balay if (u_x) { 31269371c9d4SSatish Balay PetscValidPointer(u_x, 4); 31279371c9d4SSatish Balay *u_x = prob->u_x; 31289371c9d4SSatish Balay } 31292764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31302764a2aaSMatthew G. Knepley } 31312764a2aaSMatthew G. Knepley 3132d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) 3133d71ae5a4SJacob Faibussowitsch { 31342764a2aaSMatthew G. Knepley PetscFunctionBegin; 31352764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 31369566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 31379371c9d4SSatish Balay if (f0) { 31389371c9d4SSatish Balay PetscValidPointer(f0, 2); 31399371c9d4SSatish Balay *f0 = prob->f0; 31409371c9d4SSatish Balay } 31419371c9d4SSatish Balay if (f1) { 31429371c9d4SSatish Balay PetscValidPointer(f1, 3); 31439371c9d4SSatish Balay *f1 = prob->f1; 31449371c9d4SSatish Balay } 31459371c9d4SSatish Balay if (g0) { 31469371c9d4SSatish Balay PetscValidPointer(g0, 4); 31479371c9d4SSatish Balay *g0 = prob->g0; 31489371c9d4SSatish Balay } 31499371c9d4SSatish Balay if (g1) { 31509371c9d4SSatish Balay PetscValidPointer(g1, 5); 31519371c9d4SSatish Balay *g1 = prob->g1; 31529371c9d4SSatish Balay } 31539371c9d4SSatish Balay if (g2) { 31549371c9d4SSatish Balay PetscValidPointer(g2, 6); 31559371c9d4SSatish Balay *g2 = prob->g2; 31569371c9d4SSatish Balay } 31579371c9d4SSatish Balay if (g3) { 31589371c9d4SSatish Balay PetscValidPointer(g3, 7); 31599371c9d4SSatish Balay *g3 = prob->g3; 31609371c9d4SSatish Balay } 31612764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31622764a2aaSMatthew G. Knepley } 31632764a2aaSMatthew G. Knepley 3164d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal) 3165d71ae5a4SJacob Faibussowitsch { 31662764a2aaSMatthew G. Knepley PetscFunctionBegin; 31672764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 31689566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 31699371c9d4SSatish Balay if (x) { 31709371c9d4SSatish Balay PetscValidPointer(x, 2); 31719371c9d4SSatish Balay *x = prob->x; 31729371c9d4SSatish Balay } 31739371c9d4SSatish Balay if (basisReal) { 31749371c9d4SSatish Balay PetscValidPointer(basisReal, 3); 31759371c9d4SSatish Balay *basisReal = prob->basisReal; 31769371c9d4SSatish Balay } 31779371c9d4SSatish Balay if (basisDerReal) { 31789371c9d4SSatish Balay PetscValidPointer(basisDerReal, 4); 31799371c9d4SSatish Balay *basisDerReal = prob->basisDerReal; 31809371c9d4SSatish Balay } 31819371c9d4SSatish Balay if (testReal) { 31829371c9d4SSatish Balay PetscValidPointer(testReal, 5); 31839371c9d4SSatish Balay *testReal = prob->testReal; 31849371c9d4SSatish Balay } 31859371c9d4SSatish Balay if (testDerReal) { 31869371c9d4SSatish Balay PetscValidPointer(testDerReal, 6); 31879371c9d4SSatish Balay *testDerReal = prob->testDerReal; 31889371c9d4SSatish Balay } 31892764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31902764a2aaSMatthew G. Knepley } 31912764a2aaSMatthew G. Knepley 319258ebd649SToby Isaac /*@C 3193dce8aebaSBarry Smith PetscDSAddBoundary - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. 3194dce8aebaSBarry 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 3195dce8aebaSBarry Smith integrals should be performed, using the kernels from `PetscDSSetBdResidual()`. 319658ebd649SToby Isaac 3197783e2ec8SMatthew G. Knepley Collective on ds 3198783e2ec8SMatthew G. Knepley 319958ebd649SToby Isaac Input Parameters: 320058ebd649SToby Isaac + ds - The PetscDS object 3201dce8aebaSBarry Smith . type - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann) 320258ebd649SToby Isaac . name - The BC name 320345480ffeSMatthew G. Knepley . label - The label defining constrained points 3204dce8aebaSBarry Smith . Nv - The number of `DMLabel` values for constrained points 320545480ffeSMatthew G. Knepley . values - An array of label values for constrained points 320658ebd649SToby Isaac . field - The field to constrain 320745480ffeSMatthew G. Knepley . Nc - The number of constrained field components (0 will constrain all fields) 320858ebd649SToby Isaac . comps - An array of constrained component numbers 320958ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 3210a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL 321158ebd649SToby Isaac - ctx - An optional user context for bcFunc 321258ebd649SToby Isaac 321345480ffeSMatthew G. Knepley Output Parameters: 321445480ffeSMatthew G. Knepley - bd - The boundary number 321545480ffeSMatthew G. Knepley 321658ebd649SToby Isaac Options Database Keys: 321758ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 321858ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 321958ebd649SToby Isaac 3220dce8aebaSBarry Smith Level: developer 3221dce8aebaSBarry Smith 322256cf3b9cSMatthew G. Knepley Note: 3223dce8aebaSBarry Smith Both bcFunc abd bcFunc_t will depend on the boundary condition type. If the type if `DM_BC_ESSENTIAL`, Then the calling sequence is: 322456cf3b9cSMatthew G. Knepley 322556cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[]) 322656cf3b9cSMatthew G. Knepley 3227dce8aebaSBarry Smith If the type is `DM_BC_ESSENTIAL_FIELD` or other _FIELD value, then the calling sequence is: 3228dce8aebaSBarry Smith .vb 3229dce8aebaSBarry Smith bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux, 3230dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 3231dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 3232dce8aebaSBarry Smith PetscReal time, const PetscReal x[], PetscScalar bcval[]) 3233dce8aebaSBarry Smith .ve 323456cf3b9cSMatthew G. Knepley + dim - the spatial dimension 323556cf3b9cSMatthew G. Knepley . Nf - the number of fields 323656cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 323756cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 323856cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point 323956cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 324056cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 324156cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 324256cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 324356cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point 324456cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 324556cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 324656cf3b9cSMatthew G. Knepley . t - current time 324756cf3b9cSMatthew G. Knepley . x - coordinates of the current point 324856cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters 324956cf3b9cSMatthew G. Knepley . constants - constant parameters 325056cf3b9cSMatthew G. Knepley - bcval - output values at the current point 325156cf3b9cSMatthew G. Knepley 3252dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMLabel`, `DMBoundaryConditionType`, `PetscDSAddBoundaryByName()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()` 325358ebd649SToby Isaac @*/ 3254d71ae5a4SJacob 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) 3255d71ae5a4SJacob Faibussowitsch { 325645480ffeSMatthew G. Knepley DSBoundary head = ds->boundary, b; 325745480ffeSMatthew G. Knepley PetscInt n = 0; 325845480ffeSMatthew G. Knepley const char *lname; 325958ebd649SToby Isaac 326058ebd649SToby Isaac PetscFunctionBegin; 326158ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3262783e2ec8SMatthew G. Knepley PetscValidLogicalCollectiveEnum(ds, type, 2); 326345480ffeSMatthew G. Knepley PetscValidCharPointer(name, 3); 326445480ffeSMatthew G. Knepley PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4); 326545480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nv, 5); 326645480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, field, 7); 326745480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nc, 8); 3268dce9da9cSMatthew 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); 3269d57bb9dbSMatthew G. Knepley if (Nc > 0) { 3270d57bb9dbSMatthew G. Knepley PetscInt *fcomps; 3271d57bb9dbSMatthew G. Knepley PetscInt c; 3272d57bb9dbSMatthew G. Knepley 32739566063dSJacob Faibussowitsch PetscCall(PetscDSGetComponents(ds, &fcomps)); 327463a3b9bcSJacob 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); 3275d57bb9dbSMatthew G. Knepley for (c = 0; c < Nc; ++c) { 32761dca8a05SBarry 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); 3277d57bb9dbSMatthew G. Knepley } 3278d57bb9dbSMatthew G. Knepley } 32799566063dSJacob Faibussowitsch PetscCall(PetscNew(&b)); 32809566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&b->name)); 32819566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf)); 32829566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf)); 32839566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nv, &b->values)); 32849566063dSJacob Faibussowitsch if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv)); 32859566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nc, &b->comps)); 32869566063dSJacob Faibussowitsch if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc)); 32879566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject)label, &lname)); 32889566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(lname, (char **)&b->lname)); 3289f971fd6bSMatthew G. Knepley b->type = type; 329045480ffeSMatthew G. Knepley b->label = label; 329145480ffeSMatthew G. Knepley b->Nv = Nv; 329258ebd649SToby Isaac b->field = field; 329345480ffeSMatthew G. Knepley b->Nc = Nc; 329458ebd649SToby Isaac b->func = bcFunc; 329556cf3b9cSMatthew G. Knepley b->func_t = bcFunc_t; 329658ebd649SToby Isaac b->ctx = ctx; 329745480ffeSMatthew G. Knepley b->next = NULL; 329845480ffeSMatthew G. Knepley /* Append to linked list so that we can preserve the order */ 329945480ffeSMatthew G. Knepley if (!head) ds->boundary = b; 330045480ffeSMatthew G. Knepley while (head) { 330145480ffeSMatthew G. Knepley if (!head->next) { 330245480ffeSMatthew G. Knepley head->next = b; 330345480ffeSMatthew G. Knepley head = b; 330445480ffeSMatthew G. Knepley } 330545480ffeSMatthew G. Knepley head = head->next; 330645480ffeSMatthew G. Knepley ++n; 330745480ffeSMatthew G. Knepley } 33089371c9d4SSatish Balay if (bd) { 33099371c9d4SSatish Balay PetscValidIntPointer(bd, 13); 33109371c9d4SSatish Balay *bd = n; 33119371c9d4SSatish Balay } 331245480ffeSMatthew G. Knepley PetscFunctionReturn(0); 331345480ffeSMatthew G. Knepley } 331445480ffeSMatthew G. Knepley 331545480ffeSMatthew G. Knepley /*@C 3316dce8aebaSBarry Smith PetscDSAddBoundaryByName - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. 3317dce8aebaSBarry 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 3318dce8aebaSBarry Smith boundary integrals should be performed, using the kernels from `PetscDSSetBdResidual()`. 331945480ffeSMatthew G. Knepley 332045480ffeSMatthew G. Knepley Collective on ds 332145480ffeSMatthew G. Knepley 332245480ffeSMatthew G. Knepley Input Parameters: 3323dce8aebaSBarry Smith + ds - The `PetscDS` object 3324dce8aebaSBarry Smith . type - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann) 332545480ffeSMatthew G. Knepley . name - The BC name 332645480ffeSMatthew G. Knepley . lname - The naem of the label defining constrained points 3327dce8aebaSBarry Smith . Nv - The number of `DMLabel` values for constrained points 332845480ffeSMatthew G. Knepley . values - An array of label values for constrained points 332945480ffeSMatthew G. Knepley . field - The field to constrain 333045480ffeSMatthew G. Knepley . Nc - The number of constrained field components (0 will constrain all fields) 333145480ffeSMatthew G. Knepley . comps - An array of constrained component numbers 333245480ffeSMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 3333a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL 333445480ffeSMatthew G. Knepley - ctx - An optional user context for bcFunc 333545480ffeSMatthew G. Knepley 333645480ffeSMatthew G. Knepley Output Parameters: 333745480ffeSMatthew G. Knepley - bd - The boundary number 333845480ffeSMatthew G. Knepley 333945480ffeSMatthew G. Knepley Options Database Keys: 334045480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids 334145480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components 334245480ffeSMatthew G. Knepley 3343dce8aebaSBarry Smith Calling Sequence of bcFunc() and bcFunc_t(): 3344dce8aebaSBarry Smith If the type is `DM_BC_ESSENTIAL` 3345dce8aebaSBarry Smith .vb 3346dce8aebaSBarry Smith bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[]) 3347dce8aebaSBarry Smith .ve 3348dce8aebaSBarry Smith If the type is `DM_BC_ESSENTIAL_FIELD` or other _FIELD value, 3349dce8aebaSBarry Smith .vb 3350dce8aebaSBarry Smith bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux, 3351dce8aebaSBarry Smith const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 3352dce8aebaSBarry Smith const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 3353dce8aebaSBarry Smith PetscReal time, const PetscReal x[], PetscScalar bcval[]) 3354dce8aebaSBarry Smith .ve 335545480ffeSMatthew G. Knepley + dim - the spatial dimension 335645480ffeSMatthew G. Knepley . Nf - the number of fields 335745480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 335845480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 335945480ffeSMatthew G. Knepley . u - each field evaluated at the current point 336045480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 336145480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 336245480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 336345480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 336445480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point 336545480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 336645480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 336745480ffeSMatthew G. Knepley . t - current time 336845480ffeSMatthew G. Knepley . x - coordinates of the current point 336945480ffeSMatthew G. Knepley . numConstants - number of constant parameters 337045480ffeSMatthew G. Knepley . constants - constant parameters 337145480ffeSMatthew G. Knepley - bcval - output values at the current point 337245480ffeSMatthew G. Knepley 337345480ffeSMatthew G. Knepley Level: developer 337445480ffeSMatthew G. Knepley 3375dce8aebaSBarry Smith Note: 3376dce8aebaSBarry Smith This function should only be used with `DMFOREST` currently, since labels cannot be defined before the underlying `DMPLEX` is built. 3377dce8aebaSBarry Smith 3378dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMLabel`, `DMBoundaryConditionType`, `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()` 337945480ffeSMatthew G. Knepley @*/ 3380d71ae5a4SJacob 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) 3381d71ae5a4SJacob Faibussowitsch { 338245480ffeSMatthew G. Knepley DSBoundary head = ds->boundary, b; 338345480ffeSMatthew G. Knepley PetscInt n = 0; 338445480ffeSMatthew G. Knepley 338545480ffeSMatthew G. Knepley PetscFunctionBegin; 338645480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 338745480ffeSMatthew G. Knepley PetscValidLogicalCollectiveEnum(ds, type, 2); 338845480ffeSMatthew G. Knepley PetscValidCharPointer(name, 3); 338945480ffeSMatthew G. Knepley PetscValidCharPointer(lname, 4); 339045480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nv, 5); 339145480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, field, 7); 339245480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nc, 8); 33939566063dSJacob Faibussowitsch PetscCall(PetscNew(&b)); 33949566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&b->name)); 33959566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf)); 33969566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf)); 33979566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nv, &b->values)); 33989566063dSJacob Faibussowitsch if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv)); 33999566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nc, &b->comps)); 34009566063dSJacob Faibussowitsch if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc)); 34019566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(lname, (char **)&b->lname)); 340245480ffeSMatthew G. Knepley b->type = type; 340345480ffeSMatthew G. Knepley b->label = NULL; 340445480ffeSMatthew G. Knepley b->Nv = Nv; 340545480ffeSMatthew G. Knepley b->field = field; 340645480ffeSMatthew G. Knepley b->Nc = Nc; 340745480ffeSMatthew G. Knepley b->func = bcFunc; 340845480ffeSMatthew G. Knepley b->func_t = bcFunc_t; 340945480ffeSMatthew G. Knepley b->ctx = ctx; 341045480ffeSMatthew G. Knepley b->next = NULL; 341145480ffeSMatthew G. Knepley /* Append to linked list so that we can preserve the order */ 341245480ffeSMatthew G. Knepley if (!head) ds->boundary = b; 341345480ffeSMatthew G. Knepley while (head) { 341445480ffeSMatthew G. Knepley if (!head->next) { 341545480ffeSMatthew G. Knepley head->next = b; 341645480ffeSMatthew G. Knepley head = b; 341745480ffeSMatthew G. Knepley } 341845480ffeSMatthew G. Knepley head = head->next; 341945480ffeSMatthew G. Knepley ++n; 342045480ffeSMatthew G. Knepley } 34219371c9d4SSatish Balay if (bd) { 34229371c9d4SSatish Balay PetscValidIntPointer(bd, 13); 34239371c9d4SSatish Balay *bd = n; 34249371c9d4SSatish Balay } 342558ebd649SToby Isaac PetscFunctionReturn(0); 342658ebd649SToby Isaac } 342758ebd649SToby Isaac 3428b67eacb3SMatthew G. Knepley /*@C 3429dce8aebaSBarry Smith PetscDSUpdateBoundary - Change a boundary condition for the model. The pointwise functions are used to provide boundary values for essential boundary conditions. 3430dce8aebaSBarry 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 3431dce8aebaSBarry Smith should be performed, using the kernels from `PetscDSSetBdResidual()`. 3432b67eacb3SMatthew G. Knepley 3433b67eacb3SMatthew G. Knepley Input Parameters: 3434dce8aebaSBarry Smith + ds - The `PetscDS` object 3435b67eacb3SMatthew G. Knepley . bd - The boundary condition number 3436dce8aebaSBarry Smith . type - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann) 3437b67eacb3SMatthew G. Knepley . name - The BC name 343845480ffeSMatthew G. Knepley . label - The label defining constrained points 3439dce8aebaSBarry Smith . Nv - The number of `DMLabel` ids for constrained points 344045480ffeSMatthew G. Knepley . values - An array of ids for constrained points 3441b67eacb3SMatthew G. Knepley . field - The field to constrain 344245480ffeSMatthew G. Knepley . Nc - The number of constrained field components 3443b67eacb3SMatthew G. Knepley . comps - An array of constrained component numbers 3444b67eacb3SMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 3445a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL 3446b67eacb3SMatthew G. Knepley - ctx - An optional user context for bcFunc 3447b67eacb3SMatthew G. Knepley 3448b67eacb3SMatthew G. Knepley Level: developer 3449b67eacb3SMatthew G. Knepley 3450dce8aebaSBarry Smith Note: 3451dce8aebaSBarry Smith The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from `PetscDSGetNumBoundary()`. 3452dce8aebaSBarry Smith See `PetscDSAddBoundary()` for a description of the calling sequences for the callbacks. 3453dce8aebaSBarry Smith 3454dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMBoundaryConditionType`, `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSGetNumBoundary()`, `DMLabel` 3455b67eacb3SMatthew G. Knepley @*/ 3456d71ae5a4SJacob 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) 3457d71ae5a4SJacob Faibussowitsch { 3458b67eacb3SMatthew G. Knepley DSBoundary b = ds->boundary; 3459b67eacb3SMatthew G. Knepley PetscInt n = 0; 3460b67eacb3SMatthew G. Knepley 3461b67eacb3SMatthew G. Knepley PetscFunctionBegin; 3462b67eacb3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3463b67eacb3SMatthew G. Knepley while (b) { 3464b67eacb3SMatthew G. Knepley if (n == bd) break; 3465b67eacb3SMatthew G. Knepley b = b->next; 3466b67eacb3SMatthew G. Knepley ++n; 3467b67eacb3SMatthew G. Knepley } 346863a3b9bcSJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n); 3469b67eacb3SMatthew G. Knepley if (name) { 34709566063dSJacob Faibussowitsch PetscCall(PetscFree(b->name)); 34719566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&b->name)); 3472b67eacb3SMatthew G. Knepley } 3473b67eacb3SMatthew G. Knepley b->type = type; 347445480ffeSMatthew G. Knepley if (label) { 347545480ffeSMatthew G. Knepley const char *name; 347645480ffeSMatthew G. Knepley 347745480ffeSMatthew G. Knepley b->label = label; 34789566063dSJacob Faibussowitsch PetscCall(PetscFree(b->lname)); 34799566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject)label, &name)); 34809566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&b->lname)); 348145480ffeSMatthew G. Knepley } 348245480ffeSMatthew G. Knepley if (Nv >= 0) { 348345480ffeSMatthew G. Knepley b->Nv = Nv; 34849566063dSJacob Faibussowitsch PetscCall(PetscFree(b->values)); 34859566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nv, &b->values)); 34869566063dSJacob Faibussowitsch if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv)); 348745480ffeSMatthew G. Knepley } 348845480ffeSMatthew G. Knepley if (field >= 0) b->field = field; 348945480ffeSMatthew G. Knepley if (Nc >= 0) { 349045480ffeSMatthew G. Knepley b->Nc = Nc; 34919566063dSJacob Faibussowitsch PetscCall(PetscFree(b->comps)); 34929566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nc, &b->comps)); 34939566063dSJacob Faibussowitsch if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc)); 349445480ffeSMatthew G. Knepley } 349545480ffeSMatthew G. Knepley if (bcFunc) b->func = bcFunc; 349645480ffeSMatthew G. Knepley if (bcFunc_t) b->func_t = bcFunc_t; 349745480ffeSMatthew G. Knepley if (ctx) b->ctx = ctx; 3498b67eacb3SMatthew G. Knepley PetscFunctionReturn(0); 3499b67eacb3SMatthew G. Knepley } 3500b67eacb3SMatthew G. Knepley 350158ebd649SToby Isaac /*@ 350258ebd649SToby Isaac PetscDSGetNumBoundary - Get the number of registered BC 350358ebd649SToby Isaac 350458ebd649SToby Isaac Input Parameters: 3505dce8aebaSBarry Smith . ds - The `PetscDS` object 350658ebd649SToby Isaac 350758ebd649SToby Isaac Output Parameters: 350858ebd649SToby Isaac . numBd - The number of BC 350958ebd649SToby Isaac 351058ebd649SToby Isaac Level: intermediate 351158ebd649SToby Isaac 3512dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSAddBoundary()`, `PetscDSGetBoundary()` 351358ebd649SToby Isaac @*/ 3514d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd) 3515d71ae5a4SJacob Faibussowitsch { 351658ebd649SToby Isaac DSBoundary b = ds->boundary; 351758ebd649SToby Isaac 351858ebd649SToby Isaac PetscFunctionBegin; 351958ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3520dadcf809SJacob Faibussowitsch PetscValidIntPointer(numBd, 2); 352158ebd649SToby Isaac *numBd = 0; 35229371c9d4SSatish Balay while (b) { 35239371c9d4SSatish Balay ++(*numBd); 35249371c9d4SSatish Balay b = b->next; 35259371c9d4SSatish Balay } 352658ebd649SToby Isaac PetscFunctionReturn(0); 352758ebd649SToby Isaac } 352858ebd649SToby Isaac 352958ebd649SToby Isaac /*@C 35309a6efb6aSMatthew G. Knepley PetscDSGetBoundary - Gets a boundary condition to the model 353158ebd649SToby Isaac 353258ebd649SToby Isaac Input Parameters: 3533dce8aebaSBarry Smith + ds - The `PetscDS` object 353458ebd649SToby Isaac - bd - The BC number 353558ebd649SToby Isaac 353658ebd649SToby Isaac Output Parameters: 3537dce8aebaSBarry Smith + wf - The `PetscWeakForm` holding the pointwise functions 3538dce8aebaSBarry Smith . type - The type of condition, e.g. `DM_BC_ESSENTIAL`/`DM_BC_ESSENTIAL_FIELD` (Dirichlet), or `DM_BC_NATURAL` (Neumann) 353958ebd649SToby Isaac . name - The BC name 354045480ffeSMatthew G. Knepley . label - The label defining constrained points 3541dce8aebaSBarry Smith . Nv - The number of `DMLabel` ids for constrained points 354245480ffeSMatthew G. Knepley . values - An array of ids for constrained points 354358ebd649SToby Isaac . field - The field to constrain 354445480ffeSMatthew G. Knepley . Nc - The number of constrained field components 354558ebd649SToby Isaac . comps - An array of constrained component numbers 354658ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 3547a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values 354858ebd649SToby Isaac - ctx - An optional user context for bcFunc 354958ebd649SToby Isaac 355058ebd649SToby Isaac Options Database Keys: 355158ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 355258ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 355358ebd649SToby Isaac 355458ebd649SToby Isaac Level: developer 355558ebd649SToby Isaac 3556dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscWeakForm`, `DMBoundaryConditionType`, `PetscDSAddBoundary()`, `DMLabel` 355758ebd649SToby Isaac @*/ 3558d71ae5a4SJacob 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) 3559d71ae5a4SJacob Faibussowitsch { 356058ebd649SToby Isaac DSBoundary b = ds->boundary; 356158ebd649SToby Isaac PetscInt n = 0; 356258ebd649SToby Isaac 356358ebd649SToby Isaac PetscFunctionBegin; 356458ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 356558ebd649SToby Isaac while (b) { 356658ebd649SToby Isaac if (n == bd) break; 356758ebd649SToby Isaac b = b->next; 356858ebd649SToby Isaac ++n; 356958ebd649SToby Isaac } 357063a3b9bcSJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n); 357145480ffeSMatthew G. Knepley if (wf) { 357245480ffeSMatthew G. Knepley PetscValidPointer(wf, 3); 357345480ffeSMatthew G. Knepley *wf = b->wf; 357445480ffeSMatthew G. Knepley } 3575f971fd6bSMatthew G. Knepley if (type) { 357645480ffeSMatthew G. Knepley PetscValidPointer(type, 4); 3577f971fd6bSMatthew G. Knepley *type = b->type; 357858ebd649SToby Isaac } 357958ebd649SToby Isaac if (name) { 358045480ffeSMatthew G. Knepley PetscValidPointer(name, 5); 358158ebd649SToby Isaac *name = b->name; 358258ebd649SToby Isaac } 358345480ffeSMatthew G. Knepley if (label) { 358445480ffeSMatthew G. Knepley PetscValidPointer(label, 6); 358545480ffeSMatthew G. Knepley *label = b->label; 358645480ffeSMatthew G. Knepley } 358745480ffeSMatthew G. Knepley if (Nv) { 358845480ffeSMatthew G. Knepley PetscValidIntPointer(Nv, 7); 358945480ffeSMatthew G. Knepley *Nv = b->Nv; 359045480ffeSMatthew G. Knepley } 359145480ffeSMatthew G. Knepley if (values) { 359245480ffeSMatthew G. Knepley PetscValidPointer(values, 8); 359345480ffeSMatthew G. Knepley *values = b->values; 359458ebd649SToby Isaac } 359558ebd649SToby Isaac if (field) { 359645480ffeSMatthew G. Knepley PetscValidIntPointer(field, 9); 359758ebd649SToby Isaac *field = b->field; 359858ebd649SToby Isaac } 359945480ffeSMatthew G. Knepley if (Nc) { 360045480ffeSMatthew G. Knepley PetscValidIntPointer(Nc, 10); 360145480ffeSMatthew G. Knepley *Nc = b->Nc; 360258ebd649SToby Isaac } 360358ebd649SToby Isaac if (comps) { 360445480ffeSMatthew G. Knepley PetscValidPointer(comps, 11); 360558ebd649SToby Isaac *comps = b->comps; 360658ebd649SToby Isaac } 360758ebd649SToby Isaac if (func) { 360845480ffeSMatthew G. Knepley PetscValidPointer(func, 12); 360958ebd649SToby Isaac *func = b->func; 361058ebd649SToby Isaac } 361156cf3b9cSMatthew G. Knepley if (func_t) { 361245480ffeSMatthew G. Knepley PetscValidPointer(func_t, 13); 361356cf3b9cSMatthew G. Knepley *func_t = b->func_t; 361456cf3b9cSMatthew G. Knepley } 361558ebd649SToby Isaac if (ctx) { 361645480ffeSMatthew G. Knepley PetscValidPointer(ctx, 14); 361758ebd649SToby Isaac *ctx = b->ctx; 361858ebd649SToby Isaac } 361958ebd649SToby Isaac PetscFunctionReturn(0); 362058ebd649SToby Isaac } 362158ebd649SToby Isaac 3622d71ae5a4SJacob Faibussowitsch static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew) 3623d71ae5a4SJacob Faibussowitsch { 362445480ffeSMatthew G. Knepley PetscFunctionBegin; 36259566063dSJacob Faibussowitsch PetscCall(PetscNew(bNew)); 36269566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf)); 36279566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCopy(b->wf, (*bNew)->wf)); 36289566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(b->name, (char **)&((*bNew)->name))); 36299566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(b->lname, (char **)&((*bNew)->lname))); 363045480ffeSMatthew G. Knepley (*bNew)->type = b->type; 363145480ffeSMatthew G. Knepley (*bNew)->label = b->label; 363245480ffeSMatthew G. Knepley (*bNew)->Nv = b->Nv; 36339566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(b->Nv, &(*bNew)->values)); 36349566063dSJacob Faibussowitsch PetscCall(PetscArraycpy((*bNew)->values, b->values, b->Nv)); 363545480ffeSMatthew G. Knepley (*bNew)->field = b->field; 363645480ffeSMatthew G. Knepley (*bNew)->Nc = b->Nc; 36379566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(b->Nc, &(*bNew)->comps)); 36389566063dSJacob Faibussowitsch PetscCall(PetscArraycpy((*bNew)->comps, b->comps, b->Nc)); 363945480ffeSMatthew G. Knepley (*bNew)->func = b->func; 364045480ffeSMatthew G. Knepley (*bNew)->func_t = b->func_t; 364145480ffeSMatthew G. Knepley (*bNew)->ctx = b->ctx; 364245480ffeSMatthew G. Knepley PetscFunctionReturn(0); 364345480ffeSMatthew G. Knepley } 364445480ffeSMatthew G. Knepley 36459252d075SMatthew G. Knepley /*@ 36469252d075SMatthew G. Knepley PetscDSCopyBoundary - Copy all boundary condition objects to the new problem 36479252d075SMatthew G. Knepley 36489252d075SMatthew G. Knepley Not collective 36499252d075SMatthew G. Knepley 365036951cb5SMatthew G. Knepley Input Parameters: 3651dce8aebaSBarry Smith + ds - The source `PetscDS` object 3652dce8aebaSBarry Smith . numFields - The number of selected fields, or `PETSC_DEFAULT` for all fields 365336951cb5SMatthew G. Knepley - fields - The selected fields, or NULL for all fields 36549252d075SMatthew G. Knepley 36559252d075SMatthew G. Knepley Output Parameter: 3656dce8aebaSBarry Smith . newds - The target `PetscDS`, now with a copy of the boundary conditions 36579252d075SMatthew G. Knepley 36589252d075SMatthew G. Knepley Level: intermediate 36599252d075SMatthew G. Knepley 3660dce8aebaSBarry Smith .seealso: `PetscDS`, `DMBoundary`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 36619252d075SMatthew G. Knepley @*/ 3662d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds) 3663d71ae5a4SJacob Faibussowitsch { 366445480ffeSMatthew G. Knepley DSBoundary b, *lastnext; 3665dff059c6SToby Isaac 3666dff059c6SToby Isaac PetscFunctionBegin; 366736951cb5SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 366836951cb5SMatthew G. Knepley PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4); 366936951cb5SMatthew G. Knepley if (ds == newds) PetscFunctionReturn(0); 36709566063dSJacob Faibussowitsch PetscCall(PetscDSDestroyBoundary(newds)); 367136951cb5SMatthew G. Knepley lastnext = &(newds->boundary); 367236951cb5SMatthew G. Knepley for (b = ds->boundary; b; b = b->next) { 3673dff059c6SToby Isaac DSBoundary bNew; 367436951cb5SMatthew G. Knepley PetscInt fieldNew = -1; 3675dff059c6SToby Isaac 367636951cb5SMatthew G. Knepley if (numFields > 0 && fields) { 367736951cb5SMatthew G. Knepley PetscInt f; 367836951cb5SMatthew G. Knepley 36799371c9d4SSatish Balay for (f = 0; f < numFields; ++f) 36809371c9d4SSatish Balay if (b->field == fields[f]) break; 368136951cb5SMatthew G. Knepley if (f == numFields) continue; 368236951cb5SMatthew G. Knepley fieldNew = f; 368336951cb5SMatthew G. Knepley } 36849566063dSJacob Faibussowitsch PetscCall(DSBoundaryDuplicate_Internal(b, &bNew)); 368536951cb5SMatthew G. Knepley bNew->field = fieldNew < 0 ? b->field : fieldNew; 3686dff059c6SToby Isaac *lastnext = bNew; 3687dff059c6SToby Isaac lastnext = &(bNew->next); 3688dff059c6SToby Isaac } 3689dff059c6SToby Isaac PetscFunctionReturn(0); 3690dff059c6SToby Isaac } 3691dff059c6SToby Isaac 36926c1eb96dSMatthew G. Knepley /*@ 3693dce8aebaSBarry Smith PetscDSDestroyBoundary - Remove all `DMBoundary` objects from the `PetscDS` 369445480ffeSMatthew G. Knepley 369545480ffeSMatthew G. Knepley Not collective 369645480ffeSMatthew G. Knepley 369745480ffeSMatthew G. Knepley Input Parameter: 3698dce8aebaSBarry Smith . ds - The `PetscDS` object 369945480ffeSMatthew G. Knepley 370045480ffeSMatthew G. Knepley Level: intermediate 370145480ffeSMatthew G. Knepley 3702dce8aebaSBarry Smith .seealso: `PetscDS`, `DMBoundary`, `PetscDSCopyBoundary()`, `PetscDSCopyEquations()` 370345480ffeSMatthew G. Knepley @*/ 3704d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSDestroyBoundary(PetscDS ds) 3705d71ae5a4SJacob Faibussowitsch { 370645480ffeSMatthew G. Knepley DSBoundary next = ds->boundary; 370745480ffeSMatthew G. Knepley 370845480ffeSMatthew G. Knepley PetscFunctionBegin; 370945480ffeSMatthew G. Knepley while (next) { 371045480ffeSMatthew G. Knepley DSBoundary b = next; 371145480ffeSMatthew G. Knepley 371245480ffeSMatthew G. Knepley next = b->next; 37139566063dSJacob Faibussowitsch PetscCall(PetscWeakFormDestroy(&b->wf)); 37149566063dSJacob Faibussowitsch PetscCall(PetscFree(b->name)); 37159566063dSJacob Faibussowitsch PetscCall(PetscFree(b->lname)); 37169566063dSJacob Faibussowitsch PetscCall(PetscFree(b->values)); 37179566063dSJacob Faibussowitsch PetscCall(PetscFree(b->comps)); 37189566063dSJacob Faibussowitsch PetscCall(PetscFree(b)); 371945480ffeSMatthew G. Knepley } 372045480ffeSMatthew G. Knepley PetscFunctionReturn(0); 372145480ffeSMatthew G. Knepley } 372245480ffeSMatthew G. Knepley 372345480ffeSMatthew G. Knepley /*@ 37246c1eb96dSMatthew G. Knepley PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout 37256c1eb96dSMatthew G. Knepley 37266c1eb96dSMatthew G. Knepley Not collective 37276c1eb96dSMatthew G. Knepley 3728d8d19677SJose E. Roman Input Parameters: 3729dce8aebaSBarry Smith + prob - The `PetscDS` object 37306c1eb96dSMatthew G. Knepley . numFields - Number of new fields 37316c1eb96dSMatthew G. Knepley - fields - Old field number for each new field 37326c1eb96dSMatthew G. Knepley 37336c1eb96dSMatthew G. Knepley Output Parameter: 3734dce8aebaSBarry Smith . newprob - The `PetscDS` copy 37356c1eb96dSMatthew G. Knepley 37366c1eb96dSMatthew G. Knepley Level: intermediate 37376c1eb96dSMatthew G. Knepley 3738dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSelectEquations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 37396c1eb96dSMatthew G. Knepley @*/ 3740d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 3741d71ae5a4SJacob Faibussowitsch { 37426c1eb96dSMatthew G. Knepley PetscInt Nf, Nfn, fn; 37436c1eb96dSMatthew G. Knepley 37446c1eb96dSMatthew G. Knepley PetscFunctionBegin; 37456c1eb96dSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3746dadcf809SJacob Faibussowitsch if (fields) PetscValidIntPointer(fields, 3); 37476c1eb96dSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 37489566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(prob, &Nf)); 37499566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(newprob, &Nfn)); 375045480ffeSMatthew G. Knepley numFields = numFields < 0 ? Nf : numFields; 37516c1eb96dSMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 37526c1eb96dSMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 37536c1eb96dSMatthew G. Knepley PetscObject disc; 37546c1eb96dSMatthew G. Knepley 37556c1eb96dSMatthew G. Knepley if (f >= Nf) continue; 37569566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, f, &disc)); 37579566063dSJacob Faibussowitsch PetscCall(PetscDSSetDiscretization(newprob, fn, disc)); 37586c1eb96dSMatthew G. Knepley } 37596c1eb96dSMatthew G. Knepley PetscFunctionReturn(0); 37606c1eb96dSMatthew G. Knepley } 37616c1eb96dSMatthew G. Knepley 37626c1eb96dSMatthew G. Knepley /*@ 37639252d075SMatthew G. Knepley PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout 37649252d075SMatthew G. Knepley 37659252d075SMatthew G. Knepley Not collective 37669252d075SMatthew G. Knepley 3767d8d19677SJose E. Roman Input Parameters: 3768dce8aebaSBarry Smith + prob - The `PetscDS` object 37699252d075SMatthew G. Knepley . numFields - Number of new fields 37709252d075SMatthew G. Knepley - fields - Old field number for each new field 37719252d075SMatthew G. Knepley 37729252d075SMatthew G. Knepley Output Parameter: 3773dce8aebaSBarry Smith . newprob - The `PetscDS` copy 37749252d075SMatthew G. Knepley 37759252d075SMatthew G. Knepley Level: intermediate 37769252d075SMatthew G. Knepley 3777dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSSelectDiscretizations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 37789252d075SMatthew G. Knepley @*/ 3779d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 3780d71ae5a4SJacob Faibussowitsch { 37819252d075SMatthew G. Knepley PetscInt Nf, Nfn, fn, gn; 37829252d075SMatthew G. Knepley 37839252d075SMatthew G. Knepley PetscFunctionBegin; 37849252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3785dadcf809SJacob Faibussowitsch if (fields) PetscValidIntPointer(fields, 3); 37869252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 37879566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(prob, &Nf)); 37889566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(newprob, &Nfn)); 378963a3b9bcSJacob 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); 37909252d075SMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 37919252d075SMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 37929252d075SMatthew G. Knepley PetscPointFunc obj; 37939252d075SMatthew G. Knepley PetscPointFunc f0, f1; 37949252d075SMatthew G. Knepley PetscBdPointFunc f0Bd, f1Bd; 37959252d075SMatthew G. Knepley PetscRiemannFunc r; 37969252d075SMatthew G. Knepley 3797c52f1e13SMatthew G. Knepley if (f >= Nf) continue; 37989566063dSJacob Faibussowitsch PetscCall(PetscDSGetObjective(prob, f, &obj)); 37999566063dSJacob Faibussowitsch PetscCall(PetscDSGetResidual(prob, f, &f0, &f1)); 38009566063dSJacob Faibussowitsch PetscCall(PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd)); 38019566063dSJacob Faibussowitsch PetscCall(PetscDSGetRiemannSolver(prob, f, &r)); 38029566063dSJacob Faibussowitsch PetscCall(PetscDSSetObjective(newprob, fn, obj)); 38039566063dSJacob Faibussowitsch PetscCall(PetscDSSetResidual(newprob, fn, f0, f1)); 38049566063dSJacob Faibussowitsch PetscCall(PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd)); 38059566063dSJacob Faibussowitsch PetscCall(PetscDSSetRiemannSolver(newprob, fn, r)); 38069252d075SMatthew G. Knepley for (gn = 0; gn < numFields; ++gn) { 38079252d075SMatthew G. Knepley const PetscInt g = fields ? fields[gn] : gn; 38089252d075SMatthew G. Knepley PetscPointJac g0, g1, g2, g3; 38099252d075SMatthew G. Knepley PetscPointJac g0p, g1p, g2p, g3p; 38109252d075SMatthew G. Knepley PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd; 38119252d075SMatthew G. Knepley 3812c52f1e13SMatthew G. Knepley if (g >= Nf) continue; 38139566063dSJacob Faibussowitsch PetscCall(PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3)); 38149566063dSJacob Faibussowitsch PetscCall(PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p)); 38159566063dSJacob Faibussowitsch PetscCall(PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd)); 38169566063dSJacob Faibussowitsch PetscCall(PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3)); 38179566063dSJacob Faibussowitsch PetscCall(PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p)); 38189566063dSJacob Faibussowitsch PetscCall(PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd)); 38199252d075SMatthew G. Knepley } 38209252d075SMatthew G. Knepley } 38219252d075SMatthew G. Knepley PetscFunctionReturn(0); 38229252d075SMatthew G. Knepley } 38239252d075SMatthew G. Knepley 3824da51fcedSMatthew G. Knepley /*@ 3825dce8aebaSBarry Smith PetscDSCopyEquations - Copy all pointwise function pointers to another `PetscDS` 3826da51fcedSMatthew G. Knepley 3827da51fcedSMatthew G. Knepley Not collective 3828da51fcedSMatthew G. Knepley 3829da51fcedSMatthew G. Knepley Input Parameter: 3830dce8aebaSBarry Smith . prob - The `PetscDS` object 3831da51fcedSMatthew G. Knepley 3832da51fcedSMatthew G. Knepley Output Parameter: 3833dce8aebaSBarry Smith . newprob - The `PetscDS` copy 3834da51fcedSMatthew G. Knepley 3835da51fcedSMatthew G. Knepley Level: intermediate 3836da51fcedSMatthew G. Knepley 3837dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 3838da51fcedSMatthew G. Knepley @*/ 3839d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob) 3840d71ae5a4SJacob Faibussowitsch { 3841b8025e53SMatthew G. Knepley PetscWeakForm wf, newwf; 38429252d075SMatthew G. Knepley PetscInt Nf, Ng; 3843da51fcedSMatthew G. Knepley 3844da51fcedSMatthew G. Knepley PetscFunctionBegin; 3845da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3846da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 38479566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(prob, &Nf)); 38489566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(newprob, &Ng)); 384963a3b9bcSJacob Faibussowitsch PetscCheck(Nf == Ng, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %" PetscInt_FMT " != %" PetscInt_FMT, Nf, Ng); 38509566063dSJacob Faibussowitsch PetscCall(PetscDSGetWeakForm(prob, &wf)); 38519566063dSJacob Faibussowitsch PetscCall(PetscDSGetWeakForm(newprob, &newwf)); 38529566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCopy(wf, newwf)); 38539252d075SMatthew G. Knepley PetscFunctionReturn(0); 38549252d075SMatthew G. Knepley } 385545480ffeSMatthew G. Knepley 38569252d075SMatthew G. Knepley /*@ 3857dce8aebaSBarry Smith PetscDSCopyConstants - Copy all constants to another `PetscDS` 3858da51fcedSMatthew G. Knepley 38599252d075SMatthew G. Knepley Not collective 38609252d075SMatthew G. Knepley 38619252d075SMatthew G. Knepley Input Parameter: 3862dce8aebaSBarry Smith . prob - The `PetscDS` object 38639252d075SMatthew G. Knepley 38649252d075SMatthew G. Knepley Output Parameter: 3865dce8aebaSBarry Smith . newprob - The `PetscDS` copy 38669252d075SMatthew G. Knepley 38679252d075SMatthew G. Knepley Level: intermediate 38689252d075SMatthew G. Knepley 3869dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 38709252d075SMatthew G. Knepley @*/ 3871d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob) 3872d71ae5a4SJacob Faibussowitsch { 38739252d075SMatthew G. Knepley PetscInt Nc; 38749252d075SMatthew G. Knepley const PetscScalar *constants; 38759252d075SMatthew G. Knepley 38769252d075SMatthew G. Knepley PetscFunctionBegin; 38779252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 38789252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 38799566063dSJacob Faibussowitsch PetscCall(PetscDSGetConstants(prob, &Nc, &constants)); 38809566063dSJacob Faibussowitsch PetscCall(PetscDSSetConstants(newprob, Nc, (PetscScalar *)constants)); 3881da51fcedSMatthew G. Knepley PetscFunctionReturn(0); 3882da51fcedSMatthew G. Knepley } 3883da51fcedSMatthew G. Knepley 388445480ffeSMatthew G. Knepley /*@ 3885dce8aebaSBarry Smith PetscDSCopyExactSolutions - Copy all exact solutions to another `PetscDS` 388645480ffeSMatthew G. Knepley 388745480ffeSMatthew G. Knepley Not collective 388845480ffeSMatthew G. Knepley 388945480ffeSMatthew G. Knepley Input Parameter: 3890dce8aebaSBarry Smith . ds - The `PetscDS` object 389145480ffeSMatthew G. Knepley 389245480ffeSMatthew G. Knepley Output Parameter: 3893dce8aebaSBarry Smith . newds - The `PetscDS` copy 389445480ffeSMatthew G. Knepley 389545480ffeSMatthew G. Knepley Level: intermediate 389645480ffeSMatthew G. Knepley 3897dce8aebaSBarry Smith .seealso: `PetscDS`, `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 389845480ffeSMatthew G. Knepley @*/ 3899d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds) 3900d71ae5a4SJacob Faibussowitsch { 390145480ffeSMatthew G. Knepley PetscSimplePointFunc sol; 390245480ffeSMatthew G. Knepley void *ctx; 390345480ffeSMatthew G. Knepley PetscInt Nf, f; 390445480ffeSMatthew G. Knepley 390545480ffeSMatthew G. Knepley PetscFunctionBegin; 390645480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 390745480ffeSMatthew G. Knepley PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2); 39089566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 390945480ffeSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 39109566063dSJacob Faibussowitsch PetscCall(PetscDSGetExactSolution(ds, f, &sol, &ctx)); 39119566063dSJacob Faibussowitsch PetscCall(PetscDSSetExactSolution(newds, f, sol, ctx)); 39129566063dSJacob Faibussowitsch PetscCall(PetscDSGetExactSolutionTimeDerivative(ds, f, &sol, &ctx)); 39139566063dSJacob Faibussowitsch PetscCall(PetscDSSetExactSolutionTimeDerivative(newds, f, sol, ctx)); 391445480ffeSMatthew G. Knepley } 391545480ffeSMatthew G. Knepley PetscFunctionReturn(0); 391645480ffeSMatthew G. Knepley } 391745480ffeSMatthew G. Knepley 3918d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob) 3919d71ae5a4SJacob Faibussowitsch { 3920df3a45bdSMatthew G. Knepley PetscInt dim, Nf, f; 3921b1353e8eSMatthew G. Knepley 3922b1353e8eSMatthew G. Knepley PetscFunctionBegin; 3923b1353e8eSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3924b1353e8eSMatthew G. Knepley PetscValidPointer(subprob, 3); 39259371c9d4SSatish Balay if (height == 0) { 39269371c9d4SSatish Balay *subprob = prob; 39279371c9d4SSatish Balay PetscFunctionReturn(0); 39289371c9d4SSatish Balay } 39299566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(prob, &Nf)); 39309566063dSJacob Faibussowitsch PetscCall(PetscDSGetSpatialDimension(prob, &dim)); 393163a3b9bcSJacob 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); 39329566063dSJacob Faibussowitsch if (!prob->subprobs) PetscCall(PetscCalloc1(dim, &prob->subprobs)); 3933df3a45bdSMatthew G. Knepley if (!prob->subprobs[height - 1]) { 3934b1353e8eSMatthew G. Knepley PetscInt cdim; 3935b1353e8eSMatthew G. Knepley 39369566063dSJacob Faibussowitsch PetscCall(PetscDSCreate(PetscObjectComm((PetscObject)prob), &prob->subprobs[height - 1])); 39379566063dSJacob Faibussowitsch PetscCall(PetscDSGetCoordinateDimension(prob, &cdim)); 39389566063dSJacob Faibussowitsch PetscCall(PetscDSSetCoordinateDimension(prob->subprobs[height - 1], cdim)); 3939b1353e8eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3940b1353e8eSMatthew G. Knepley PetscFE subfe; 3941b1353e8eSMatthew G. Knepley PetscObject obj; 3942b1353e8eSMatthew G. Knepley PetscClassId id; 3943b1353e8eSMatthew G. Knepley 39449566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, f, &obj)); 39459566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 39469566063dSJacob Faibussowitsch if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetHeightSubspace((PetscFE)obj, height, &subfe)); 394763a3b9bcSJacob Faibussowitsch else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %" PetscInt_FMT, f); 39489566063dSJacob Faibussowitsch PetscCall(PetscDSSetDiscretization(prob->subprobs[height - 1], f, (PetscObject)subfe)); 3949b1353e8eSMatthew G. Knepley } 3950b1353e8eSMatthew G. Knepley } 3951df3a45bdSMatthew G. Knepley *subprob = prob->subprobs[height - 1]; 3952b1353e8eSMatthew G. Knepley PetscFunctionReturn(0); 3953b1353e8eSMatthew G. Knepley } 3954b1353e8eSMatthew G. Knepley 3955d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype) 3956d71ae5a4SJacob Faibussowitsch { 3957c7bd5f0bSMatthew G. Knepley PetscObject obj; 3958c7bd5f0bSMatthew G. Knepley PetscClassId id; 3959c7bd5f0bSMatthew G. Knepley PetscInt Nf; 3960c7bd5f0bSMatthew G. Knepley 3961c7bd5f0bSMatthew G. Knepley PetscFunctionBegin; 3962c7bd5f0bSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3963665f567fSMatthew G. Knepley PetscValidPointer(disctype, 3); 3964665f567fSMatthew G. Knepley *disctype = PETSC_DISC_NONE; 39659566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 396663a3b9bcSJacob Faibussowitsch PetscCheck(f < Nf, PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_SIZ, "Field %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, Nf); 39679566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, f, &obj)); 3968665f567fSMatthew G. Knepley if (obj) { 39699566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 3970665f567fSMatthew G. Knepley if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE; 3971665f567fSMatthew G. Knepley else *disctype = PETSC_DISC_FV; 3972665f567fSMatthew G. Knepley } 3973c7bd5f0bSMatthew G. Knepley PetscFunctionReturn(0); 3974c7bd5f0bSMatthew G. Knepley } 3975c7bd5f0bSMatthew G. Knepley 3976d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds) 3977d71ae5a4SJacob Faibussowitsch { 39782764a2aaSMatthew G. Knepley PetscFunctionBegin; 39799566063dSJacob Faibussowitsch PetscCall(PetscFree(ds->data)); 39802764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 39812764a2aaSMatthew G. Knepley } 39822764a2aaSMatthew G. Knepley 3983d71ae5a4SJacob Faibussowitsch static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds) 3984d71ae5a4SJacob Faibussowitsch { 39852764a2aaSMatthew G. Knepley PetscFunctionBegin; 39866528b96dSMatthew G. Knepley ds->ops->setfromoptions = NULL; 39876528b96dSMatthew G. Knepley ds->ops->setup = NULL; 39886528b96dSMatthew G. Knepley ds->ops->view = NULL; 39896528b96dSMatthew G. Knepley ds->ops->destroy = PetscDSDestroy_Basic; 39902764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 39912764a2aaSMatthew G. Knepley } 39922764a2aaSMatthew G. Knepley 39932764a2aaSMatthew G. Knepley /*MC 39942764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 39952764a2aaSMatthew G. Knepley 39962764a2aaSMatthew G. Knepley Level: intermediate 39972764a2aaSMatthew G. Knepley 3998db781477SPatrick Sanan .seealso: `PetscDSType`, `PetscDSCreate()`, `PetscDSSetType()` 39992764a2aaSMatthew G. Knepley M*/ 40002764a2aaSMatthew G. Knepley 4001d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds) 4002d71ae5a4SJacob Faibussowitsch { 40032764a2aaSMatthew G. Knepley PetscDS_Basic *b; 40042764a2aaSMatthew G. Knepley 40052764a2aaSMatthew G. Knepley PetscFunctionBegin; 40066528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 40074dfa11a4SJacob Faibussowitsch PetscCall(PetscNew(&b)); 40086528b96dSMatthew G. Knepley ds->data = b; 40092764a2aaSMatthew G. Knepley 40109566063dSJacob Faibussowitsch PetscCall(PetscDSInitialize_Basic(ds)); 40112764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 40122764a2aaSMatthew G. Knepley } 4013