1af0996ceSBarry Smith #include <petsc/private/petscdsimpl.h> /*I "petscds.h" I*/ 22764a2aaSMatthew G. Knepley 32764a2aaSMatthew G. Knepley PetscClassId PETSCDS_CLASSID = 0; 42764a2aaSMatthew G. Knepley 52764a2aaSMatthew G. Knepley PetscFunctionList PetscDSList = NULL; 62764a2aaSMatthew G. Knepley PetscBool PetscDSRegisterAllCalled = PETSC_FALSE; 72764a2aaSMatthew G. Knepley 894dcdc3fSMatthew G. Knepley /* A PetscDS (Discrete System) encodes a set of equations posed in a discrete space, which represents a set of 994dcdc3fSMatthew G. Knepley nonlinear continuum equations. The equations can have multiple fields, each field having a different 1094dcdc3fSMatthew G. Knepley discretization. In addition, different pieces of the domain can have different field combinations and equations. 1194dcdc3fSMatthew G. Knepley 1294dcdc3fSMatthew G. Knepley The DS provides the user a description of the approximation space on any given cell. It also gives pointwise 1394dcdc3fSMatthew G. Knepley functions representing the equations. 1494dcdc3fSMatthew G. Knepley 1594dcdc3fSMatthew G. Knepley Each field is associated with a label, marking the cells on which it is supported. Note that a field can be 1694dcdc3fSMatthew G. Knepley supported on the closure of a cell not in the label due to overlap of the boundary of neighboring cells. The DM 1794dcdc3fSMatthew G. Knepley then creates a DS for each set of cells with identical approximation spaces. When assembling, the user asks for 1894dcdc3fSMatthew G. Knepley the space associated with a given cell. DMPlex uses the labels associated with each DS in the default integration loop. 1994dcdc3fSMatthew G. Knepley */ 2094dcdc3fSMatthew G. Knepley 212764a2aaSMatthew G. Knepley /*@C 222764a2aaSMatthew G. Knepley PetscDSRegister - Adds a new PetscDS implementation 232764a2aaSMatthew G. Knepley 242764a2aaSMatthew G. Knepley Not Collective 252764a2aaSMatthew G. Knepley 262764a2aaSMatthew G. Knepley Input Parameters: 272764a2aaSMatthew G. Knepley + name - The name of a new user-defined creation routine 282764a2aaSMatthew G. Knepley - create_func - The creation routine itself 292764a2aaSMatthew G. Knepley 302764a2aaSMatthew G. Knepley Notes: 312764a2aaSMatthew G. Knepley PetscDSRegister() may be called multiple times to add several user-defined PetscDSs 322764a2aaSMatthew G. Knepley 332764a2aaSMatthew G. Knepley Sample usage: 342764a2aaSMatthew G. Knepley .vb 352764a2aaSMatthew G. Knepley PetscDSRegister("my_ds", MyPetscDSCreate); 362764a2aaSMatthew G. Knepley .ve 372764a2aaSMatthew G. Knepley 382764a2aaSMatthew G. Knepley Then, your PetscDS type can be chosen with the procedural interface via 392764a2aaSMatthew G. Knepley .vb 402764a2aaSMatthew G. Knepley PetscDSCreate(MPI_Comm, PetscDS *); 412764a2aaSMatthew G. Knepley PetscDSSetType(PetscDS, "my_ds"); 422764a2aaSMatthew G. Knepley .ve 432764a2aaSMatthew G. Knepley or at runtime via the option 442764a2aaSMatthew G. Knepley .vb 452764a2aaSMatthew G. Knepley -petscds_type my_ds 462764a2aaSMatthew G. Knepley .ve 472764a2aaSMatthew G. Knepley 482764a2aaSMatthew G. Knepley Level: advanced 492764a2aaSMatthew G. Knepley 50f5f57ec0SBarry Smith Not available from Fortran 51f5f57ec0SBarry Smith 52db781477SPatrick Sanan .seealso: `PetscDSRegisterAll()`, `PetscDSRegisterDestroy()` 532764a2aaSMatthew G. Knepley 542764a2aaSMatthew G. Knepley @*/ 559371c9d4SSatish Balay PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS)) { 562764a2aaSMatthew G. Knepley PetscFunctionBegin; 579566063dSJacob Faibussowitsch PetscCall(PetscFunctionListAdd(&PetscDSList, sname, function)); 582764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 592764a2aaSMatthew G. Knepley } 602764a2aaSMatthew G. Knepley 612764a2aaSMatthew G. Knepley /*@C 622764a2aaSMatthew G. Knepley PetscDSSetType - Builds a particular PetscDS 632764a2aaSMatthew G. Knepley 64d083f849SBarry Smith Collective on prob 652764a2aaSMatthew G. Knepley 662764a2aaSMatthew G. Knepley Input Parameters: 672764a2aaSMatthew G. Knepley + prob - The PetscDS object 682764a2aaSMatthew G. Knepley - name - The kind of system 692764a2aaSMatthew G. Knepley 702764a2aaSMatthew G. Knepley Options Database Key: 712764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types 722764a2aaSMatthew G. Knepley 732764a2aaSMatthew G. Knepley Level: intermediate 742764a2aaSMatthew G. Knepley 75f5f57ec0SBarry Smith Not available from Fortran 76f5f57ec0SBarry Smith 77db781477SPatrick Sanan .seealso: `PetscDSGetType()`, `PetscDSCreate()` 782764a2aaSMatthew G. Knepley @*/ 799371c9d4SSatish Balay PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name) { 802764a2aaSMatthew G. Knepley PetscErrorCode (*r)(PetscDS); 812764a2aaSMatthew G. Knepley PetscBool match; 822764a2aaSMatthew G. Knepley 832764a2aaSMatthew G. Knepley PetscFunctionBegin; 842764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 859566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)prob, name, &match)); 862764a2aaSMatthew G. Knepley if (match) PetscFunctionReturn(0); 872764a2aaSMatthew G. Knepley 889566063dSJacob Faibussowitsch PetscCall(PetscDSRegisterAll()); 899566063dSJacob Faibussowitsch PetscCall(PetscFunctionListFind(PetscDSList, name, &r)); 9028b400f6SJacob Faibussowitsch PetscCheck(r, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name); 912764a2aaSMatthew G. Knepley 92dbbe0bcdSBarry Smith PetscTryTypeMethod(prob, destroy); 932764a2aaSMatthew G. Knepley prob->ops->destroy = NULL; 94dbbe0bcdSBarry Smith 959566063dSJacob Faibussowitsch PetscCall((*r)(prob)); 969566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)prob, name)); 972764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 982764a2aaSMatthew G. Knepley } 992764a2aaSMatthew G. Knepley 1002764a2aaSMatthew G. Knepley /*@C 1012764a2aaSMatthew G. Knepley PetscDSGetType - Gets the PetscDS type name (as a string) from the object. 1022764a2aaSMatthew G. Knepley 1032764a2aaSMatthew G. Knepley Not Collective 1042764a2aaSMatthew G. Knepley 1052764a2aaSMatthew G. Knepley Input Parameter: 1062764a2aaSMatthew G. Knepley . prob - The PetscDS 1072764a2aaSMatthew G. Knepley 1082764a2aaSMatthew G. Knepley Output Parameter: 1092764a2aaSMatthew G. Knepley . name - The PetscDS type name 1102764a2aaSMatthew G. Knepley 1112764a2aaSMatthew G. Knepley Level: intermediate 1122764a2aaSMatthew G. Knepley 113f5f57ec0SBarry Smith Not available from Fortran 114f5f57ec0SBarry Smith 115db781477SPatrick Sanan .seealso: `PetscDSSetType()`, `PetscDSCreate()` 1162764a2aaSMatthew G. Knepley @*/ 1179371c9d4SSatish Balay PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name) { 1182764a2aaSMatthew G. Knepley PetscFunctionBegin; 1192764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 120c959eef4SJed Brown PetscValidPointer(name, 2); 1219566063dSJacob Faibussowitsch PetscCall(PetscDSRegisterAll()); 1222764a2aaSMatthew G. Knepley *name = ((PetscObject)prob)->type_name; 1232764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 1242764a2aaSMatthew G. Knepley } 1252764a2aaSMatthew G. Knepley 1269371c9d4SSatish Balay static PetscErrorCode PetscDSView_Ascii(PetscDS ds, PetscViewer viewer) { 1277d8a60eaSMatthew G. Knepley PetscViewerFormat format; 12897b6e6e8SMatthew G. Knepley const PetscScalar *constants; 1295fedec97SMatthew G. Knepley PetscInt Nf, numConstants, f; 1307d8a60eaSMatthew G. Knepley 1317d8a60eaSMatthew G. Knepley PetscFunctionBegin; 1329566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 1339566063dSJacob Faibussowitsch PetscCall(PetscViewerGetFormat(viewer, &format)); 13463a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Discrete System with %" PetscInt_FMT " fields\n", Nf)); 1359566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 13663a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " cell total dim %" PetscInt_FMT " total comp %" PetscInt_FMT "\n", ds->totDim, ds->totComp)); 1379566063dSJacob Faibussowitsch if (ds->isCohesive) PetscCall(PetscViewerASCIIPrintf(viewer, " cohesive cell\n")); 1385fedec97SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 13940967b3bSMatthew G. Knepley DSBoundary b; 1407d8a60eaSMatthew G. Knepley PetscObject obj; 1417d8a60eaSMatthew G. Knepley PetscClassId id; 142f35450b9SMatthew G. Knepley PetscQuadrature q; 1437d8a60eaSMatthew G. Knepley const char *name; 144f35450b9SMatthew G. Knepley PetscInt Nc, Nq, Nqc; 1457d8a60eaSMatthew G. Knepley 1469566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, f, &obj)); 1479566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 1489566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName(obj, &name)); 1499566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>")); 1509566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE)); 1517d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 1529566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents((PetscFE)obj, &Nc)); 1539566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature((PetscFE)obj, &q)); 1549566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " FEM")); 1557d8a60eaSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 1569566063dSJacob Faibussowitsch PetscCall(PetscFVGetNumComponents((PetscFV)obj, &Nc)); 1579566063dSJacob Faibussowitsch PetscCall(PetscFVGetQuadrature((PetscFV)obj, &q)); 1589566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " FVM")); 1599371c9d4SSatish Balay } else SETERRQ(PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %" PetscInt_FMT, f); 16063a3b9bcSJacob Faibussowitsch if (Nc > 1) PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT " components", Nc)); 16163a3b9bcSJacob Faibussowitsch else PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT " component ", Nc)); 1629566063dSJacob Faibussowitsch if (ds->implicit[f]) PetscCall(PetscViewerASCIIPrintf(viewer, " (implicit)")); 1639566063dSJacob Faibussowitsch else PetscCall(PetscViewerASCIIPrintf(viewer, " (explicit)")); 1643e60c2a6SMatthew G. Knepley if (q) { 1659566063dSJacob Faibussowitsch PetscCall(PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL)); 16663a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " (Nq %" PetscInt_FMT " Nqc %" PetscInt_FMT ")", Nq, Nqc)); 1673e60c2a6SMatthew G. Knepley } 16863a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " %" PetscInt_FMT "-jet", ds->jetDegree[f])); 1699566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "\n")); 1709566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE)); 1719566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 1729566063dSJacob Faibussowitsch if (id == PETSCFE_CLASSID) PetscCall(PetscFEView((PetscFE)obj, viewer)); 1739566063dSJacob Faibussowitsch else if (id == PETSCFV_CLASSID) PetscCall(PetscFVView((PetscFV)obj, viewer)); 1749566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 17540967b3bSMatthew G. Knepley 1765fedec97SMatthew G. Knepley for (b = ds->boundary; b; b = b->next) { 17706ad1575SMatthew G. Knepley char *name; 17840967b3bSMatthew G. Knepley PetscInt c, i; 17940967b3bSMatthew G. Knepley 18040967b3bSMatthew G. Knepley if (b->field != f) continue; 1819566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 1829566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->lname, DMBoundaryConditionTypes[b->type])); 18345480ffeSMatthew G. Knepley if (!b->Nc) { 1849566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " all components\n")); 18540967b3bSMatthew G. Knepley } else { 1869566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " components: ")); 1879566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE)); 18845480ffeSMatthew G. Knepley for (c = 0; c < b->Nc; ++c) { 1899566063dSJacob Faibussowitsch if (c > 0) PetscCall(PetscViewerASCIIPrintf(viewer, ", ")); 19063a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT, b->comps[c])); 19140967b3bSMatthew G. Knepley } 1929566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "\n")); 1939566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE)); 19440967b3bSMatthew G. Knepley } 1959566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, " values: ")); 1969566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_FALSE)); 19745480ffeSMatthew G. Knepley for (i = 0; i < b->Nv; ++i) { 1989566063dSJacob Faibussowitsch if (i > 0) PetscCall(PetscViewerASCIIPrintf(viewer, ", ")); 19963a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT, b->values[i])); 20040967b3bSMatthew G. Knepley } 2019566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "\n")); 2029566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIUseTabs(viewer, PETSC_TRUE)); 2038e0d8d9cSMatthew G. Knepley if (b->func) { 2049566063dSJacob Faibussowitsch PetscCall(PetscDLAddr(b->func, &name)); 2059566063dSJacob Faibussowitsch if (name) PetscCall(PetscViewerASCIIPrintf(viewer, " func: %s\n", name)); 2069566063dSJacob Faibussowitsch else PetscCall(PetscViewerASCIIPrintf(viewer, " func: %p\n", b->func)); 2079566063dSJacob Faibussowitsch PetscCall(PetscFree(name)); 2088e0d8d9cSMatthew G. Knepley } 2098e0d8d9cSMatthew G. Knepley if (b->func_t) { 2109566063dSJacob Faibussowitsch PetscCall(PetscDLAddr(b->func_t, &name)); 2119566063dSJacob Faibussowitsch if (name) PetscCall(PetscViewerASCIIPrintf(viewer, " func_t: %s\n", name)); 2129566063dSJacob Faibussowitsch else PetscCall(PetscViewerASCIIPrintf(viewer, " func_t: %p\n", b->func_t)); 2139566063dSJacob Faibussowitsch PetscCall(PetscFree(name)); 2148e0d8d9cSMatthew G. Knepley } 2159566063dSJacob Faibussowitsch PetscCall(PetscWeakFormView(b->wf, viewer)); 2169566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 21740967b3bSMatthew G. Knepley } 2187d8a60eaSMatthew G. Knepley } 2199566063dSJacob Faibussowitsch PetscCall(PetscDSGetConstants(ds, &numConstants, &constants)); 22097b6e6e8SMatthew G. Knepley if (numConstants) { 22163a3b9bcSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "%" PetscInt_FMT " constants\n", numConstants)); 2229566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPushTab(viewer)); 2239566063dSJacob Faibussowitsch for (f = 0; f < numConstants; ++f) PetscCall(PetscViewerASCIIPrintf(viewer, "%g\n", (double)PetscRealPart(constants[f]))); 2249566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 22597b6e6e8SMatthew G. Knepley } 2269566063dSJacob Faibussowitsch PetscCall(PetscWeakFormView(ds->wf, viewer)); 2279566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPopTab(viewer)); 2287d8a60eaSMatthew G. Knepley PetscFunctionReturn(0); 2297d8a60eaSMatthew G. Knepley } 2307d8a60eaSMatthew G. Knepley 2312764a2aaSMatthew G. Knepley /*@C 232fe2efc57SMark PetscDSViewFromOptions - View from Options 233fe2efc57SMark 234fe2efc57SMark Collective on PetscDS 235fe2efc57SMark 236fe2efc57SMark Input Parameters: 237fe2efc57SMark + A - the PetscDS object 238736c3998SJose E. Roman . obj - Optional object 239736c3998SJose E. Roman - name - command line option 240fe2efc57SMark 241fe2efc57SMark Level: intermediate 242db781477SPatrick Sanan .seealso: `PetscDS`, `PetscDSView`, `PetscObjectViewFromOptions()`, `PetscDSCreate()` 243fe2efc57SMark @*/ 2449371c9d4SSatish Balay PetscErrorCode PetscDSViewFromOptions(PetscDS A, PetscObject obj, const char name[]) { 245fe2efc57SMark PetscFunctionBegin; 246fe2efc57SMark PetscValidHeaderSpecific(A, PETSCDS_CLASSID, 1); 2479566063dSJacob Faibussowitsch PetscCall(PetscObjectViewFromOptions((PetscObject)A, obj, name)); 248fe2efc57SMark PetscFunctionReturn(0); 249fe2efc57SMark } 250fe2efc57SMark 251fe2efc57SMark /*@C 2522764a2aaSMatthew G. Knepley PetscDSView - Views a PetscDS 2532764a2aaSMatthew G. Knepley 254d083f849SBarry Smith Collective on prob 2552764a2aaSMatthew G. Knepley 256d8d19677SJose E. Roman Input Parameters: 2572764a2aaSMatthew G. Knepley + prob - the PetscDS object to view 2582764a2aaSMatthew G. Knepley - v - the viewer 2592764a2aaSMatthew G. Knepley 2602764a2aaSMatthew G. Knepley Level: developer 2612764a2aaSMatthew G. Knepley 262db781477SPatrick Sanan .seealso `PetscDSDestroy()` 2632764a2aaSMatthew G. Knepley @*/ 2649371c9d4SSatish Balay PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v) { 2657d8a60eaSMatthew G. Knepley PetscBool iascii; 2662764a2aaSMatthew G. Knepley 2672764a2aaSMatthew G. Knepley PetscFunctionBegin; 2682764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2699566063dSJacob Faibussowitsch if (!v) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)prob), &v)); 270ad540459SPierre Jolivet else PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2); 2719566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)v, PETSCVIEWERASCII, &iascii)); 2729566063dSJacob Faibussowitsch if (iascii) PetscCall(PetscDSView_Ascii(prob, v)); 273dbbe0bcdSBarry Smith PetscTryTypeMethod(prob, view, v); 2742764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 2752764a2aaSMatthew G. Knepley } 2762764a2aaSMatthew G. Knepley 2772764a2aaSMatthew G. Knepley /*@ 2782764a2aaSMatthew G. Knepley PetscDSSetFromOptions - sets parameters in a PetscDS from the options database 2792764a2aaSMatthew G. Knepley 280d083f849SBarry Smith Collective on prob 2812764a2aaSMatthew G. Knepley 2822764a2aaSMatthew G. Knepley Input Parameter: 2832764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for 2842764a2aaSMatthew G. Knepley 2852764a2aaSMatthew G. Knepley Options Database: 286147403d9SBarry Smith + -petscds_type <type> - Set the DS type 287147403d9SBarry Smith . -petscds_view <view opt> - View the DS 288147403d9SBarry Smith . -petscds_jac_pre - Turn formation of a separate Jacobian preconditioner on or off 289147403d9SBarry Smith . -bc_<name> <ids> - Specify a list of label ids for a boundary condition 290147403d9SBarry Smith - -bc_<name>_comp <comps> - Specify a list of field components to constrain for a boundary condition 2912764a2aaSMatthew G. Knepley 2922764a2aaSMatthew G. Knepley Level: developer 2932764a2aaSMatthew G. Knepley 294db781477SPatrick Sanan .seealso `PetscDSView()` 2952764a2aaSMatthew G. Knepley @*/ 2969371c9d4SSatish Balay PetscErrorCode PetscDSSetFromOptions(PetscDS prob) { 297f1fd5e65SToby Isaac DSBoundary b; 2982764a2aaSMatthew G. Knepley const char *defaultType; 2992764a2aaSMatthew G. Knepley char name[256]; 3002764a2aaSMatthew G. Knepley PetscBool flg; 3012764a2aaSMatthew G. Knepley 3022764a2aaSMatthew G. Knepley PetscFunctionBegin; 3032764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3042764a2aaSMatthew G. Knepley if (!((PetscObject)prob)->type_name) { 3052764a2aaSMatthew G. Knepley defaultType = PETSCDSBASIC; 3062764a2aaSMatthew G. Knepley } else { 3072764a2aaSMatthew G. Knepley defaultType = ((PetscObject)prob)->type_name; 3082764a2aaSMatthew G. Knepley } 3099566063dSJacob Faibussowitsch PetscCall(PetscDSRegisterAll()); 3102764a2aaSMatthew G. Knepley 311d0609cedSBarry Smith PetscObjectOptionsBegin((PetscObject)prob); 312f1fd5e65SToby Isaac for (b = prob->boundary; b; b = b->next) { 313f1fd5e65SToby Isaac char optname[1024]; 314f1fd5e65SToby Isaac PetscInt ids[1024], len = 1024; 315f1fd5e65SToby Isaac PetscBool flg; 316f1fd5e65SToby Isaac 3179566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name)); 3189566063dSJacob Faibussowitsch PetscCall(PetscMemzero(ids, sizeof(ids))); 3199566063dSJacob Faibussowitsch PetscCall(PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg)); 320f1fd5e65SToby Isaac if (flg) { 32145480ffeSMatthew G. Knepley b->Nv = len; 3229566063dSJacob Faibussowitsch PetscCall(PetscFree(b->values)); 3239566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(len, &b->values)); 3249566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(b->values, ids, len)); 3259566063dSJacob Faibussowitsch PetscCall(PetscWeakFormRewriteKeys(b->wf, b->label, len, b->values)); 326f1fd5e65SToby Isaac } 327e7b0402cSSander Arens len = 1024; 3289566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name)); 3299566063dSJacob Faibussowitsch PetscCall(PetscMemzero(ids, sizeof(ids))); 3309566063dSJacob Faibussowitsch PetscCall(PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg)); 331f1fd5e65SToby Isaac if (flg) { 33245480ffeSMatthew G. Knepley b->Nc = len; 3339566063dSJacob Faibussowitsch PetscCall(PetscFree(b->comps)); 3349566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(len, &b->comps)); 3359566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(b->comps, ids, len)); 336f1fd5e65SToby Isaac } 337f1fd5e65SToby Isaac } 3389566063dSJacob Faibussowitsch PetscCall(PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg)); 3392764a2aaSMatthew G. Knepley if (flg) { 3409566063dSJacob Faibussowitsch PetscCall(PetscDSSetType(prob, name)); 3412764a2aaSMatthew G. Knepley } else if (!((PetscObject)prob)->type_name) { 3429566063dSJacob Faibussowitsch PetscCall(PetscDSSetType(prob, defaultType)); 3432764a2aaSMatthew G. Knepley } 3449566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg)); 345dbbe0bcdSBarry Smith PetscTryTypeMethod(prob, setfromoptions); 3462764a2aaSMatthew G. Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 347dbbe0bcdSBarry Smith PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)prob, PetscOptionsObject)); 348d0609cedSBarry Smith PetscOptionsEnd(); 3499566063dSJacob Faibussowitsch if (prob->Nf) PetscCall(PetscDSViewFromOptions(prob, NULL, "-petscds_view")); 3502764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 3512764a2aaSMatthew G. Knepley } 3522764a2aaSMatthew G. Knepley 3532764a2aaSMatthew G. Knepley /*@C 3542764a2aaSMatthew G. Knepley PetscDSSetUp - Construct data structures for the PetscDS 3552764a2aaSMatthew G. Knepley 356d083f849SBarry Smith Collective on prob 3572764a2aaSMatthew G. Knepley 3582764a2aaSMatthew G. Knepley Input Parameter: 3592764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup 3602764a2aaSMatthew G. Knepley 3612764a2aaSMatthew G. Knepley Level: developer 3622764a2aaSMatthew G. Knepley 363db781477SPatrick Sanan .seealso `PetscDSView()`, `PetscDSDestroy()` 3642764a2aaSMatthew G. Knepley @*/ 3659371c9d4SSatish Balay PetscErrorCode PetscDSSetUp(PetscDS prob) { 3662764a2aaSMatthew G. Knepley const PetscInt Nf = prob->Nf; 367f9244615SMatthew G. Knepley PetscBool hasH = PETSC_FALSE; 3684bee2e38SMatthew G. Knepley PetscInt dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f; 3692764a2aaSMatthew G. Knepley 3702764a2aaSMatthew G. Knepley PetscFunctionBegin; 3712764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3722764a2aaSMatthew G. Knepley if (prob->setup) PetscFunctionReturn(0); 3732764a2aaSMatthew G. Knepley /* Calculate sizes */ 3749566063dSJacob Faibussowitsch PetscCall(PetscDSGetSpatialDimension(prob, &dim)); 3759566063dSJacob Faibussowitsch PetscCall(PetscDSGetCoordinateDimension(prob, &dimEmbed)); 376f744cafaSSander Arens prob->totDim = prob->totComp = 0; 3779566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(Nf, &prob->Nc, Nf, &prob->Nb)); 3789566063dSJacob Faibussowitsch PetscCall(PetscCalloc2(Nf + 1, &prob->off, Nf + 1, &prob->offDer)); 3799566063dSJacob 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])); 3809566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(Nf, &prob->T, Nf, &prob->Tf)); 3812764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3829de99aefSMatthew G. Knepley PetscObject obj; 3839de99aefSMatthew G. Knepley PetscClassId id; 384665f567fSMatthew G. Knepley PetscQuadrature q = NULL; 3859de99aefSMatthew G. Knepley PetscInt Nq = 0, Nb, Nc; 3862764a2aaSMatthew G. Knepley 3879566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, f, &obj)); 388f9244615SMatthew G. Knepley if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE; 389665f567fSMatthew G. Knepley if (!obj) { 390665f567fSMatthew G. Knepley /* Empty mesh */ 391665f567fSMatthew G. Knepley Nb = Nc = 0; 392665f567fSMatthew G. Knepley prob->T[f] = prob->Tf[f] = NULL; 393665f567fSMatthew G. Knepley } else { 3949566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 3959de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 3969de99aefSMatthew G. Knepley PetscFE fe = (PetscFE)obj; 3979de99aefSMatthew G. Knepley 3989566063dSJacob Faibussowitsch PetscCall(PetscFEGetQuadrature(fe, &q)); 3999566063dSJacob Faibussowitsch PetscCall(PetscFEGetDimension(fe, &Nb)); 4009566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(fe, &Nc)); 4019566063dSJacob Faibussowitsch PetscCall(PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f])); 4029566063dSJacob Faibussowitsch PetscCall(PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f])); 4039de99aefSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 4049de99aefSMatthew G. Knepley PetscFV fv = (PetscFV)obj; 4059de99aefSMatthew G. Knepley 4069566063dSJacob Faibussowitsch PetscCall(PetscFVGetQuadrature(fv, &q)); 4079566063dSJacob Faibussowitsch PetscCall(PetscFVGetNumComponents(fv, &Nc)); 4089c3cf19fSMatthew G. Knepley Nb = Nc; 4099566063dSJacob Faibussowitsch PetscCall(PetscFVGetCellTabulation(fv, &prob->T[f])); 4104d0b9603SSander Arens /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */ 41163a3b9bcSJacob Faibussowitsch } else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %" PetscInt_FMT, f); 412665f567fSMatthew G. Knepley } 41347e57110SSander Arens prob->Nc[f] = Nc; 41447e57110SSander Arens prob->Nb[f] = Nb; 415194d53e6SMatthew G. Knepley prob->off[f + 1] = Nc + prob->off[f]; 416194d53e6SMatthew G. Knepley prob->offDer[f + 1] = Nc * dim + prob->offDer[f]; 4179ee2af8cSMatthew G. Knepley prob->offCohesive[0][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) + prob->offCohesive[0][f]; 4189ee2af8cSMatthew G. Knepley prob->offDerCohesive[0][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) * dimEmbed + prob->offDerCohesive[0][f]; 4199ee2af8cSMatthew G. Knepley prob->offCohesive[1][f] = (prob->cohesive[f] ? 0 : Nc) + prob->offCohesive[0][f]; 4209ee2af8cSMatthew G. Knepley prob->offDerCohesive[1][f] = (prob->cohesive[f] ? 0 : Nc) * dimEmbed + prob->offDerCohesive[0][f]; 4219ee2af8cSMatthew G. Knepley prob->offCohesive[2][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) + prob->offCohesive[2][f]; 4229ee2af8cSMatthew G. Knepley prob->offDerCohesive[2][f + 1] = (prob->cohesive[f] ? Nc : Nc * 2) * dimEmbed + prob->offDerCohesive[2][f]; 4239566063dSJacob Faibussowitsch if (q) PetscCall(PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL)); 4242764a2aaSMatthew G. Knepley NqMax = PetscMax(NqMax, Nq); 4254bee2e38SMatthew G. Knepley NbMax = PetscMax(NbMax, Nb); 4262764a2aaSMatthew G. Knepley NcMax = PetscMax(NcMax, Nc); 4279c3cf19fSMatthew G. Knepley prob->totDim += Nb; 4282764a2aaSMatthew G. Knepley prob->totComp += Nc; 4295fedec97SMatthew G. Knepley /* There are two faces for all fields on a cohesive cell, except for cohesive fields */ 4305fedec97SMatthew G. Knepley if (prob->isCohesive && !prob->cohesive[f]) prob->totDim += Nb; 4312764a2aaSMatthew G. Knepley } 4329ee2af8cSMatthew G. Knepley prob->offCohesive[1][Nf] = prob->offCohesive[0][Nf]; 4339ee2af8cSMatthew G. Knepley prob->offDerCohesive[1][Nf] = prob->offDerCohesive[0][Nf]; 4342764a2aaSMatthew G. Knepley /* Allocate works space */ 4355fedec97SMatthew G. Knepley NsMax = 2; /* A non-cohesive discretizations can be used on a cohesive cell, so we need this extra workspace for all DS */ 4369566063dSJacob 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)); 4379566063dSJacob Faibussowitsch PetscCall(PetscMalloc5(dimEmbed, &prob->x, NbMax * NcMax, &prob->basisReal, NbMax * NcMax * dimEmbed, &prob->basisDerReal, NbMax * NcMax, &prob->testReal, NbMax * NcMax * dimEmbed, &prob->testDerReal)); 4389371c9d4SSatish 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, 4399371c9d4SSatish Balay &prob->g2, NsMax * NsMax * NqMax * NcMax * NcMax * dimEmbed * dimEmbed, &prob->g3)); 440dbbe0bcdSBarry Smith PetscTryTypeMethod(prob, setup); 4412764a2aaSMatthew G. Knepley prob->setup = PETSC_TRUE; 4422764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4432764a2aaSMatthew G. Knepley } 4442764a2aaSMatthew G. Knepley 4459371c9d4SSatish Balay static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob) { 4462764a2aaSMatthew G. Knepley PetscFunctionBegin; 4479566063dSJacob Faibussowitsch PetscCall(PetscFree2(prob->Nc, prob->Nb)); 4489566063dSJacob Faibussowitsch PetscCall(PetscFree2(prob->off, prob->offDer)); 4499566063dSJacob Faibussowitsch PetscCall(PetscFree6(prob->offCohesive[0], prob->offCohesive[1], prob->offCohesive[2], prob->offDerCohesive[0], prob->offDerCohesive[1], prob->offDerCohesive[2])); 4509566063dSJacob Faibussowitsch PetscCall(PetscFree2(prob->T, prob->Tf)); 4519566063dSJacob Faibussowitsch PetscCall(PetscFree3(prob->u, prob->u_t, prob->u_x)); 4529566063dSJacob Faibussowitsch PetscCall(PetscFree5(prob->x, prob->basisReal, prob->basisDerReal, prob->testReal, prob->testDerReal)); 4539566063dSJacob Faibussowitsch PetscCall(PetscFree6(prob->f0, prob->f1, prob->g0, prob->g1, prob->g2, prob->g3)); 4542764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4552764a2aaSMatthew G. Knepley } 4562764a2aaSMatthew G. Knepley 4579371c9d4SSatish Balay static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew) { 458f744cafaSSander Arens PetscObject *tmpd; 45934aa8a36SMatthew G. Knepley PetscBool *tmpi; 460f9244615SMatthew G. Knepley PetscInt *tmpk; 4615fedec97SMatthew G. Knepley PetscBool *tmpc; 4626528b96dSMatthew G. Knepley PetscPointFunc *tmpup; 463f2cacb80SMatthew G. Knepley PetscSimplePointFunc *tmpexactSol, *tmpexactSol_t; 464f2cacb80SMatthew G. Knepley void **tmpexactCtx, **tmpexactCtx_t; 4650c2f2876SMatthew G. Knepley void **tmpctx; 46634aa8a36SMatthew G. Knepley PetscInt Nf = prob->Nf, f; 4672764a2aaSMatthew G. Knepley 4682764a2aaSMatthew G. Knepley PetscFunctionBegin; 4692764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 4702764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 4719566063dSJacob Faibussowitsch PetscCall(PetscDSDestroyStructs_Static(prob)); 4729566063dSJacob Faibussowitsch PetscCall(PetscMalloc4(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpc, NfNew, &tmpk)); 4739371c9d4SSatish Balay for (f = 0; f < Nf; ++f) { 4749371c9d4SSatish Balay tmpd[f] = prob->disc[f]; 4759371c9d4SSatish Balay tmpi[f] = prob->implicit[f]; 4769371c9d4SSatish Balay tmpc[f] = prob->cohesive[f]; 4779371c9d4SSatish Balay tmpk[f] = prob->jetDegree[f]; 4789371c9d4SSatish Balay } 4799371c9d4SSatish Balay for (f = Nf; f < NfNew; ++f) { 4809371c9d4SSatish Balay tmpd[f] = NULL; 4819371c9d4SSatish Balay tmpi[f] = PETSC_TRUE, tmpc[f] = PETSC_FALSE; 4829371c9d4SSatish Balay tmpk[f] = 1; 4839371c9d4SSatish Balay } 4849566063dSJacob Faibussowitsch PetscCall(PetscFree4(prob->disc, prob->implicit, prob->cohesive, prob->jetDegree)); 4859566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetNumFields(prob->wf, NfNew)); 4862764a2aaSMatthew G. Knepley prob->Nf = NfNew; 4872764a2aaSMatthew G. Knepley prob->disc = tmpd; 488249df284SMatthew G. Knepley prob->implicit = tmpi; 4895fedec97SMatthew G. Knepley prob->cohesive = tmpc; 490f9244615SMatthew G. Knepley prob->jetDegree = tmpk; 4919566063dSJacob Faibussowitsch PetscCall(PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx)); 49232d2bbc9SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f]; 4930c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f]; 49432d2bbc9SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL; 4950c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL; 4969566063dSJacob Faibussowitsch PetscCall(PetscFree2(prob->update, prob->ctx)); 49732d2bbc9SMatthew G. Knepley prob->update = tmpup; 4980c2f2876SMatthew G. Knepley prob->ctx = tmpctx; 4999566063dSJacob Faibussowitsch PetscCall(PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t)); 500c371a6d1SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f]; 50195cbbfd3SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f]; 502f2cacb80SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f]; 503f2cacb80SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f]; 504c371a6d1SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL; 50595cbbfd3SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL; 506f2cacb80SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL; 507f2cacb80SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL; 5089566063dSJacob Faibussowitsch PetscCall(PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t)); 509c371a6d1SMatthew G. Knepley prob->exactSol = tmpexactSol; 51095cbbfd3SMatthew G. Knepley prob->exactCtx = tmpexactCtx; 511f2cacb80SMatthew G. Knepley prob->exactSol_t = tmpexactSol_t; 512f2cacb80SMatthew G. Knepley prob->exactCtx_t = tmpexactCtx_t; 5132764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5142764a2aaSMatthew G. Knepley } 5152764a2aaSMatthew G. Knepley 5162764a2aaSMatthew G. Knepley /*@ 5172764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 5182764a2aaSMatthew G. Knepley 519d083f849SBarry Smith Collective on prob 5202764a2aaSMatthew G. Knepley 5212764a2aaSMatthew G. Knepley Input Parameter: 5222764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 5232764a2aaSMatthew G. Knepley 5242764a2aaSMatthew G. Knepley Level: developer 5252764a2aaSMatthew G. Knepley 526db781477SPatrick Sanan .seealso `PetscDSView()` 5272764a2aaSMatthew G. Knepley @*/ 5289371c9d4SSatish Balay PetscErrorCode PetscDSDestroy(PetscDS *ds) { 5292764a2aaSMatthew G. Knepley PetscInt f; 5302764a2aaSMatthew G. Knepley 5312764a2aaSMatthew G. Knepley PetscFunctionBegin; 5326528b96dSMatthew G. Knepley if (!*ds) PetscFunctionReturn(0); 5336528b96dSMatthew G. Knepley PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1); 5342764a2aaSMatthew G. Knepley 5359371c9d4SSatish Balay if (--((PetscObject)(*ds))->refct > 0) { 5369371c9d4SSatish Balay *ds = NULL; 5379371c9d4SSatish Balay PetscFunctionReturn(0); 5389371c9d4SSatish Balay } 5396528b96dSMatthew G. Knepley ((PetscObject)(*ds))->refct = 0; 5406528b96dSMatthew G. Knepley if ((*ds)->subprobs) { 541df3a45bdSMatthew G. Knepley PetscInt dim, d; 542df3a45bdSMatthew G. Knepley 5439566063dSJacob Faibussowitsch PetscCall(PetscDSGetSpatialDimension(*ds, &dim)); 5449566063dSJacob Faibussowitsch for (d = 0; d < dim; ++d) PetscCall(PetscDSDestroy(&(*ds)->subprobs[d])); 545df3a45bdSMatthew G. Knepley } 5469566063dSJacob Faibussowitsch PetscCall(PetscFree((*ds)->subprobs)); 5479566063dSJacob Faibussowitsch PetscCall(PetscDSDestroyStructs_Static(*ds)); 54848a46eb9SPierre Jolivet for (f = 0; f < (*ds)->Nf; ++f) PetscCall(PetscObjectDereference((*ds)->disc[f])); 5499566063dSJacob Faibussowitsch PetscCall(PetscFree4((*ds)->disc, (*ds)->implicit, (*ds)->cohesive, (*ds)->jetDegree)); 5509566063dSJacob Faibussowitsch PetscCall(PetscWeakFormDestroy(&(*ds)->wf)); 5519566063dSJacob Faibussowitsch PetscCall(PetscFree2((*ds)->update, (*ds)->ctx)); 5529566063dSJacob Faibussowitsch PetscCall(PetscFree4((*ds)->exactSol, (*ds)->exactCtx, (*ds)->exactSol_t, (*ds)->exactCtx_t)); 553dbbe0bcdSBarry Smith PetscTryTypeMethod((*ds), destroy); 5549566063dSJacob Faibussowitsch PetscCall(PetscDSDestroyBoundary(*ds)); 5559566063dSJacob Faibussowitsch PetscCall(PetscFree((*ds)->constants)); 5569566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(ds)); 5572764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5582764a2aaSMatthew G. Knepley } 5592764a2aaSMatthew G. Knepley 5602764a2aaSMatthew G. Knepley /*@ 5612764a2aaSMatthew G. Knepley PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType(). 5622764a2aaSMatthew G. Knepley 563d083f849SBarry Smith Collective 5642764a2aaSMatthew G. Knepley 5652764a2aaSMatthew G. Knepley Input Parameter: 5662764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object 5672764a2aaSMatthew G. Knepley 5682764a2aaSMatthew G. Knepley Output Parameter: 5696528b96dSMatthew G. Knepley . ds - The PetscDS object 5702764a2aaSMatthew G. Knepley 5712764a2aaSMatthew G. Knepley Level: beginner 5722764a2aaSMatthew G. Knepley 573db781477SPatrick Sanan .seealso: `PetscDSSetType()`, `PETSCDSBASIC` 5742764a2aaSMatthew G. Knepley @*/ 5759371c9d4SSatish Balay PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds) { 5762764a2aaSMatthew G. Knepley PetscDS p; 5772764a2aaSMatthew G. Knepley 5782764a2aaSMatthew G. Knepley PetscFunctionBegin; 5796528b96dSMatthew G. Knepley PetscValidPointer(ds, 2); 5806528b96dSMatthew G. Knepley *ds = NULL; 5819566063dSJacob Faibussowitsch PetscCall(PetscDSInitializePackage()); 5822764a2aaSMatthew G. Knepley 5839566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView)); 5842764a2aaSMatthew G. Knepley 5852764a2aaSMatthew G. Knepley p->Nf = 0; 5862764a2aaSMatthew G. Knepley p->setup = PETSC_FALSE; 58797b6e6e8SMatthew G. Knepley p->numConstants = 0; 58897b6e6e8SMatthew G. Knepley p->constants = NULL; 589a859676bSMatthew G. Knepley p->dimEmbed = -1; 59055c1f793SMatthew G. Knepley p->useJacPre = PETSC_TRUE; 5919566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCreate(comm, &p->wf)); 5922764a2aaSMatthew G. Knepley 5936528b96dSMatthew G. Knepley *ds = p; 5942764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5952764a2aaSMatthew G. Knepley } 5962764a2aaSMatthew G. Knepley 597bc4ae4beSMatthew G. Knepley /*@ 598bc4ae4beSMatthew G. Knepley PetscDSGetNumFields - Returns the number of fields in the DS 599bc4ae4beSMatthew G. Knepley 600bc4ae4beSMatthew G. Knepley Not collective 601bc4ae4beSMatthew G. Knepley 602bc4ae4beSMatthew G. Knepley Input Parameter: 603bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 604bc4ae4beSMatthew G. Knepley 605bc4ae4beSMatthew G. Knepley Output Parameter: 606bc4ae4beSMatthew G. Knepley . Nf - The number of fields 607bc4ae4beSMatthew G. Knepley 608bc4ae4beSMatthew G. Knepley Level: beginner 609bc4ae4beSMatthew G. Knepley 610db781477SPatrick Sanan .seealso: `PetscDSGetSpatialDimension()`, `PetscDSCreate()` 611bc4ae4beSMatthew G. Knepley @*/ 6129371c9d4SSatish Balay PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) { 6132764a2aaSMatthew G. Knepley PetscFunctionBegin; 6142764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 615dadcf809SJacob Faibussowitsch PetscValidIntPointer(Nf, 2); 6162764a2aaSMatthew G. Knepley *Nf = prob->Nf; 6172764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6182764a2aaSMatthew G. Knepley } 6192764a2aaSMatthew G. Knepley 620bc4ae4beSMatthew G. Knepley /*@ 621a859676bSMatthew G. Knepley PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations 622bc4ae4beSMatthew G. Knepley 623bc4ae4beSMatthew G. Knepley Not collective 624bc4ae4beSMatthew G. Knepley 625bc4ae4beSMatthew G. Knepley Input Parameter: 626bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 627bc4ae4beSMatthew G. Knepley 628bc4ae4beSMatthew G. Knepley Output Parameter: 629bc4ae4beSMatthew G. Knepley . dim - The spatial dimension 630bc4ae4beSMatthew G. Knepley 631bc4ae4beSMatthew G. Knepley Level: beginner 632bc4ae4beSMatthew G. Knepley 633db781477SPatrick Sanan .seealso: `PetscDSGetCoordinateDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 634bc4ae4beSMatthew G. Knepley @*/ 6359371c9d4SSatish Balay PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) { 6362764a2aaSMatthew G. Knepley PetscFunctionBegin; 6372764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 638dadcf809SJacob Faibussowitsch PetscValidIntPointer(dim, 2); 6392764a2aaSMatthew G. Knepley *dim = 0; 6409de99aefSMatthew G. Knepley if (prob->Nf) { 6419de99aefSMatthew G. Knepley PetscObject obj; 6429de99aefSMatthew G. Knepley PetscClassId id; 6439de99aefSMatthew G. Knepley 6449566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, 0, &obj)); 645665f567fSMatthew G. Knepley if (obj) { 6469566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 6479566063dSJacob Faibussowitsch if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetSpatialDimension((PetscFE)obj, dim)); 6489566063dSJacob Faibussowitsch else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetSpatialDimension((PetscFV)obj, dim)); 64998921bdaSJacob Faibussowitsch else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 6509de99aefSMatthew G. Knepley } 651665f567fSMatthew G. Knepley } 6522764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6532764a2aaSMatthew G. Knepley } 6542764a2aaSMatthew G. Knepley 655bc4ae4beSMatthew G. Knepley /*@ 656a859676bSMatthew G. Knepley PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 657a859676bSMatthew G. Knepley 658a859676bSMatthew G. Knepley Not collective 659a859676bSMatthew G. Knepley 660a859676bSMatthew G. Knepley Input Parameter: 661a859676bSMatthew G. Knepley . prob - The PetscDS object 662a859676bSMatthew G. Knepley 663a859676bSMatthew G. Knepley Output Parameter: 664a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension 665a859676bSMatthew G. Knepley 666a859676bSMatthew G. Knepley Level: beginner 667a859676bSMatthew G. Knepley 668db781477SPatrick Sanan .seealso: `PetscDSSetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 669a859676bSMatthew G. Knepley @*/ 6709371c9d4SSatish Balay PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed) { 671a859676bSMatthew G. Knepley PetscFunctionBegin; 672a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 673dadcf809SJacob Faibussowitsch PetscValidIntPointer(dimEmbed, 2); 67408401ef6SPierre Jolivet PetscCheck(prob->dimEmbed >= 0, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS"); 675a859676bSMatthew G. Knepley *dimEmbed = prob->dimEmbed; 676a859676bSMatthew G. Knepley PetscFunctionReturn(0); 677a859676bSMatthew G. Knepley } 678a859676bSMatthew G. Knepley 679a859676bSMatthew G. Knepley /*@ 680a859676bSMatthew G. Knepley PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 681a859676bSMatthew G. Knepley 682d083f849SBarry Smith Logically collective on prob 683a859676bSMatthew G. Knepley 684a859676bSMatthew G. Knepley Input Parameters: 685a859676bSMatthew G. Knepley + prob - The PetscDS object 686a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension 687a859676bSMatthew G. Knepley 688a859676bSMatthew G. Knepley Level: beginner 689a859676bSMatthew G. Knepley 690db781477SPatrick Sanan .seealso: `PetscDSGetCoordinateDimension()`, `PetscDSGetSpatialDimension()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 691a859676bSMatthew G. Knepley @*/ 6929371c9d4SSatish Balay PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed) { 693a859676bSMatthew G. Knepley PetscFunctionBegin; 694a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 69563a3b9bcSJacob Faibussowitsch PetscCheck(dimEmbed >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %" PetscInt_FMT, dimEmbed); 696a859676bSMatthew G. Knepley prob->dimEmbed = dimEmbed; 697a859676bSMatthew G. Knepley PetscFunctionReturn(0); 698a859676bSMatthew G. Knepley } 699a859676bSMatthew G. Knepley 700a859676bSMatthew G. Knepley /*@ 7015fedec97SMatthew G. Knepley PetscDSIsCohesive - Returns the flag indicating that this DS is for a cohesive cell 7028edf6225SMatthew G. Knepley 7038edf6225SMatthew G. Knepley Not collective 7048edf6225SMatthew G. Knepley 7058edf6225SMatthew G. Knepley Input Parameter: 7065fedec97SMatthew G. Knepley . ds - The PetscDS object 7078edf6225SMatthew G. Knepley 7088edf6225SMatthew G. Knepley Output Parameter: 7095fedec97SMatthew G. Knepley . isCohesive - The flag 7108edf6225SMatthew G. Knepley 7118edf6225SMatthew G. Knepley Level: developer 7128edf6225SMatthew G. Knepley 713db781477SPatrick Sanan .seealso: `PetscDSGetNumCohesive()`, `PetscDSGetCohesive()`, `PetscDSSetCohesive()`, `PetscDSCreate()` 7148edf6225SMatthew G. Knepley @*/ 7159371c9d4SSatish Balay PetscErrorCode PetscDSIsCohesive(PetscDS ds, PetscBool *isCohesive) { 7168edf6225SMatthew G. Knepley PetscFunctionBegin; 7175fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 718dadcf809SJacob Faibussowitsch PetscValidBoolPointer(isCohesive, 2); 7195fedec97SMatthew G. Knepley *isCohesive = ds->isCohesive; 7208edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7218edf6225SMatthew G. Knepley } 7228edf6225SMatthew G. Knepley 7238edf6225SMatthew G. Knepley /*@ 7245fedec97SMatthew G. Knepley PetscDSGetNumCohesive - Returns the numer of cohesive fields, meaning those defined on the interior of a cohesive cell 7255fedec97SMatthew G. Knepley 7265fedec97SMatthew G. Knepley Not collective 7275fedec97SMatthew G. Knepley 7285fedec97SMatthew G. Knepley Input Parameter: 7295fedec97SMatthew G. Knepley . ds - The PetscDS object 7305fedec97SMatthew G. Knepley 7315fedec97SMatthew G. Knepley Output Parameter: 7325fedec97SMatthew G. Knepley . numCohesive - The number of cohesive fields 7335fedec97SMatthew G. Knepley 7345fedec97SMatthew G. Knepley Level: developer 7355fedec97SMatthew G. Knepley 736db781477SPatrick Sanan .seealso: `PetscDSSetCohesive()`, `PetscDSCreate()` 7375fedec97SMatthew G. Knepley @*/ 7389371c9d4SSatish Balay PetscErrorCode PetscDSGetNumCohesive(PetscDS ds, PetscInt *numCohesive) { 7395fedec97SMatthew G. Knepley PetscInt f; 7405fedec97SMatthew G. Knepley 7415fedec97SMatthew G. Knepley PetscFunctionBegin; 7425fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 743dadcf809SJacob Faibussowitsch PetscValidIntPointer(numCohesive, 2); 7445fedec97SMatthew G. Knepley *numCohesive = 0; 7455fedec97SMatthew G. Knepley for (f = 0; f < ds->Nf; ++f) *numCohesive += ds->cohesive[f] ? 1 : 0; 7465fedec97SMatthew G. Knepley PetscFunctionReturn(0); 7475fedec97SMatthew G. Knepley } 7485fedec97SMatthew G. Knepley 7495fedec97SMatthew G. Knepley /*@ 7505fedec97SMatthew G. Knepley PetscDSGetCohesive - Returns the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell 7515fedec97SMatthew G. Knepley 7525fedec97SMatthew G. Knepley Not collective 7535fedec97SMatthew G. Knepley 754f1a722f8SMatthew G. Knepley Input Parameters: 7555fedec97SMatthew G. Knepley + ds - The PetscDS object 7565fedec97SMatthew G. Knepley - f - The field index 7575fedec97SMatthew G. Knepley 7585fedec97SMatthew G. Knepley Output Parameter: 7595fedec97SMatthew G. Knepley . isCohesive - The flag 7605fedec97SMatthew G. Knepley 7615fedec97SMatthew G. Knepley Level: developer 7625fedec97SMatthew G. Knepley 763db781477SPatrick Sanan .seealso: `PetscDSSetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()` 7645fedec97SMatthew G. Knepley @*/ 7659371c9d4SSatish Balay PetscErrorCode PetscDSGetCohesive(PetscDS ds, PetscInt f, PetscBool *isCohesive) { 7665fedec97SMatthew G. Knepley PetscFunctionBegin; 7675fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 768dadcf809SJacob Faibussowitsch PetscValidBoolPointer(isCohesive, 3); 76963a3b9bcSJacob 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); 7705fedec97SMatthew G. Knepley *isCohesive = ds->cohesive[f]; 7715fedec97SMatthew G. Knepley PetscFunctionReturn(0); 7725fedec97SMatthew G. Knepley } 7735fedec97SMatthew G. Knepley 7745fedec97SMatthew G. Knepley /*@ 7755fedec97SMatthew G. Knepley PetscDSSetCohesive - Set the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell 7768edf6225SMatthew G. Knepley 7778edf6225SMatthew G. Knepley Not collective 7788edf6225SMatthew G. Knepley 7798edf6225SMatthew G. Knepley Input Parameters: 7805fedec97SMatthew G. Knepley + ds - The PetscDS object 7815fedec97SMatthew G. Knepley . f - The field index 7825fedec97SMatthew G. Knepley - isCohesive - The flag for a cohesive field 7838edf6225SMatthew G. Knepley 7848edf6225SMatthew G. Knepley Level: developer 7858edf6225SMatthew G. Knepley 786db781477SPatrick Sanan .seealso: `PetscDSGetCohesive()`, `PetscDSIsCohesive()`, `PetscDSCreate()` 7878edf6225SMatthew G. Knepley @*/ 7889371c9d4SSatish Balay PetscErrorCode PetscDSSetCohesive(PetscDS ds, PetscInt f, PetscBool isCohesive) { 7895fedec97SMatthew G. Knepley PetscInt i; 7905fedec97SMatthew G. Knepley 7918edf6225SMatthew G. Knepley PetscFunctionBegin; 7925fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 79363a3b9bcSJacob 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); 7945fedec97SMatthew G. Knepley ds->cohesive[f] = isCohesive; 7955fedec97SMatthew G. Knepley ds->isCohesive = PETSC_FALSE; 7965fedec97SMatthew G. Knepley for (i = 0; i < ds->Nf; ++i) ds->isCohesive = ds->isCohesive || ds->cohesive[f] ? PETSC_TRUE : PETSC_FALSE; 7978edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7988edf6225SMatthew G. Knepley } 7998edf6225SMatthew G. Knepley 8008edf6225SMatthew G. Knepley /*@ 801bc4ae4beSMatthew G. Knepley PetscDSGetTotalDimension - Returns the total size of the approximation space for this system 802bc4ae4beSMatthew G. Knepley 803bc4ae4beSMatthew G. Knepley Not collective 804bc4ae4beSMatthew G. Knepley 805bc4ae4beSMatthew G. Knepley Input Parameter: 806bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 807bc4ae4beSMatthew G. Knepley 808bc4ae4beSMatthew G. Knepley Output Parameter: 809bc4ae4beSMatthew G. Knepley . dim - The total problem dimension 810bc4ae4beSMatthew G. Knepley 811bc4ae4beSMatthew G. Knepley Level: beginner 812bc4ae4beSMatthew G. Knepley 813db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()` 814bc4ae4beSMatthew G. Knepley @*/ 8159371c9d4SSatish Balay PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) { 8162764a2aaSMatthew G. Knepley PetscFunctionBegin; 8172764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8189566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 819dadcf809SJacob Faibussowitsch PetscValidIntPointer(dim, 2); 8202764a2aaSMatthew G. Knepley *dim = prob->totDim; 8212764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8222764a2aaSMatthew G. Knepley } 8232764a2aaSMatthew G. Knepley 824bc4ae4beSMatthew G. Knepley /*@ 825bc4ae4beSMatthew G. Knepley PetscDSGetTotalComponents - Returns the total number of components in this system 826bc4ae4beSMatthew G. Knepley 827bc4ae4beSMatthew G. Knepley Not collective 828bc4ae4beSMatthew G. Knepley 829bc4ae4beSMatthew G. Knepley Input Parameter: 830bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 831bc4ae4beSMatthew G. Knepley 832bc4ae4beSMatthew G. Knepley Output Parameter: 833bc4ae4beSMatthew G. Knepley . dim - The total number of components 834bc4ae4beSMatthew G. Knepley 835bc4ae4beSMatthew G. Knepley Level: beginner 836bc4ae4beSMatthew G. Knepley 837db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()` 838bc4ae4beSMatthew G. Knepley @*/ 8399371c9d4SSatish Balay PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) { 8402764a2aaSMatthew G. Knepley PetscFunctionBegin; 8412764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8429566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 843dadcf809SJacob Faibussowitsch PetscValidIntPointer(Nc, 2); 8442764a2aaSMatthew G. Knepley *Nc = prob->totComp; 8452764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8462764a2aaSMatthew G. Knepley } 8472764a2aaSMatthew G. Knepley 848bc4ae4beSMatthew G. Knepley /*@ 849bc4ae4beSMatthew G. Knepley PetscDSGetDiscretization - Returns the discretization object for the given field 850bc4ae4beSMatthew G. Knepley 851bc4ae4beSMatthew G. Knepley Not collective 852bc4ae4beSMatthew G. Knepley 853bc4ae4beSMatthew G. Knepley Input Parameters: 854bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 855bc4ae4beSMatthew G. Knepley - f - The field number 856bc4ae4beSMatthew G. Knepley 857bc4ae4beSMatthew G. Knepley Output Parameter: 858bc4ae4beSMatthew G. Knepley . disc - The discretization object 859bc4ae4beSMatthew G. Knepley 860bc4ae4beSMatthew G. Knepley Level: beginner 861bc4ae4beSMatthew G. Knepley 862db781477SPatrick Sanan .seealso: `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 863bc4ae4beSMatthew G. Knepley @*/ 8649371c9d4SSatish Balay PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) { 8656528b96dSMatthew G. Knepley PetscFunctionBeginHot; 8662764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8672764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 86863a3b9bcSJacob 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); 8692764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 8702764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8712764a2aaSMatthew G. Knepley } 8722764a2aaSMatthew G. Knepley 873bc4ae4beSMatthew G. Knepley /*@ 874bc4ae4beSMatthew G. Knepley PetscDSSetDiscretization - Sets the discretization object for the given field 875bc4ae4beSMatthew G. Knepley 876bc4ae4beSMatthew G. Knepley Not collective 877bc4ae4beSMatthew G. Knepley 878bc4ae4beSMatthew G. Knepley Input Parameters: 879bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 880bc4ae4beSMatthew G. Knepley . f - The field number 881bc4ae4beSMatthew G. Knepley - disc - The discretization object 882bc4ae4beSMatthew G. Knepley 883bc4ae4beSMatthew G. Knepley Level: beginner 884bc4ae4beSMatthew G. Knepley 885db781477SPatrick Sanan .seealso: `PetscDSGetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 886bc4ae4beSMatthew G. Knepley @*/ 8879371c9d4SSatish Balay PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) { 8882764a2aaSMatthew G. Knepley PetscFunctionBegin; 8892764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 890665f567fSMatthew G. Knepley if (disc) PetscValidPointer(disc, 3); 89163a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 8929566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(prob, f + 1)); 8939566063dSJacob Faibussowitsch PetscCall(PetscObjectDereference(prob->disc[f])); 8942764a2aaSMatthew G. Knepley prob->disc[f] = disc; 8959566063dSJacob Faibussowitsch PetscCall(PetscObjectReference(disc)); 896665f567fSMatthew G. Knepley if (disc) { 897249df284SMatthew G. Knepley PetscClassId id; 898249df284SMatthew G. Knepley 8999566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(disc, &id)); 9001cf84007SMatthew G. Knepley if (id == PETSCFE_CLASSID) { 9019566063dSJacob Faibussowitsch PetscCall(PetscDSSetImplicit(prob, f, PETSC_TRUE)); 9021cf84007SMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 9039566063dSJacob Faibussowitsch PetscCall(PetscDSSetImplicit(prob, f, PETSC_FALSE)); 904a6cbbb48SMatthew G. Knepley } 9059566063dSJacob Faibussowitsch PetscCall(PetscDSSetJetDegree(prob, f, 1)); 906249df284SMatthew G. Knepley } 9072764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9082764a2aaSMatthew G. Knepley } 9092764a2aaSMatthew G. Knepley 910bc4ae4beSMatthew G. Knepley /*@ 9116528b96dSMatthew G. Knepley PetscDSGetWeakForm - Returns the weak form object 9126528b96dSMatthew G. Knepley 9136528b96dSMatthew G. Knepley Not collective 9146528b96dSMatthew G. Knepley 9156528b96dSMatthew G. Knepley Input Parameter: 9166528b96dSMatthew G. Knepley . ds - The PetscDS object 9176528b96dSMatthew G. Knepley 9186528b96dSMatthew G. Knepley Output Parameter: 9196528b96dSMatthew G. Knepley . wf - The weak form object 9206528b96dSMatthew G. Knepley 9216528b96dSMatthew G. Knepley Level: beginner 9226528b96dSMatthew G. Knepley 923db781477SPatrick Sanan .seealso: `PetscDSSetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 9246528b96dSMatthew G. Knepley @*/ 9259371c9d4SSatish Balay PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf) { 9266528b96dSMatthew G. Knepley PetscFunctionBegin; 9276528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 9286528b96dSMatthew G. Knepley PetscValidPointer(wf, 2); 9296528b96dSMatthew G. Knepley *wf = ds->wf; 9306528b96dSMatthew G. Knepley PetscFunctionReturn(0); 9316528b96dSMatthew G. Knepley } 9326528b96dSMatthew G. Knepley 9336528b96dSMatthew G. Knepley /*@ 9346528b96dSMatthew G. Knepley PetscDSSetWeakForm - Sets the weak form object 9356528b96dSMatthew G. Knepley 9366528b96dSMatthew G. Knepley Not collective 9376528b96dSMatthew G. Knepley 9386528b96dSMatthew G. Knepley Input Parameters: 9396528b96dSMatthew G. Knepley + ds - The PetscDS object 9406528b96dSMatthew G. Knepley - wf - The weak form object 9416528b96dSMatthew G. Knepley 9426528b96dSMatthew G. Knepley Level: beginner 9436528b96dSMatthew G. Knepley 944db781477SPatrick Sanan .seealso: `PetscDSGetWeakForm()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 9456528b96dSMatthew G. Knepley @*/ 9469371c9d4SSatish Balay PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf) { 9476528b96dSMatthew G. Knepley PetscFunctionBegin; 9486528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 9496528b96dSMatthew G. Knepley PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2); 9509566063dSJacob Faibussowitsch PetscCall(PetscObjectDereference((PetscObject)ds->wf)); 9516528b96dSMatthew G. Knepley ds->wf = wf; 9529566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)wf)); 9539566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetNumFields(wf, ds->Nf)); 9546528b96dSMatthew G. Knepley PetscFunctionReturn(0); 9556528b96dSMatthew G. Knepley } 9566528b96dSMatthew G. Knepley 9576528b96dSMatthew G. Knepley /*@ 958bc4ae4beSMatthew G. Knepley PetscDSAddDiscretization - Adds a discretization object 959bc4ae4beSMatthew G. Knepley 960bc4ae4beSMatthew G. Knepley Not collective 961bc4ae4beSMatthew G. Knepley 962bc4ae4beSMatthew G. Knepley Input Parameters: 963bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 964bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object 965bc4ae4beSMatthew G. Knepley 966bc4ae4beSMatthew G. Knepley Level: beginner 967bc4ae4beSMatthew G. Knepley 968db781477SPatrick Sanan .seealso: `PetscDSGetDiscretization()`, `PetscDSSetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 969bc4ae4beSMatthew G. Knepley @*/ 9709371c9d4SSatish Balay PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) { 9712764a2aaSMatthew G. Knepley PetscFunctionBegin; 9729566063dSJacob Faibussowitsch PetscCall(PetscDSSetDiscretization(prob, prob->Nf, disc)); 9732764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9742764a2aaSMatthew G. Knepley } 9752764a2aaSMatthew G. Knepley 976249df284SMatthew G. Knepley /*@ 977083401c6SMatthew G. Knepley PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS 978083401c6SMatthew G. Knepley 979083401c6SMatthew G. Knepley Not collective 980083401c6SMatthew G. Knepley 981083401c6SMatthew G. Knepley Input Parameter: 982083401c6SMatthew G. Knepley . prob - The PetscDS object 983083401c6SMatthew G. Knepley 984083401c6SMatthew G. Knepley Output Parameter: 985083401c6SMatthew G. Knepley . q - The quadrature object 986083401c6SMatthew G. Knepley 987083401c6SMatthew G. Knepley Level: intermediate 988083401c6SMatthew G. Knepley 989db781477SPatrick Sanan .seealso: `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 990083401c6SMatthew G. Knepley @*/ 9919371c9d4SSatish Balay PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q) { 992083401c6SMatthew G. Knepley PetscObject obj; 993083401c6SMatthew G. Knepley PetscClassId id; 994083401c6SMatthew G. Knepley 995083401c6SMatthew G. Knepley PetscFunctionBegin; 996083401c6SMatthew G. Knepley *q = NULL; 997083401c6SMatthew G. Knepley if (!prob->Nf) PetscFunctionReturn(0); 9989566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, 0, &obj)); 9999566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 10009566063dSJacob Faibussowitsch if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetQuadrature((PetscFE)obj, q)); 10019566063dSJacob Faibussowitsch else if (id == PETSCFV_CLASSID) PetscCall(PetscFVGetQuadrature((PetscFV)obj, q)); 100298921bdaSJacob Faibussowitsch else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 1003083401c6SMatthew G. Knepley PetscFunctionReturn(0); 1004083401c6SMatthew G. Knepley } 1005083401c6SMatthew G. Knepley 1006083401c6SMatthew G. Knepley /*@ 1007249df284SMatthew G. Knepley PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX 1008249df284SMatthew G. Knepley 1009249df284SMatthew G. Knepley Not collective 1010249df284SMatthew G. Knepley 1011249df284SMatthew G. Knepley Input Parameters: 1012249df284SMatthew G. Knepley + prob - The PetscDS object 1013249df284SMatthew G. Knepley - f - The field number 1014249df284SMatthew G. Knepley 1015249df284SMatthew G. Knepley Output Parameter: 1016249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field 1017249df284SMatthew G. Knepley 1018249df284SMatthew G. Knepley Level: developer 1019249df284SMatthew G. Knepley 1020db781477SPatrick Sanan .seealso: `PetscDSSetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1021249df284SMatthew G. Knepley @*/ 10229371c9d4SSatish Balay PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit) { 1023249df284SMatthew G. Knepley PetscFunctionBegin; 1024249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1025dadcf809SJacob Faibussowitsch PetscValidBoolPointer(implicit, 3); 102663a3b9bcSJacob 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); 1027249df284SMatthew G. Knepley *implicit = prob->implicit[f]; 1028249df284SMatthew G. Knepley PetscFunctionReturn(0); 1029249df284SMatthew G. Knepley } 1030249df284SMatthew G. Knepley 1031249df284SMatthew G. Knepley /*@ 1032249df284SMatthew G. Knepley PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX 1033249df284SMatthew G. Knepley 1034249df284SMatthew G. Knepley Not collective 1035249df284SMatthew G. Knepley 1036249df284SMatthew G. Knepley Input Parameters: 1037249df284SMatthew G. Knepley + prob - The PetscDS object 1038249df284SMatthew G. Knepley . f - The field number 1039249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field 1040249df284SMatthew G. Knepley 1041249df284SMatthew G. Knepley Level: developer 1042249df284SMatthew G. Knepley 1043db781477SPatrick Sanan .seealso: `PetscDSGetImplicit()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1044249df284SMatthew G. Knepley @*/ 10459371c9d4SSatish Balay PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit) { 1046249df284SMatthew G. Knepley PetscFunctionBegin; 1047249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 104863a3b9bcSJacob 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); 1049249df284SMatthew G. Knepley prob->implicit[f] = implicit; 1050249df284SMatthew G. Knepley PetscFunctionReturn(0); 1051249df284SMatthew G. Knepley } 1052249df284SMatthew G. Knepley 1053f9244615SMatthew G. Knepley /*@ 1054f9244615SMatthew G. Knepley PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate. 1055f9244615SMatthew G. Knepley 1056f9244615SMatthew G. Knepley Not collective 1057f9244615SMatthew G. Knepley 1058f9244615SMatthew G. Knepley Input Parameters: 1059f9244615SMatthew G. Knepley + ds - The PetscDS object 1060f9244615SMatthew G. Knepley - f - The field number 1061f9244615SMatthew G. Knepley 1062f9244615SMatthew G. Knepley Output Parameter: 1063f9244615SMatthew G. Knepley . k - The highest derivative we need to tabulate 1064f9244615SMatthew G. Knepley 1065f9244615SMatthew G. Knepley Level: developer 1066f9244615SMatthew G. Knepley 1067db781477SPatrick Sanan .seealso: `PetscDSSetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1068f9244615SMatthew G. Knepley @*/ 10699371c9d4SSatish Balay PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k) { 1070f9244615SMatthew G. Knepley PetscFunctionBegin; 1071f9244615SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1072dadcf809SJacob Faibussowitsch PetscValidIntPointer(k, 3); 107363a3b9bcSJacob 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); 1074f9244615SMatthew G. Knepley *k = ds->jetDegree[f]; 1075f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1076f9244615SMatthew G. Knepley } 1077f9244615SMatthew G. Knepley 1078f9244615SMatthew G. Knepley /*@ 1079f9244615SMatthew G. Knepley PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate. 1080f9244615SMatthew G. Knepley 1081f9244615SMatthew G. Knepley Not collective 1082f9244615SMatthew G. Knepley 1083f9244615SMatthew G. Knepley Input Parameters: 1084f9244615SMatthew G. Knepley + ds - The PetscDS object 1085f9244615SMatthew G. Knepley . f - The field number 1086f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate 1087f9244615SMatthew G. Knepley 1088f9244615SMatthew G. Knepley Level: developer 1089f9244615SMatthew G. Knepley 1090db781477SPatrick Sanan .seealso: `PetscDSGetJetDegree()`, `PetscDSSetDiscretization()`, `PetscDSAddDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 1091f9244615SMatthew G. Knepley @*/ 10929371c9d4SSatish Balay PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k) { 1093f9244615SMatthew G. Knepley PetscFunctionBegin; 1094f9244615SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 109563a3b9bcSJacob 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); 1096f9244615SMatthew G. Knepley ds->jetDegree[f] = k; 1097f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1098f9244615SMatthew G. Knepley } 1099f9244615SMatthew G. Knepley 11009371c9d4SSatish Balay 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[])) { 11016528b96dSMatthew G. Knepley PetscPointFunc *tmp; 11026528b96dSMatthew G. Knepley PetscInt n; 11036528b96dSMatthew G. Knepley 11042764a2aaSMatthew G. Knepley PetscFunctionBegin; 11056528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 11066528b96dSMatthew G. Knepley PetscValidPointer(obj, 3); 110763a3b9bcSJacob 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); 11089566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetObjective(ds->wf, NULL, 0, f, 0, &n, &tmp)); 11096528b96dSMatthew G. Knepley *obj = tmp ? tmp[0] : NULL; 11102764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11112764a2aaSMatthew G. Knepley } 11122764a2aaSMatthew G. Knepley 11139371c9d4SSatish Balay 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[])) { 11142764a2aaSMatthew G. Knepley PetscFunctionBegin; 11156528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 11166528b96dSMatthew G. Knepley if (obj) PetscValidFunction(obj, 3); 111763a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 11189566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, 0, obj)); 11192764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11202764a2aaSMatthew G. Knepley } 11212764a2aaSMatthew G. Knepley 1122194d53e6SMatthew G. Knepley /*@C 1123194d53e6SMatthew G. Knepley PetscDSGetResidual - Get the pointwise residual function for a given test field 1124194d53e6SMatthew G. Knepley 1125194d53e6SMatthew G. Knepley Not collective 1126194d53e6SMatthew G. Knepley 1127194d53e6SMatthew G. Knepley Input Parameters: 11286528b96dSMatthew G. Knepley + ds - The PetscDS 1129194d53e6SMatthew G. Knepley - f - The test field number 1130194d53e6SMatthew G. Knepley 1131194d53e6SMatthew G. Knepley Output Parameters: 1132194d53e6SMatthew G. Knepley + f0 - integrand for the test function term 1133194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1134194d53e6SMatthew G. Knepley 1135194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1136194d53e6SMatthew G. Knepley 1137194d53e6SMatthew G. Knepley \int_\Omega \phi f_0(u, u_t, \nabla u, x, t) + \nabla\phi \cdot {\vec f}_1(u, u_t, \nabla u, x, t) 1138194d53e6SMatthew G. Knepley 1139194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1140194d53e6SMatthew G. Knepley 114130b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1142194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1143194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 114430b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1145194d53e6SMatthew G. Knepley 1146194d53e6SMatthew G. Knepley + dim - the spatial dimension 1147194d53e6SMatthew G. Knepley . Nf - the number of fields 1148194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1149194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1150194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1151194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1152194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1153194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1154194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1155194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1156194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1157194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1158194d53e6SMatthew G. Knepley . t - current time 1159194d53e6SMatthew G. Knepley . x - coordinates of the current point 116097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 116197b6e6e8SMatthew G. Knepley . constants - constant parameters 1162194d53e6SMatthew G. Knepley - f0 - output values at the current point 1163194d53e6SMatthew G. Knepley 1164194d53e6SMatthew G. Knepley Level: intermediate 1165194d53e6SMatthew G. Knepley 1166db781477SPatrick Sanan .seealso: `PetscDSSetResidual()` 1167194d53e6SMatthew G. Knepley @*/ 11689371c9d4SSatish Balay 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[])) { 11696528b96dSMatthew G. Knepley PetscPointFunc *tmp0, *tmp1; 11706528b96dSMatthew G. Knepley PetscInt n0, n1; 11716528b96dSMatthew G. Knepley 11722764a2aaSMatthew G. Knepley PetscFunctionBegin; 11736528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 117463a3b9bcSJacob 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); 11759566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1)); 11766528b96dSMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 11776528b96dSMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 11782764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11792764a2aaSMatthew G. Knepley } 11802764a2aaSMatthew G. Knepley 1181194d53e6SMatthew G. Knepley /*@C 1182194d53e6SMatthew G. Knepley PetscDSSetResidual - Set the pointwise residual function for a given test field 1183194d53e6SMatthew G. Knepley 1184194d53e6SMatthew G. Knepley Not collective 1185194d53e6SMatthew G. Knepley 1186194d53e6SMatthew G. Knepley Input Parameters: 11876528b96dSMatthew G. Knepley + ds - The PetscDS 1188194d53e6SMatthew G. Knepley . f - The test field number 1189194d53e6SMatthew G. Knepley . f0 - integrand for the test function term 1190194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1191194d53e6SMatthew G. Knepley 1192194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1193194d53e6SMatthew G. Knepley 1194194d53e6SMatthew G. Knepley \int_\Omega \phi f_0(u, u_t, \nabla u, x, t) + \nabla\phi \cdot {\vec f}_1(u, u_t, \nabla u, x, t) 1195194d53e6SMatthew G. Knepley 1196194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1197194d53e6SMatthew G. Knepley 119830b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1199194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1200194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 120130b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1202194d53e6SMatthew G. Knepley 1203194d53e6SMatthew G. Knepley + dim - the spatial dimension 1204194d53e6SMatthew G. Knepley . Nf - the number of fields 1205194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1206194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1207194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1208194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1209194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1210194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1211194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1212194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1213194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1214194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1215194d53e6SMatthew G. Knepley . t - current time 1216194d53e6SMatthew G. Knepley . x - coordinates of the current point 121797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 121897b6e6e8SMatthew G. Knepley . constants - constant parameters 1219194d53e6SMatthew G. Knepley - f0 - output values at the current point 1220194d53e6SMatthew G. Knepley 1221194d53e6SMatthew G. Knepley Level: intermediate 1222194d53e6SMatthew G. Knepley 1223db781477SPatrick Sanan .seealso: `PetscDSGetResidual()` 1224194d53e6SMatthew G. Knepley @*/ 12259371c9d4SSatish Balay 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[])) { 12262764a2aaSMatthew G. Knepley PetscFunctionBegin; 12276528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1228f866a1d0SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1229f866a1d0SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 123063a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 12319566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1)); 12322764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 12332764a2aaSMatthew G. Knepley } 12342764a2aaSMatthew G. Knepley 12353e75805dSMatthew G. Knepley /*@C 1236cb36c0f9SMatthew G. Knepley PetscDSGetRHSResidual - Get the pointwise RHS residual function for explicit timestepping for a given test field 1237cb36c0f9SMatthew G. Knepley 1238cb36c0f9SMatthew G. Knepley Not collective 1239cb36c0f9SMatthew G. Knepley 1240cb36c0f9SMatthew G. Knepley Input Parameters: 1241cb36c0f9SMatthew G. Knepley + ds - The PetscDS 1242cb36c0f9SMatthew G. Knepley - f - The test field number 1243cb36c0f9SMatthew G. Knepley 1244cb36c0f9SMatthew G. Knepley Output Parameters: 1245cb36c0f9SMatthew G. Knepley + f0 - integrand for the test function term 1246cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term 1247cb36c0f9SMatthew G. Knepley 1248cb36c0f9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1249cb36c0f9SMatthew G. Knepley 1250cb36c0f9SMatthew G. Knepley \int_\Omega \phi f_0(u, u_t, \nabla u, x, t) + \nabla\phi \cdot {\vec f}_1(u, u_t, \nabla u, x, t) 1251cb36c0f9SMatthew G. Knepley 1252cb36c0f9SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1253cb36c0f9SMatthew G. Knepley 1254cb36c0f9SMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1255cb36c0f9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1256cb36c0f9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1257cb36c0f9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1258cb36c0f9SMatthew G. Knepley 1259cb36c0f9SMatthew G. Knepley + dim - the spatial dimension 1260cb36c0f9SMatthew G. Knepley . Nf - the number of fields 1261cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1262cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1263cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point 1264cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1265cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1266cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1267cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1268cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1269cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1270cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1271cb36c0f9SMatthew G. Knepley . t - current time 1272cb36c0f9SMatthew G. Knepley . x - coordinates of the current point 1273cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters 1274cb36c0f9SMatthew G. Knepley . constants - constant parameters 1275cb36c0f9SMatthew G. Knepley - f0 - output values at the current point 1276cb36c0f9SMatthew G. Knepley 1277cb36c0f9SMatthew G. Knepley Level: intermediate 1278cb36c0f9SMatthew G. Knepley 1279db781477SPatrick Sanan .seealso: `PetscDSSetRHSResidual()` 1280cb36c0f9SMatthew G. Knepley @*/ 12819371c9d4SSatish Balay 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[])) { 1282cb36c0f9SMatthew G. Knepley PetscPointFunc *tmp0, *tmp1; 1283cb36c0f9SMatthew G. Knepley PetscInt n0, n1; 1284cb36c0f9SMatthew G. Knepley 1285cb36c0f9SMatthew G. Knepley PetscFunctionBegin; 1286cb36c0f9SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 128763a3b9bcSJacob 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); 12889566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 100, &n0, &tmp0, &n1, &tmp1)); 1289cb36c0f9SMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 1290cb36c0f9SMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 1291cb36c0f9SMatthew G. Knepley PetscFunctionReturn(0); 1292cb36c0f9SMatthew G. Knepley } 1293cb36c0f9SMatthew G. Knepley 1294cb36c0f9SMatthew G. Knepley /*@C 1295cb36c0f9SMatthew G. Knepley PetscDSSetRHSResidual - Set the pointwise residual function for explicit timestepping for a given test field 1296cb36c0f9SMatthew G. Knepley 1297cb36c0f9SMatthew G. Knepley Not collective 1298cb36c0f9SMatthew G. Knepley 1299cb36c0f9SMatthew G. Knepley Input Parameters: 1300cb36c0f9SMatthew G. Knepley + ds - The PetscDS 1301cb36c0f9SMatthew G. Knepley . f - The test field number 1302cb36c0f9SMatthew G. Knepley . f0 - integrand for the test function term 1303cb36c0f9SMatthew G. Knepley - f1 - integrand for the test function gradient term 1304cb36c0f9SMatthew G. Knepley 1305cb36c0f9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1306cb36c0f9SMatthew G. Knepley 1307cb36c0f9SMatthew G. Knepley \int_\Omega \phi f_0(u, u_t, \nabla u, x, t) + \nabla\phi \cdot {\vec f}_1(u, u_t, \nabla u, x, t) 1308cb36c0f9SMatthew G. Knepley 1309cb36c0f9SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1310cb36c0f9SMatthew G. Knepley 1311cb36c0f9SMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1312cb36c0f9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1313cb36c0f9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1314cb36c0f9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1315cb36c0f9SMatthew G. Knepley 1316cb36c0f9SMatthew G. Knepley + dim - the spatial dimension 1317cb36c0f9SMatthew G. Knepley . Nf - the number of fields 1318cb36c0f9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1319cb36c0f9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1320cb36c0f9SMatthew G. Knepley . u - each field evaluated at the current point 1321cb36c0f9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1322cb36c0f9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1323cb36c0f9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1324cb36c0f9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1325cb36c0f9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1326cb36c0f9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1327cb36c0f9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1328cb36c0f9SMatthew G. Knepley . t - current time 1329cb36c0f9SMatthew G. Knepley . x - coordinates of the current point 1330cb36c0f9SMatthew G. Knepley . numConstants - number of constant parameters 1331cb36c0f9SMatthew G. Knepley . constants - constant parameters 1332cb36c0f9SMatthew G. Knepley - f0 - output values at the current point 1333cb36c0f9SMatthew G. Knepley 1334cb36c0f9SMatthew G. Knepley Level: intermediate 1335cb36c0f9SMatthew G. Knepley 1336db781477SPatrick Sanan .seealso: `PetscDSGetResidual()` 1337cb36c0f9SMatthew G. Knepley @*/ 13389371c9d4SSatish Balay 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[])) { 1339cb36c0f9SMatthew G. Knepley PetscFunctionBegin; 1340cb36c0f9SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1341cb36c0f9SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1342cb36c0f9SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 134363a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 13449566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 100, 0, f0, 0, f1)); 1345cb36c0f9SMatthew G. Knepley PetscFunctionReturn(0); 1346cb36c0f9SMatthew G. Knepley } 1347cb36c0f9SMatthew G. Knepley 1348cb36c0f9SMatthew G. Knepley /*@C 13493e75805dSMatthew G. Knepley PetscDSHasJacobian - Signals that Jacobian functions have been set 13503e75805dSMatthew G. Knepley 13513e75805dSMatthew G. Knepley Not collective 13523e75805dSMatthew G. Knepley 13533e75805dSMatthew G. Knepley Input Parameter: 13543e75805dSMatthew G. Knepley . prob - The PetscDS 13553e75805dSMatthew G. Knepley 13563e75805dSMatthew G. Knepley Output Parameter: 13573e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set 13583e75805dSMatthew G. Knepley 13593e75805dSMatthew G. Knepley Level: intermediate 13603e75805dSMatthew G. Knepley 1361db781477SPatrick Sanan .seealso: `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()` 13623e75805dSMatthew G. Knepley @*/ 13639371c9d4SSatish Balay PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac) { 13643e75805dSMatthew G. Knepley PetscFunctionBegin; 13656528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 13669566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasJacobian(ds->wf, hasJac)); 13673e75805dSMatthew G. Knepley PetscFunctionReturn(0); 13683e75805dSMatthew G. Knepley } 13693e75805dSMatthew G. Knepley 1370194d53e6SMatthew G. Knepley /*@C 1371194d53e6SMatthew G. Knepley PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field 1372194d53e6SMatthew G. Knepley 1373194d53e6SMatthew G. Knepley Not collective 1374194d53e6SMatthew G. Knepley 1375194d53e6SMatthew G. Knepley Input Parameters: 13766528b96dSMatthew G. Knepley + ds - The PetscDS 1377194d53e6SMatthew G. Knepley . f - The test field number 1378194d53e6SMatthew G. Knepley - g - The field number 1379194d53e6SMatthew G. Knepley 1380194d53e6SMatthew G. Knepley Output Parameters: 1381194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1382194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1383194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1384194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1385194d53e6SMatthew G. Knepley 1386194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1387194d53e6SMatthew G. Knepley 1388194d53e6SMatthew G. Knepley \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi 1389194d53e6SMatthew G. Knepley 1390194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1391194d53e6SMatthew G. Knepley 139230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1393194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1394194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 139530b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1396194d53e6SMatthew G. Knepley 1397194d53e6SMatthew G. Knepley + dim - the spatial dimension 1398194d53e6SMatthew G. Knepley . Nf - the number of fields 1399194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1400194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1401194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1402194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1403194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1404194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1405194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1406194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1407194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1408194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1409194d53e6SMatthew G. Knepley . t - current time 14102aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1411194d53e6SMatthew G. Knepley . x - coordinates of the current point 141297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 141397b6e6e8SMatthew G. Knepley . constants - constant parameters 1414194d53e6SMatthew G. Knepley - g0 - output values at the current point 1415194d53e6SMatthew G. Knepley 1416194d53e6SMatthew G. Knepley Level: intermediate 1417194d53e6SMatthew G. Knepley 1418db781477SPatrick Sanan .seealso: `PetscDSSetJacobian()` 1419194d53e6SMatthew G. Knepley @*/ 14209371c9d4SSatish Balay 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[])) { 14216528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 14226528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 14236528b96dSMatthew G. Knepley 14242764a2aaSMatthew G. Knepley PetscFunctionBegin; 14256528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 142663a3b9bcSJacob 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); 142763a3b9bcSJacob 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); 14289566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 14296528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 14306528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 14316528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 14326528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 14332764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 14342764a2aaSMatthew G. Knepley } 14352764a2aaSMatthew G. Knepley 1436194d53e6SMatthew G. Knepley /*@C 1437194d53e6SMatthew G. Knepley PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields 1438194d53e6SMatthew G. Knepley 1439194d53e6SMatthew G. Knepley Not collective 1440194d53e6SMatthew G. Knepley 1441194d53e6SMatthew G. Knepley Input Parameters: 14426528b96dSMatthew G. Knepley + ds - The PetscDS 1443194d53e6SMatthew G. Knepley . f - The test field number 1444194d53e6SMatthew G. Knepley . g - The field number 1445194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1446194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1447194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1448194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1449194d53e6SMatthew G. Knepley 1450194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1451194d53e6SMatthew G. Knepley 1452194d53e6SMatthew G. Knepley \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi 1453194d53e6SMatthew G. Knepley 1454194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1455194d53e6SMatthew G. Knepley 145630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1457194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1458194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 145930b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1460194d53e6SMatthew G. Knepley 1461194d53e6SMatthew G. Knepley + dim - the spatial dimension 1462194d53e6SMatthew G. Knepley . Nf - the number of fields 1463194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1464194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1465194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1466194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1467194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1468194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1469194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1470194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1471194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1472194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1473194d53e6SMatthew G. Knepley . t - current time 14742aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1475194d53e6SMatthew G. Knepley . x - coordinates of the current point 147697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 147797b6e6e8SMatthew G. Knepley . constants - constant parameters 1478194d53e6SMatthew G. Knepley - g0 - output values at the current point 1479194d53e6SMatthew G. Knepley 1480194d53e6SMatthew G. Knepley Level: intermediate 1481194d53e6SMatthew G. Knepley 1482db781477SPatrick Sanan .seealso: `PetscDSGetJacobian()` 1483194d53e6SMatthew G. Knepley @*/ 14849371c9d4SSatish Balay 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[])) { 14852764a2aaSMatthew G. Knepley PetscFunctionBegin; 14866528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14872764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 14882764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 14892764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 14902764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 149163a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 149263a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 14939566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 14942764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 14952764a2aaSMatthew G. Knepley } 14962764a2aaSMatthew G. Knepley 1497475e0ac9SMatthew G. Knepley /*@C 149855c1f793SMatthew G. Knepley PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner 149955c1f793SMatthew G. Knepley 150055c1f793SMatthew G. Knepley Not collective 150155c1f793SMatthew G. Knepley 150255c1f793SMatthew G. Knepley Input Parameters: 150355c1f793SMatthew G. Knepley + prob - The PetscDS 150455c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner 150555c1f793SMatthew G. Knepley 150655c1f793SMatthew G. Knepley Level: intermediate 150755c1f793SMatthew G. Knepley 1508db781477SPatrick Sanan .seealso: `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()` 150955c1f793SMatthew G. Knepley @*/ 15109371c9d4SSatish Balay PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre) { 151155c1f793SMatthew G. Knepley PetscFunctionBegin; 151255c1f793SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 151355c1f793SMatthew G. Knepley prob->useJacPre = useJacPre; 151455c1f793SMatthew G. Knepley PetscFunctionReturn(0); 151555c1f793SMatthew G. Knepley } 151655c1f793SMatthew G. Knepley 151755c1f793SMatthew G. Knepley /*@C 1518475e0ac9SMatthew G. Knepley PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set 1519475e0ac9SMatthew G. Knepley 1520475e0ac9SMatthew G. Knepley Not collective 1521475e0ac9SMatthew G. Knepley 1522475e0ac9SMatthew G. Knepley Input Parameter: 1523475e0ac9SMatthew G. Knepley . prob - The PetscDS 1524475e0ac9SMatthew G. Knepley 1525475e0ac9SMatthew G. Knepley Output Parameter: 1526475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set 1527475e0ac9SMatthew G. Knepley 1528475e0ac9SMatthew G. Knepley Level: intermediate 1529475e0ac9SMatthew G. Knepley 1530db781477SPatrick Sanan .seealso: `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()` 1531475e0ac9SMatthew G. Knepley @*/ 15329371c9d4SSatish Balay PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre) { 1533475e0ac9SMatthew G. Knepley PetscFunctionBegin; 15346528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1535475e0ac9SMatthew G. Knepley *hasJacPre = PETSC_FALSE; 15366528b96dSMatthew G. Knepley if (!ds->useJacPre) PetscFunctionReturn(0); 15379566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre)); 1538475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1539475e0ac9SMatthew G. Knepley } 1540475e0ac9SMatthew G. Knepley 1541475e0ac9SMatthew G. Knepley /*@C 1542475e0ac9SMatthew G. Knepley PetscDSGetJacobianPreconditioner - Get the pointwise Jacobian preconditioner function for given test and basis field. If this is missing, the system matrix is used to build the preconditioner. 1543475e0ac9SMatthew G. Knepley 1544475e0ac9SMatthew G. Knepley Not collective 1545475e0ac9SMatthew G. Knepley 1546475e0ac9SMatthew G. Knepley Input Parameters: 15476528b96dSMatthew G. Knepley + ds - The PetscDS 1548475e0ac9SMatthew G. Knepley . f - The test field number 1549475e0ac9SMatthew G. Knepley - g - The field number 1550475e0ac9SMatthew G. Knepley 1551475e0ac9SMatthew G. Knepley Output Parameters: 1552475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term 1553475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1554475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1555475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1556475e0ac9SMatthew G. Knepley 1557475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1558475e0ac9SMatthew G. Knepley 1559475e0ac9SMatthew G. Knepley \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi 1560475e0ac9SMatthew G. Knepley 1561475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1562475e0ac9SMatthew G. Knepley 1563475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1564475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1565475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1566475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1567475e0ac9SMatthew G. Knepley 1568475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1569475e0ac9SMatthew G. Knepley . Nf - the number of fields 1570475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1571475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1572475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1573475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1574475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1575475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1576475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1577475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1578475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1579475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1580475e0ac9SMatthew G. Knepley . t - current time 1581475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1582475e0ac9SMatthew G. Knepley . x - coordinates of the current point 158397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 158497b6e6e8SMatthew G. Knepley . constants - constant parameters 1585475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1586475e0ac9SMatthew G. Knepley 1587475e0ac9SMatthew G. Knepley Level: intermediate 1588475e0ac9SMatthew G. Knepley 1589db781477SPatrick Sanan .seealso: `PetscDSSetJacobianPreconditioner()`, `PetscDSGetJacobian()` 1590475e0ac9SMatthew G. Knepley @*/ 15919371c9d4SSatish Balay 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[])) { 15926528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 15936528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 15946528b96dSMatthew G. Knepley 1595475e0ac9SMatthew G. Knepley PetscFunctionBegin; 15966528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 159763a3b9bcSJacob 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); 159863a3b9bcSJacob 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); 15999566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 16006528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 16016528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 16026528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 16036528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 1604475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1605475e0ac9SMatthew G. Knepley } 1606475e0ac9SMatthew G. Knepley 1607475e0ac9SMatthew G. Knepley /*@C 1608475e0ac9SMatthew G. Knepley PetscDSSetJacobianPreconditioner - Set the pointwise Jacobian preconditioner function for given test and basis fields. If this is missing, the system matrix is used to build the preconditioner. 1609475e0ac9SMatthew G. Knepley 1610475e0ac9SMatthew G. Knepley Not collective 1611475e0ac9SMatthew G. Knepley 1612475e0ac9SMatthew G. Knepley Input Parameters: 16136528b96dSMatthew G. Knepley + ds - The PetscDS 1614475e0ac9SMatthew G. Knepley . f - The test field number 1615475e0ac9SMatthew G. Knepley . g - The field number 1616475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term 1617475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1618475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1619475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1620475e0ac9SMatthew G. Knepley 1621475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1622475e0ac9SMatthew G. Knepley 1623475e0ac9SMatthew G. Knepley \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi 1624475e0ac9SMatthew G. Knepley 1625475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1626475e0ac9SMatthew G. Knepley 1627475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1628475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1629475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1630475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1631475e0ac9SMatthew G. Knepley 1632475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1633475e0ac9SMatthew G. Knepley . Nf - the number of fields 1634475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1635475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1636475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1637475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1638475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1639475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1640475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1641475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1642475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1643475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1644475e0ac9SMatthew G. Knepley . t - current time 1645475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1646475e0ac9SMatthew G. Knepley . x - coordinates of the current point 164797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 164897b6e6e8SMatthew G. Knepley . constants - constant parameters 1649475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1650475e0ac9SMatthew G. Knepley 1651475e0ac9SMatthew G. Knepley Level: intermediate 1652475e0ac9SMatthew G. Knepley 1653db781477SPatrick Sanan .seealso: `PetscDSGetJacobianPreconditioner()`, `PetscDSSetJacobian()` 1654475e0ac9SMatthew G. Knepley @*/ 16559371c9d4SSatish Balay 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[])) { 1656475e0ac9SMatthew G. Knepley PetscFunctionBegin; 16576528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1658475e0ac9SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1659475e0ac9SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1660475e0ac9SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1661475e0ac9SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 166263a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 166363a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 16649566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 1665475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1666475e0ac9SMatthew G. Knepley } 1667475e0ac9SMatthew G. Knepley 1668b7e05686SMatthew G. Knepley /*@C 1669b7e05686SMatthew G. Knepley PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set 1670b7e05686SMatthew G. Knepley 1671b7e05686SMatthew G. Knepley Not collective 1672b7e05686SMatthew G. Knepley 1673b7e05686SMatthew G. Knepley Input Parameter: 16746528b96dSMatthew G. Knepley . ds - The PetscDS 1675b7e05686SMatthew G. Knepley 1676b7e05686SMatthew G. Knepley Output Parameter: 1677b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set 1678b7e05686SMatthew G. Knepley 1679b7e05686SMatthew G. Knepley Level: intermediate 1680b7e05686SMatthew G. Knepley 1681db781477SPatrick Sanan .seealso: `PetscDSGetDynamicJacobian()`, `PetscDSSetDynamicJacobian()`, `PetscDSGetJacobian()` 1682b7e05686SMatthew G. Knepley @*/ 16839371c9d4SSatish Balay PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac) { 1684b7e05686SMatthew G. Knepley PetscFunctionBegin; 16856528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 16869566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac)); 1687b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1688b7e05686SMatthew G. Knepley } 1689b7e05686SMatthew G. Knepley 1690b7e05686SMatthew G. Knepley /*@C 1691b7e05686SMatthew G. Knepley PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field 1692b7e05686SMatthew G. Knepley 1693b7e05686SMatthew G. Knepley Not collective 1694b7e05686SMatthew G. Knepley 1695b7e05686SMatthew G. Knepley Input Parameters: 16966528b96dSMatthew G. Knepley + ds - The PetscDS 1697b7e05686SMatthew G. Knepley . f - The test field number 1698b7e05686SMatthew G. Knepley - g - The field number 1699b7e05686SMatthew G. Knepley 1700b7e05686SMatthew G. Knepley Output Parameters: 1701b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term 1702b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1703b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1704b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1705b7e05686SMatthew G. Knepley 1706b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1707b7e05686SMatthew G. Knepley 1708b7e05686SMatthew G. Knepley \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi 1709b7e05686SMatthew G. Knepley 1710b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1711b7e05686SMatthew G. Knepley 1712b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1713b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1714b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1715b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1716b7e05686SMatthew G. Knepley 1717b7e05686SMatthew G. Knepley + dim - the spatial dimension 1718b7e05686SMatthew G. Knepley . Nf - the number of fields 1719b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1720b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1721b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1722b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1723b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1724b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1725b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1726b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1727b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1728b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1729b7e05686SMatthew G. Knepley . t - current time 1730b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1731b7e05686SMatthew G. Knepley . x - coordinates of the current point 173297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 173397b6e6e8SMatthew G. Knepley . constants - constant parameters 1734b7e05686SMatthew G. Knepley - g0 - output values at the current point 1735b7e05686SMatthew G. Knepley 1736b7e05686SMatthew G. Knepley Level: intermediate 1737b7e05686SMatthew G. Knepley 1738db781477SPatrick Sanan .seealso: `PetscDSSetJacobian()` 1739b7e05686SMatthew G. Knepley @*/ 17409371c9d4SSatish Balay 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[])) { 17416528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 17426528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 17436528b96dSMatthew G. Knepley 1744b7e05686SMatthew G. Knepley PetscFunctionBegin; 17456528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 174663a3b9bcSJacob 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); 174763a3b9bcSJacob 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); 17489566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 17496528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 17506528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 17516528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 17526528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 1753b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1754b7e05686SMatthew G. Knepley } 1755b7e05686SMatthew G. Knepley 1756b7e05686SMatthew G. Knepley /*@C 1757b7e05686SMatthew G. Knepley PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields 1758b7e05686SMatthew G. Knepley 1759b7e05686SMatthew G. Knepley Not collective 1760b7e05686SMatthew G. Knepley 1761b7e05686SMatthew G. Knepley Input Parameters: 17626528b96dSMatthew G. Knepley + ds - The PetscDS 1763b7e05686SMatthew G. Knepley . f - The test field number 1764b7e05686SMatthew G. Knepley . g - The field number 1765b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term 1766b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1767b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1768b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1769b7e05686SMatthew G. Knepley 1770b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1771b7e05686SMatthew G. Knepley 1772b7e05686SMatthew G. Knepley \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi 1773b7e05686SMatthew G. Knepley 1774b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1775b7e05686SMatthew G. Knepley 1776b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1777b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1778b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1779b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1780b7e05686SMatthew G. Knepley 1781b7e05686SMatthew G. Knepley + dim - the spatial dimension 1782b7e05686SMatthew G. Knepley . Nf - the number of fields 1783b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1784b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1785b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1786b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1787b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1788b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1789b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1790b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1791b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1792b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1793b7e05686SMatthew G. Knepley . t - current time 1794b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1795b7e05686SMatthew G. Knepley . x - coordinates of the current point 179697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 179797b6e6e8SMatthew G. Knepley . constants - constant parameters 1798b7e05686SMatthew G. Knepley - g0 - output values at the current point 1799b7e05686SMatthew G. Knepley 1800b7e05686SMatthew G. Knepley Level: intermediate 1801b7e05686SMatthew G. Knepley 1802db781477SPatrick Sanan .seealso: `PetscDSGetJacobian()` 1803b7e05686SMatthew G. Knepley @*/ 18049371c9d4SSatish Balay 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[])) { 1805b7e05686SMatthew G. Knepley PetscFunctionBegin; 18066528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1807b7e05686SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1808b7e05686SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1809b7e05686SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1810b7e05686SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 181163a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 181263a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 18139566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 1814b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1815b7e05686SMatthew G. Knepley } 1816b7e05686SMatthew G. Knepley 18170c2f2876SMatthew G. Knepley /*@C 18180c2f2876SMatthew G. Knepley PetscDSGetRiemannSolver - Returns the Riemann solver for the given field 18190c2f2876SMatthew G. Knepley 18200c2f2876SMatthew G. Knepley Not collective 18210c2f2876SMatthew G. Knepley 18224165533cSJose E. Roman Input Parameters: 18236528b96dSMatthew G. Knepley + ds - The PetscDS object 18240c2f2876SMatthew G. Knepley - f - The field number 18250c2f2876SMatthew G. Knepley 18264165533cSJose E. Roman Output Parameter: 18270c2f2876SMatthew G. Knepley . r - Riemann solver 18280c2f2876SMatthew G. Knepley 18290c2f2876SMatthew G. Knepley Calling sequence for r: 18300c2f2876SMatthew G. Knepley 18315db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 18320c2f2876SMatthew G. Knepley 18335db36cf9SMatthew G. Knepley + dim - The spatial dimension 18345db36cf9SMatthew G. Knepley . Nf - The number of fields 18355db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 18360c2f2876SMatthew G. Knepley . n - The normal vector to the interface 18370c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 18380c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 18390c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 184097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 184197b6e6e8SMatthew G. Knepley . constants - constant parameters 18420c2f2876SMatthew G. Knepley - ctx - optional user context 18430c2f2876SMatthew G. Knepley 18440c2f2876SMatthew G. Knepley Level: intermediate 18450c2f2876SMatthew G. Knepley 1846db781477SPatrick Sanan .seealso: `PetscDSSetRiemannSolver()` 18470c2f2876SMatthew G. Knepley @*/ 18489371c9d4SSatish Balay 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)) { 18496528b96dSMatthew G. Knepley PetscRiemannFunc *tmp; 18506528b96dSMatthew G. Knepley PetscInt n; 18516528b96dSMatthew G. Knepley 18520c2f2876SMatthew G. Knepley PetscFunctionBegin; 18536528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 18540c2f2876SMatthew G. Knepley PetscValidPointer(r, 3); 185563a3b9bcSJacob 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); 18569566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, 0, &n, &tmp)); 18576528b96dSMatthew G. Knepley *r = tmp ? tmp[0] : NULL; 18580c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18590c2f2876SMatthew G. Knepley } 18600c2f2876SMatthew G. Knepley 18610c2f2876SMatthew G. Knepley /*@C 18620c2f2876SMatthew G. Knepley PetscDSSetRiemannSolver - Sets the Riemann solver for the given field 18630c2f2876SMatthew G. Knepley 18640c2f2876SMatthew G. Knepley Not collective 18650c2f2876SMatthew G. Knepley 18664165533cSJose E. Roman Input Parameters: 18676528b96dSMatthew G. Knepley + ds - The PetscDS object 18680c2f2876SMatthew G. Knepley . f - The field number 18690c2f2876SMatthew G. Knepley - r - Riemann solver 18700c2f2876SMatthew G. Knepley 18710c2f2876SMatthew G. Knepley Calling sequence for r: 18720c2f2876SMatthew G. Knepley 18735db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 18740c2f2876SMatthew G. Knepley 18755db36cf9SMatthew G. Knepley + dim - The spatial dimension 18765db36cf9SMatthew G. Knepley . Nf - The number of fields 18775db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 18780c2f2876SMatthew G. Knepley . n - The normal vector to the interface 18790c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 18800c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 18810c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 188297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 188397b6e6e8SMatthew G. Knepley . constants - constant parameters 18840c2f2876SMatthew G. Knepley - ctx - optional user context 18850c2f2876SMatthew G. Knepley 18860c2f2876SMatthew G. Knepley Level: intermediate 18870c2f2876SMatthew G. Knepley 1888db781477SPatrick Sanan .seealso: `PetscDSGetRiemannSolver()` 18890c2f2876SMatthew G. Knepley @*/ 18909371c9d4SSatish Balay 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)) { 18910c2f2876SMatthew G. Knepley PetscFunctionBegin; 18926528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1893de716cbcSToby Isaac if (r) PetscValidFunction(r, 3); 189463a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 18959566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, 0, r)); 18960c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18970c2f2876SMatthew G. Knepley } 18980c2f2876SMatthew G. Knepley 189932d2bbc9SMatthew G. Knepley /*@C 190032d2bbc9SMatthew G. Knepley PetscDSGetUpdate - Get the pointwise update function for a given field 190132d2bbc9SMatthew G. Knepley 190232d2bbc9SMatthew G. Knepley Not collective 190332d2bbc9SMatthew G. Knepley 190432d2bbc9SMatthew G. Knepley Input Parameters: 19056528b96dSMatthew G. Knepley + ds - The PetscDS 190632d2bbc9SMatthew G. Knepley - f - The field number 190732d2bbc9SMatthew G. Knepley 1908f899ff85SJose E. Roman Output Parameter: 1909a2b725a8SWilliam Gropp . update - update function 191032d2bbc9SMatthew G. Knepley 191132d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 191232d2bbc9SMatthew G. Knepley 191332d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 191432d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 191532d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 191632d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 191732d2bbc9SMatthew G. Knepley 191832d2bbc9SMatthew G. Knepley + dim - the spatial dimension 191932d2bbc9SMatthew G. Knepley . Nf - the number of fields 192032d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 192132d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 192232d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 192332d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 192432d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 192532d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 192632d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 192732d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 192832d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 192932d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 193032d2bbc9SMatthew G. Knepley . t - current time 193132d2bbc9SMatthew G. Knepley . x - coordinates of the current point 193232d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point 193332d2bbc9SMatthew G. Knepley 193432d2bbc9SMatthew G. Knepley Level: intermediate 193532d2bbc9SMatthew G. Knepley 1936db781477SPatrick Sanan .seealso: `PetscDSSetUpdate()`, `PetscDSSetResidual()` 193732d2bbc9SMatthew G. Knepley @*/ 19389371c9d4SSatish Balay 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[])) { 193932d2bbc9SMatthew G. Knepley PetscFunctionBegin; 19406528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 194163a3b9bcSJacob 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); 19429371c9d4SSatish Balay if (update) { 19439371c9d4SSatish Balay PetscValidPointer(update, 3); 19449371c9d4SSatish Balay *update = ds->update[f]; 19459371c9d4SSatish Balay } 194632d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 194732d2bbc9SMatthew G. Knepley } 194832d2bbc9SMatthew G. Knepley 194932d2bbc9SMatthew G. Knepley /*@C 19503fa77dffSMatthew G. Knepley PetscDSSetUpdate - Set the pointwise update function for a given field 195132d2bbc9SMatthew G. Knepley 195232d2bbc9SMatthew G. Knepley Not collective 195332d2bbc9SMatthew G. Knepley 195432d2bbc9SMatthew G. Knepley Input Parameters: 19556528b96dSMatthew G. Knepley + ds - The PetscDS 195632d2bbc9SMatthew G. Knepley . f - The field number 195732d2bbc9SMatthew G. Knepley - update - update function 195832d2bbc9SMatthew G. Knepley 195932d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 196032d2bbc9SMatthew G. Knepley 196132d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 196232d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 196332d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 196432d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 196532d2bbc9SMatthew G. Knepley 196632d2bbc9SMatthew G. Knepley + dim - the spatial dimension 196732d2bbc9SMatthew G. Knepley . Nf - the number of fields 196832d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 196932d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 197032d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 197132d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 197232d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 197332d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 197432d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 197532d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 197632d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 197732d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 197832d2bbc9SMatthew G. Knepley . t - current time 197932d2bbc9SMatthew G. Knepley . x - coordinates of the current point 198032d2bbc9SMatthew G. Knepley - uNew - new field values at the current point 198132d2bbc9SMatthew G. Knepley 198232d2bbc9SMatthew G. Knepley Level: intermediate 198332d2bbc9SMatthew G. Knepley 1984db781477SPatrick Sanan .seealso: `PetscDSGetResidual()` 198532d2bbc9SMatthew G. Knepley @*/ 19869371c9d4SSatish Balay 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[])) { 198732d2bbc9SMatthew G. Knepley PetscFunctionBegin; 19886528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 198932d2bbc9SMatthew G. Knepley if (update) PetscValidFunction(update, 3); 199063a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 19919566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(ds, f + 1)); 19926528b96dSMatthew G. Knepley ds->update[f] = update; 199332d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 199432d2bbc9SMatthew G. Knepley } 199532d2bbc9SMatthew G. Knepley 19969371c9d4SSatish Balay PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void *ctx) { 19970c2f2876SMatthew G. Knepley PetscFunctionBegin; 19986528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 199963a3b9bcSJacob 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); 20000c2f2876SMatthew G. Knepley PetscValidPointer(ctx, 3); 20013ec1f749SStefano Zampini *(void **)ctx = ds->ctx[f]; 20020c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 20030c2f2876SMatthew G. Knepley } 20040c2f2876SMatthew G. Knepley 20059371c9d4SSatish Balay PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx) { 20060c2f2876SMatthew G. Knepley PetscFunctionBegin; 20076528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 200863a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 20099566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(ds, f + 1)); 20106528b96dSMatthew G. Knepley ds->ctx[f] = ctx; 20110c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 20120c2f2876SMatthew G. Knepley } 20130c2f2876SMatthew G. Knepley 2014194d53e6SMatthew G. Knepley /*@C 2015194d53e6SMatthew G. Knepley PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field 2016194d53e6SMatthew G. Knepley 2017194d53e6SMatthew G. Knepley Not collective 2018194d53e6SMatthew G. Knepley 2019194d53e6SMatthew G. Knepley Input Parameters: 20206528b96dSMatthew G. Knepley + ds - The PetscDS 2021194d53e6SMatthew G. Knepley - f - The test field number 2022194d53e6SMatthew G. Knepley 2023194d53e6SMatthew G. Knepley Output Parameters: 2024194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term 2025194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2026194d53e6SMatthew G. Knepley 2027194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2028194d53e6SMatthew G. Knepley 2029194d53e6SMatthew G. Knepley \int_\Gamma \phi {\vec f}_0(u, u_t, \nabla u, x, t) \cdot \hat n + \nabla\phi \cdot {\overleftrightarrow f}_1(u, u_t, \nabla u, x, t) \cdot \hat n 2030194d53e6SMatthew G. Knepley 2031194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2032194d53e6SMatthew G. Knepley 203330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2034194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2035194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 203630b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2037194d53e6SMatthew G. Knepley 2038194d53e6SMatthew G. Knepley + dim - the spatial dimension 2039194d53e6SMatthew G. Knepley . Nf - the number of fields 2040194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2041194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2042194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2043194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2044194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2045194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2046194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2047194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2048194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2049194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2050194d53e6SMatthew G. Knepley . t - current time 2051194d53e6SMatthew G. Knepley . x - coordinates of the current point 2052194d53e6SMatthew G. Knepley . n - unit normal at the current point 205397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 205497b6e6e8SMatthew G. Knepley . constants - constant parameters 2055194d53e6SMatthew G. Knepley - f0 - output values at the current point 2056194d53e6SMatthew G. Knepley 2057194d53e6SMatthew G. Knepley Level: intermediate 2058194d53e6SMatthew G. Knepley 2059db781477SPatrick Sanan .seealso: `PetscDSSetBdResidual()` 2060194d53e6SMatthew G. Knepley @*/ 20619371c9d4SSatish Balay 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[])) { 20626528b96dSMatthew G. Knepley PetscBdPointFunc *tmp0, *tmp1; 20636528b96dSMatthew G. Knepley PetscInt n0, n1; 20646528b96dSMatthew G. Knepley 20652764a2aaSMatthew G. Knepley PetscFunctionBegin; 20666528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 206763a3b9bcSJacob 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); 20689566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1)); 20696528b96dSMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 20706528b96dSMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 20712764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 20722764a2aaSMatthew G. Knepley } 20732764a2aaSMatthew G. Knepley 2074194d53e6SMatthew G. Knepley /*@C 2075194d53e6SMatthew G. Knepley PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field 2076194d53e6SMatthew G. Knepley 2077194d53e6SMatthew G. Knepley Not collective 2078194d53e6SMatthew G. Knepley 2079194d53e6SMatthew G. Knepley Input Parameters: 20806528b96dSMatthew G. Knepley + ds - The PetscDS 2081194d53e6SMatthew G. Knepley . f - The test field number 2082194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term 2083194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2084194d53e6SMatthew G. Knepley 2085194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2086194d53e6SMatthew G. Knepley 2087194d53e6SMatthew G. Knepley \int_\Gamma \phi {\vec f}_0(u, u_t, \nabla u, x, t) \cdot \hat n + \nabla\phi \cdot {\overleftrightarrow f}_1(u, u_t, \nabla u, x, t) \cdot \hat n 2088194d53e6SMatthew G. Knepley 2089194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2090194d53e6SMatthew G. Knepley 209130b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2092194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2093194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 209430b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2095194d53e6SMatthew G. Knepley 2096194d53e6SMatthew G. Knepley + dim - the spatial dimension 2097194d53e6SMatthew G. Knepley . Nf - the number of fields 2098194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2099194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2100194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2101194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2102194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2103194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2104194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2105194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2106194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2107194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2108194d53e6SMatthew G. Knepley . t - current time 2109194d53e6SMatthew G. Knepley . x - coordinates of the current point 2110194d53e6SMatthew G. Knepley . n - unit normal at the current point 211197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 211297b6e6e8SMatthew G. Knepley . constants - constant parameters 2113194d53e6SMatthew G. Knepley - f0 - output values at the current point 2114194d53e6SMatthew G. Knepley 2115194d53e6SMatthew G. Knepley Level: intermediate 2116194d53e6SMatthew G. Knepley 2117db781477SPatrick Sanan .seealso: `PetscDSGetBdResidual()` 2118194d53e6SMatthew G. Knepley @*/ 21199371c9d4SSatish Balay 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[])) { 21202764a2aaSMatthew G. Knepley PetscFunctionBegin; 21216528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 212263a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 21239566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1)); 21242764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21252764a2aaSMatthew G. Knepley } 21262764a2aaSMatthew G. Knepley 212727f02ce8SMatthew G. Knepley /*@ 212827f02ce8SMatthew G. Knepley PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set 212927f02ce8SMatthew G. Knepley 213027f02ce8SMatthew G. Knepley Not collective 213127f02ce8SMatthew G. Knepley 213227f02ce8SMatthew G. Knepley Input Parameter: 21336528b96dSMatthew G. Knepley . ds - The PetscDS 213427f02ce8SMatthew G. Knepley 213527f02ce8SMatthew G. Knepley Output Parameter: 213627f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set 213727f02ce8SMatthew G. Knepley 213827f02ce8SMatthew G. Knepley Level: intermediate 213927f02ce8SMatthew G. Knepley 2140db781477SPatrick Sanan .seealso: `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()` 214127f02ce8SMatthew G. Knepley @*/ 21429371c9d4SSatish Balay PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac) { 214327f02ce8SMatthew G. Knepley PetscFunctionBegin; 21446528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 21456528b96dSMatthew G. Knepley PetscValidBoolPointer(hasBdJac, 2); 21469566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasBdJacobian(ds->wf, hasBdJac)); 214727f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 214827f02ce8SMatthew G. Knepley } 214927f02ce8SMatthew G. Knepley 2150194d53e6SMatthew G. Knepley /*@C 2151194d53e6SMatthew G. Knepley PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field 2152194d53e6SMatthew G. Knepley 2153194d53e6SMatthew G. Knepley Not collective 2154194d53e6SMatthew G. Knepley 2155194d53e6SMatthew G. Knepley Input Parameters: 21566528b96dSMatthew G. Knepley + ds - The PetscDS 2157194d53e6SMatthew G. Knepley . f - The test field number 2158194d53e6SMatthew G. Knepley - g - The field number 2159194d53e6SMatthew G. Knepley 2160194d53e6SMatthew G. Knepley Output Parameters: 2161194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 2162194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2163194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2164194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2165194d53e6SMatthew G. Knepley 2166194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2167194d53e6SMatthew G. Knepley 2168194d53e6SMatthew G. Knepley \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi 2169194d53e6SMatthew G. Knepley 2170194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2171194d53e6SMatthew G. Knepley 217230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2173194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2174194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 217530b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2176194d53e6SMatthew G. Knepley 2177194d53e6SMatthew G. Knepley + dim - the spatial dimension 2178194d53e6SMatthew G. Knepley . Nf - the number of fields 2179194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2180194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2181194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2182194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2183194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2184194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2185194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2186194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2187194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2188194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2189194d53e6SMatthew G. Knepley . t - current time 21902aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2191194d53e6SMatthew G. Knepley . x - coordinates of the current point 2192194d53e6SMatthew G. Knepley . n - normal at the current point 219397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 219497b6e6e8SMatthew G. Knepley . constants - constant parameters 2195194d53e6SMatthew G. Knepley - g0 - output values at the current point 2196194d53e6SMatthew G. Knepley 2197194d53e6SMatthew G. Knepley Level: intermediate 2198194d53e6SMatthew G. Knepley 2199db781477SPatrick Sanan .seealso: `PetscDSSetBdJacobian()` 2200194d53e6SMatthew G. Knepley @*/ 22019371c9d4SSatish Balay 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[])) { 22026528b96dSMatthew G. Knepley PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3; 22036528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 22046528b96dSMatthew G. Knepley 22052764a2aaSMatthew G. Knepley PetscFunctionBegin; 22066528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 220763a3b9bcSJacob 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); 220863a3b9bcSJacob 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); 22099566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 22106528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 22116528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 22126528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 22136528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 22142764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22152764a2aaSMatthew G. Knepley } 22162764a2aaSMatthew G. Knepley 2217194d53e6SMatthew G. Knepley /*@C 2218194d53e6SMatthew G. Knepley PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field 2219194d53e6SMatthew G. Knepley 2220194d53e6SMatthew G. Knepley Not collective 2221194d53e6SMatthew G. Knepley 2222194d53e6SMatthew G. Knepley Input Parameters: 22236528b96dSMatthew G. Knepley + ds - The PetscDS 2224194d53e6SMatthew G. Knepley . f - The test field number 2225194d53e6SMatthew G. Knepley . g - The field number 2226194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 2227194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2228194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2229194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2230194d53e6SMatthew G. Knepley 2231194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2232194d53e6SMatthew G. Knepley 2233194d53e6SMatthew G. Knepley \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi 2234194d53e6SMatthew G. Knepley 2235194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2236194d53e6SMatthew G. Knepley 223730b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2238194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2239194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 224030b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2241194d53e6SMatthew G. Knepley 2242194d53e6SMatthew G. Knepley + dim - the spatial dimension 2243194d53e6SMatthew G. Knepley . Nf - the number of fields 2244194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2245194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2246194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2247194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2248194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2249194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2250194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2251194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2252194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2253194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2254194d53e6SMatthew G. Knepley . t - current time 22552aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2256194d53e6SMatthew G. Knepley . x - coordinates of the current point 2257194d53e6SMatthew G. Knepley . n - normal at the current point 225897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 225997b6e6e8SMatthew G. Knepley . constants - constant parameters 2260194d53e6SMatthew G. Knepley - g0 - output values at the current point 2261194d53e6SMatthew G. Knepley 2262194d53e6SMatthew G. Knepley Level: intermediate 2263194d53e6SMatthew G. Knepley 2264db781477SPatrick Sanan .seealso: `PetscDSGetBdJacobian()` 2265194d53e6SMatthew G. Knepley @*/ 22669371c9d4SSatish Balay 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[])) { 22672764a2aaSMatthew G. Knepley PetscFunctionBegin; 22686528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 22692764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 22702764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 22712764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 22722764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 227363a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 227463a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 22759566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 22762764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22772764a2aaSMatthew G. Knepley } 22782764a2aaSMatthew G. Knepley 227927f02ce8SMatthew G. Knepley /*@ 228027f02ce8SMatthew G. Knepley PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set 228127f02ce8SMatthew G. Knepley 228227f02ce8SMatthew G. Knepley Not collective 228327f02ce8SMatthew G. Knepley 228427f02ce8SMatthew G. Knepley Input Parameter: 22856528b96dSMatthew G. Knepley . ds - The PetscDS 228627f02ce8SMatthew G. Knepley 228727f02ce8SMatthew G. Knepley Output Parameter: 228827f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set 228927f02ce8SMatthew G. Knepley 229027f02ce8SMatthew G. Knepley Level: intermediate 229127f02ce8SMatthew G. Knepley 2292db781477SPatrick Sanan .seealso: `PetscDSHasJacobian()`, `PetscDSSetBdJacobian()`, `PetscDSGetBdJacobian()` 229327f02ce8SMatthew G. Knepley @*/ 22949371c9d4SSatish Balay PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre) { 229527f02ce8SMatthew G. Knepley PetscFunctionBegin; 22966528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 22976528b96dSMatthew G. Knepley PetscValidBoolPointer(hasBdJacPre, 2); 22989566063dSJacob Faibussowitsch PetscCall(PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre)); 229927f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 230027f02ce8SMatthew G. Knepley } 230127f02ce8SMatthew G. Knepley 230227f02ce8SMatthew G. Knepley /*@C 230327f02ce8SMatthew G. Knepley PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field 230427f02ce8SMatthew G. Knepley 230527f02ce8SMatthew G. Knepley Not collective 230627f02ce8SMatthew G. Knepley 230727f02ce8SMatthew G. Knepley Input Parameters: 23086528b96dSMatthew G. Knepley + ds - The PetscDS 230927f02ce8SMatthew G. Knepley . f - The test field number 231027f02ce8SMatthew G. Knepley - g - The field number 231127f02ce8SMatthew G. Knepley 231227f02ce8SMatthew G. Knepley Output Parameters: 231327f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term 231427f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 231527f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 231627f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 231727f02ce8SMatthew G. Knepley 231827f02ce8SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 231927f02ce8SMatthew G. Knepley 232027f02ce8SMatthew G. Knepley \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi 232127f02ce8SMatthew G. Knepley 232227f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 232327f02ce8SMatthew G. Knepley 232427f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 232527f02ce8SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 232627f02ce8SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 232727f02ce8SMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 232827f02ce8SMatthew G. Knepley 232927f02ce8SMatthew G. Knepley + dim - the spatial dimension 233027f02ce8SMatthew G. Knepley . Nf - the number of fields 233127f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 233227f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 233327f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 233427f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 233527f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 233627f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 233727f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 233827f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 233927f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 234027f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 234127f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 234227f02ce8SMatthew G. Knepley . t - current time 234327f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 234427f02ce8SMatthew G. Knepley . x - coordinates of the current point 234527f02ce8SMatthew G. Knepley . n - normal at the current point 234627f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 234727f02ce8SMatthew G. Knepley . constants - constant parameters 234827f02ce8SMatthew G. Knepley - g0 - output values at the current point 234927f02ce8SMatthew G. Knepley 235027f02ce8SMatthew G. Knepley This is not yet available in Fortran. 235127f02ce8SMatthew G. Knepley 235227f02ce8SMatthew G. Knepley Level: intermediate 235327f02ce8SMatthew G. Knepley 2354db781477SPatrick Sanan .seealso: `PetscDSSetBdJacobianPreconditioner()` 235527f02ce8SMatthew G. Knepley @*/ 23569371c9d4SSatish Balay 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[])) { 23576528b96dSMatthew G. Knepley PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3; 23586528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 23596528b96dSMatthew G. Knepley 236027f02ce8SMatthew G. Knepley PetscFunctionBegin; 23616528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 236263a3b9bcSJacob 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); 236363a3b9bcSJacob 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); 23649566063dSJacob Faibussowitsch PetscCall(PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3)); 23656528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 23666528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 23676528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 23686528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 236927f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 237027f02ce8SMatthew G. Knepley } 237127f02ce8SMatthew G. Knepley 237227f02ce8SMatthew G. Knepley /*@C 237327f02ce8SMatthew G. Knepley PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field 237427f02ce8SMatthew G. Knepley 237527f02ce8SMatthew G. Knepley Not collective 237627f02ce8SMatthew G. Knepley 237727f02ce8SMatthew G. Knepley Input Parameters: 23786528b96dSMatthew G. Knepley + ds - The PetscDS 237927f02ce8SMatthew G. Knepley . f - The test field number 238027f02ce8SMatthew G. Knepley . g - The field number 238127f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term 238227f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 238327f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 238427f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 238527f02ce8SMatthew G. Knepley 238627f02ce8SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 238727f02ce8SMatthew G. Knepley 238827f02ce8SMatthew G. Knepley \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi 238927f02ce8SMatthew G. Knepley 239027f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 239127f02ce8SMatthew G. Knepley 239227f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 239327f02ce8SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 239427f02ce8SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 239527f02ce8SMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 239627f02ce8SMatthew G. Knepley 239727f02ce8SMatthew G. Knepley + dim - the spatial dimension 239827f02ce8SMatthew G. Knepley . Nf - the number of fields 239927f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 240027f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 240127f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 240227f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 240327f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 240427f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 240527f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 240627f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 240727f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 240827f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 240927f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 241027f02ce8SMatthew G. Knepley . t - current time 241127f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 241227f02ce8SMatthew G. Knepley . x - coordinates of the current point 241327f02ce8SMatthew G. Knepley . n - normal at the current point 241427f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 241527f02ce8SMatthew G. Knepley . constants - constant parameters 241627f02ce8SMatthew G. Knepley - g0 - output values at the current point 241727f02ce8SMatthew G. Knepley 241827f02ce8SMatthew G. Knepley This is not yet available in Fortran. 241927f02ce8SMatthew G. Knepley 242027f02ce8SMatthew G. Knepley Level: intermediate 242127f02ce8SMatthew G. Knepley 2422db781477SPatrick Sanan .seealso: `PetscDSGetBdJacobianPreconditioner()` 242327f02ce8SMatthew G. Knepley @*/ 24249371c9d4SSatish Balay 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[])) { 242527f02ce8SMatthew G. Knepley PetscFunctionBegin; 24266528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 242727f02ce8SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 242827f02ce8SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 242927f02ce8SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 243027f02ce8SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 243163a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 243263a3b9bcSJacob Faibussowitsch PetscCheck(g >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", g); 24339566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3)); 243427f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 243527f02ce8SMatthew G. Knepley } 243627f02ce8SMatthew G. Knepley 24370d3e9b51SMatthew G. Knepley /*@C 2438c371a6d1SMatthew G. Knepley PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field 2439c371a6d1SMatthew G. Knepley 2440c371a6d1SMatthew G. Knepley Not collective 2441c371a6d1SMatthew G. Knepley 2442c371a6d1SMatthew G. Knepley Input Parameters: 2443c371a6d1SMatthew G. Knepley + prob - The PetscDS 2444c371a6d1SMatthew G. Knepley - f - The test field number 2445c371a6d1SMatthew G. Knepley 2446d8d19677SJose E. Roman Output Parameters: 244795cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field 244895cbbfd3SMatthew G. Knepley - exactCtx - exact solution context 2449c371a6d1SMatthew G. Knepley 2450c371a6d1SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2451c371a6d1SMatthew G. Knepley 2452c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2453c371a6d1SMatthew G. Knepley 2454c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2455c371a6d1SMatthew G. Knepley . t - current time 2456c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2457c371a6d1SMatthew G. Knepley . Nc - the number of field components 2458c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2459c371a6d1SMatthew G. Knepley - ctx - a user context 2460c371a6d1SMatthew G. Knepley 2461c371a6d1SMatthew G. Knepley Level: intermediate 2462c371a6d1SMatthew G. Knepley 2463db781477SPatrick Sanan .seealso: `PetscDSSetExactSolution()`, `PetscDSGetExactSolutionTimeDerivative()` 2464c371a6d1SMatthew G. Knepley @*/ 24659371c9d4SSatish Balay PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx) { 2466c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2467c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 246863a3b9bcSJacob 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); 24699371c9d4SSatish Balay if (sol) { 24709371c9d4SSatish Balay PetscValidPointer(sol, 3); 24719371c9d4SSatish Balay *sol = prob->exactSol[f]; 24729371c9d4SSatish Balay } 24739371c9d4SSatish Balay if (ctx) { 24749371c9d4SSatish Balay PetscValidPointer(ctx, 4); 24759371c9d4SSatish Balay *ctx = prob->exactCtx[f]; 24769371c9d4SSatish Balay } 2477c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2478c371a6d1SMatthew G. Knepley } 2479c371a6d1SMatthew G. Knepley 2480c371a6d1SMatthew G. Knepley /*@C 2481578a5ef5SMatthew Knepley PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field 2482c371a6d1SMatthew G. Knepley 2483c371a6d1SMatthew G. Knepley Not collective 2484c371a6d1SMatthew G. Knepley 2485c371a6d1SMatthew G. Knepley Input Parameters: 2486c371a6d1SMatthew G. Knepley + prob - The PetscDS 2487c371a6d1SMatthew G. Knepley . f - The test field number 248895cbbfd3SMatthew G. Knepley . sol - solution function for the test fields 248995cbbfd3SMatthew G. Knepley - ctx - solution context or NULL 2490c371a6d1SMatthew G. Knepley 2491c371a6d1SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2492c371a6d1SMatthew G. Knepley 2493c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2494c371a6d1SMatthew G. Knepley 2495c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2496c371a6d1SMatthew G. Knepley . t - current time 2497c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2498c371a6d1SMatthew G. Knepley . Nc - the number of field components 2499c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2500c371a6d1SMatthew G. Knepley - ctx - a user context 2501c371a6d1SMatthew G. Knepley 2502c371a6d1SMatthew G. Knepley Level: intermediate 2503c371a6d1SMatthew G. Knepley 2504db781477SPatrick Sanan .seealso: `PetscDSGetExactSolution()` 2505c371a6d1SMatthew G. Knepley @*/ 25069371c9d4SSatish Balay PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx) { 2507c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2508c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 250963a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 25109566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(prob, f + 1)); 25119371c9d4SSatish Balay if (sol) { 25129371c9d4SSatish Balay PetscValidFunction(sol, 3); 25139371c9d4SSatish Balay prob->exactSol[f] = sol; 25149371c9d4SSatish Balay } 25159371c9d4SSatish Balay if (ctx) { 25169371c9d4SSatish Balay PetscValidFunction(ctx, 4); 25179371c9d4SSatish Balay prob->exactCtx[f] = ctx; 25189371c9d4SSatish Balay } 2519c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2520c371a6d1SMatthew G. Knepley } 2521c371a6d1SMatthew G. Knepley 25225638fd0eSMatthew G. Knepley /*@C 2523f2cacb80SMatthew G. Knepley PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field 2524f2cacb80SMatthew G. Knepley 2525f2cacb80SMatthew G. Knepley Not collective 2526f2cacb80SMatthew G. Knepley 2527f2cacb80SMatthew G. Knepley Input Parameters: 2528f2cacb80SMatthew G. Knepley + prob - The PetscDS 2529f2cacb80SMatthew G. Knepley - f - The test field number 2530f2cacb80SMatthew G. Knepley 2531d8d19677SJose E. Roman Output Parameters: 2532f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field 2533f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context 2534f2cacb80SMatthew G. Knepley 2535f2cacb80SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2536f2cacb80SMatthew G. Knepley 2537f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2538f2cacb80SMatthew G. Knepley 2539f2cacb80SMatthew G. Knepley + dim - the spatial dimension 2540f2cacb80SMatthew G. Knepley . t - current time 2541f2cacb80SMatthew G. Knepley . x - coordinates of the current point 2542f2cacb80SMatthew G. Knepley . Nc - the number of field components 2543f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point 2544f2cacb80SMatthew G. Knepley - ctx - a user context 2545f2cacb80SMatthew G. Knepley 2546f2cacb80SMatthew G. Knepley Level: intermediate 2547f2cacb80SMatthew G. Knepley 2548db781477SPatrick Sanan .seealso: `PetscDSSetExactSolutionTimeDerivative()`, `PetscDSGetExactSolution()` 2549f2cacb80SMatthew G. Knepley @*/ 25509371c9d4SSatish Balay PetscErrorCode PetscDSGetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx) { 2551f2cacb80SMatthew G. Knepley PetscFunctionBegin; 2552f2cacb80SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 255363a3b9bcSJacob 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); 25549371c9d4SSatish Balay if (sol) { 25559371c9d4SSatish Balay PetscValidPointer(sol, 3); 25569371c9d4SSatish Balay *sol = prob->exactSol_t[f]; 25579371c9d4SSatish Balay } 25589371c9d4SSatish Balay if (ctx) { 25599371c9d4SSatish Balay PetscValidPointer(ctx, 4); 25609371c9d4SSatish Balay *ctx = prob->exactCtx_t[f]; 25619371c9d4SSatish Balay } 2562f2cacb80SMatthew G. Knepley PetscFunctionReturn(0); 2563f2cacb80SMatthew G. Knepley } 2564f2cacb80SMatthew G. Knepley 2565f2cacb80SMatthew G. Knepley /*@C 2566f2cacb80SMatthew G. Knepley PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field 2567f2cacb80SMatthew G. Knepley 2568f2cacb80SMatthew G. Knepley Not collective 2569f2cacb80SMatthew G. Knepley 2570f2cacb80SMatthew G. Knepley Input Parameters: 2571f2cacb80SMatthew G. Knepley + prob - The PetscDS 2572f2cacb80SMatthew G. Knepley . f - The test field number 2573f2cacb80SMatthew G. Knepley . sol - time derivative of the solution function for the test fields 2574f2cacb80SMatthew G. Knepley - ctx - time derivative of the solution context or NULL 2575f2cacb80SMatthew G. Knepley 2576f2cacb80SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2577f2cacb80SMatthew G. Knepley 2578f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2579f2cacb80SMatthew G. Knepley 2580f2cacb80SMatthew G. Knepley + dim - the spatial dimension 2581f2cacb80SMatthew G. Knepley . t - current time 2582f2cacb80SMatthew G. Knepley . x - coordinates of the current point 2583f2cacb80SMatthew G. Knepley . Nc - the number of field components 2584f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point 2585f2cacb80SMatthew G. Knepley - ctx - a user context 2586f2cacb80SMatthew G. Knepley 2587f2cacb80SMatthew G. Knepley Level: intermediate 2588f2cacb80SMatthew G. Knepley 2589db781477SPatrick Sanan .seealso: `PetscDSGetExactSolutionTimeDerivative()`, `PetscDSSetExactSolution()` 2590f2cacb80SMatthew G. Knepley @*/ 25919371c9d4SSatish Balay PetscErrorCode PetscDSSetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx) { 2592f2cacb80SMatthew G. Knepley PetscFunctionBegin; 2593f2cacb80SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 259463a3b9bcSJacob Faibussowitsch PetscCheck(f >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be non-negative", f); 25959566063dSJacob Faibussowitsch PetscCall(PetscDSEnlarge_Static(prob, f + 1)); 25969371c9d4SSatish Balay if (sol) { 25979371c9d4SSatish Balay PetscValidFunction(sol, 3); 25989371c9d4SSatish Balay prob->exactSol_t[f] = sol; 25999371c9d4SSatish Balay } 26009371c9d4SSatish Balay if (ctx) { 26019371c9d4SSatish Balay PetscValidFunction(ctx, 4); 26029371c9d4SSatish Balay prob->exactCtx_t[f] = ctx; 26039371c9d4SSatish Balay } 2604f2cacb80SMatthew G. Knepley PetscFunctionReturn(0); 2605f2cacb80SMatthew G. Knepley } 2606f2cacb80SMatthew G. Knepley 2607f2cacb80SMatthew G. Knepley /*@C 260897b6e6e8SMatthew G. Knepley PetscDSGetConstants - Returns the array of constants passed to point functions 260997b6e6e8SMatthew G. Knepley 261097b6e6e8SMatthew G. Knepley Not collective 261197b6e6e8SMatthew G. Knepley 261297b6e6e8SMatthew G. Knepley Input Parameter: 261397b6e6e8SMatthew G. Knepley . prob - The PetscDS object 261497b6e6e8SMatthew G. Knepley 261597b6e6e8SMatthew G. Knepley Output Parameters: 261697b6e6e8SMatthew G. Knepley + numConstants - The number of constants 261797b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 261897b6e6e8SMatthew G. Knepley 261997b6e6e8SMatthew G. Knepley Level: intermediate 262097b6e6e8SMatthew G. Knepley 2621db781477SPatrick Sanan .seealso: `PetscDSSetConstants()`, `PetscDSCreate()` 262297b6e6e8SMatthew G. Knepley @*/ 26239371c9d4SSatish Balay PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[]) { 262497b6e6e8SMatthew G. Knepley PetscFunctionBegin; 262597b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26269371c9d4SSatish Balay if (numConstants) { 26279371c9d4SSatish Balay PetscValidIntPointer(numConstants, 2); 26289371c9d4SSatish Balay *numConstants = prob->numConstants; 26299371c9d4SSatish Balay } 26309371c9d4SSatish Balay if (constants) { 26319371c9d4SSatish Balay PetscValidPointer(constants, 3); 26329371c9d4SSatish Balay *constants = prob->constants; 26339371c9d4SSatish Balay } 263497b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 263597b6e6e8SMatthew G. Knepley } 263697b6e6e8SMatthew G. Knepley 26370d3e9b51SMatthew G. Knepley /*@C 263897b6e6e8SMatthew G. Knepley PetscDSSetConstants - Set the array of constants passed to point functions 263997b6e6e8SMatthew G. Knepley 264097b6e6e8SMatthew G. Knepley Not collective 264197b6e6e8SMatthew G. Knepley 264297b6e6e8SMatthew G. Knepley Input Parameters: 264397b6e6e8SMatthew G. Knepley + prob - The PetscDS object 264497b6e6e8SMatthew G. Knepley . numConstants - The number of constants 264597b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 264697b6e6e8SMatthew G. Knepley 264797b6e6e8SMatthew G. Knepley Level: intermediate 264897b6e6e8SMatthew G. Knepley 2649db781477SPatrick Sanan .seealso: `PetscDSGetConstants()`, `PetscDSCreate()` 265097b6e6e8SMatthew G. Knepley @*/ 26519371c9d4SSatish Balay PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[]) { 265297b6e6e8SMatthew G. Knepley PetscFunctionBegin; 265397b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 265497b6e6e8SMatthew G. Knepley if (numConstants != prob->numConstants) { 26559566063dSJacob Faibussowitsch PetscCall(PetscFree(prob->constants)); 265697b6e6e8SMatthew G. Knepley prob->numConstants = numConstants; 265797b6e6e8SMatthew G. Knepley if (prob->numConstants) { 26589566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(prob->numConstants, &prob->constants)); 265920be0f5bSMatthew G. Knepley } else { 266020be0f5bSMatthew G. Knepley prob->constants = NULL; 266120be0f5bSMatthew G. Knepley } 266220be0f5bSMatthew G. Knepley } 266320be0f5bSMatthew G. Knepley if (prob->numConstants) { 2664dadcf809SJacob Faibussowitsch PetscValidScalarPointer(constants, 3); 26659566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(prob->constants, constants, prob->numConstants)); 266697b6e6e8SMatthew G. Knepley } 266797b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 266897b6e6e8SMatthew G. Knepley } 266997b6e6e8SMatthew G. Knepley 26704cd1e086SMatthew G. Knepley /*@ 26714cd1e086SMatthew G. Knepley PetscDSGetFieldIndex - Returns the index of the given field 26724cd1e086SMatthew G. Knepley 26734cd1e086SMatthew G. Knepley Not collective 26744cd1e086SMatthew G. Knepley 26754cd1e086SMatthew G. Knepley Input Parameters: 26764cd1e086SMatthew G. Knepley + prob - The PetscDS object 26774cd1e086SMatthew G. Knepley - disc - The discretization object 26784cd1e086SMatthew G. Knepley 26794cd1e086SMatthew G. Knepley Output Parameter: 26804cd1e086SMatthew G. Knepley . f - The field number 26814cd1e086SMatthew G. Knepley 26824cd1e086SMatthew G. Knepley Level: beginner 26834cd1e086SMatthew G. Knepley 2684db781477SPatrick Sanan .seealso: `PetscGetDiscretization()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 26854cd1e086SMatthew G. Knepley @*/ 26869371c9d4SSatish Balay PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f) { 26874cd1e086SMatthew G. Knepley PetscInt g; 26884cd1e086SMatthew G. Knepley 26894cd1e086SMatthew G. Knepley PetscFunctionBegin; 26904cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2691dadcf809SJacob Faibussowitsch PetscValidIntPointer(f, 3); 26924cd1e086SMatthew G. Knepley *f = -1; 26939371c9d4SSatish Balay for (g = 0; g < prob->Nf; ++g) { 26949371c9d4SSatish Balay if (disc == prob->disc[g]) break; 26959371c9d4SSatish Balay } 269608401ef6SPierre Jolivet PetscCheck(g != prob->Nf, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS."); 26974cd1e086SMatthew G. Knepley *f = g; 26984cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 26994cd1e086SMatthew G. Knepley } 27004cd1e086SMatthew G. Knepley 27014cd1e086SMatthew G. Knepley /*@ 27024cd1e086SMatthew G. Knepley PetscDSGetFieldSize - Returns the size of the given field in the full space basis 27034cd1e086SMatthew G. Knepley 27044cd1e086SMatthew G. Knepley Not collective 27054cd1e086SMatthew G. Knepley 27064cd1e086SMatthew G. Knepley Input Parameters: 27074cd1e086SMatthew G. Knepley + prob - The PetscDS object 27084cd1e086SMatthew G. Knepley - f - The field number 27094cd1e086SMatthew G. Knepley 27104cd1e086SMatthew G. Knepley Output Parameter: 27114cd1e086SMatthew G. Knepley . size - The size 27124cd1e086SMatthew G. Knepley 27134cd1e086SMatthew G. Knepley Level: beginner 27144cd1e086SMatthew G. Knepley 2715db781477SPatrick Sanan .seealso: `PetscDSGetFieldOffset()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 27164cd1e086SMatthew G. Knepley @*/ 27179371c9d4SSatish Balay PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size) { 27184cd1e086SMatthew G. Knepley PetscFunctionBegin; 27194cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2720dadcf809SJacob Faibussowitsch PetscValidIntPointer(size, 3); 272163a3b9bcSJacob 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); 27229566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 2723d4742ddaSMatthew G. Knepley *size = prob->Nb[f]; 27244cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 27254cd1e086SMatthew G. Knepley } 27264cd1e086SMatthew G. Knepley 2727bc4ae4beSMatthew G. Knepley /*@ 2728bc4ae4beSMatthew G. Knepley PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis 2729bc4ae4beSMatthew G. Knepley 2730bc4ae4beSMatthew G. Knepley Not collective 2731bc4ae4beSMatthew G. Knepley 2732bc4ae4beSMatthew G. Knepley Input Parameters: 2733bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 2734bc4ae4beSMatthew G. Knepley - f - The field number 2735bc4ae4beSMatthew G. Knepley 2736bc4ae4beSMatthew G. Knepley Output Parameter: 2737bc4ae4beSMatthew G. Knepley . off - The offset 2738bc4ae4beSMatthew G. Knepley 2739bc4ae4beSMatthew G. Knepley Level: beginner 2740bc4ae4beSMatthew G. Knepley 2741db781477SPatrick Sanan .seealso: `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 2742bc4ae4beSMatthew G. Knepley @*/ 27439371c9d4SSatish Balay PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) { 27444cd1e086SMatthew G. Knepley PetscInt size, g; 27452764a2aaSMatthew G. Knepley 27462764a2aaSMatthew G. Knepley PetscFunctionBegin; 27472764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2748dadcf809SJacob Faibussowitsch PetscValidIntPointer(off, 3); 274963a3b9bcSJacob Faibussowitsch PetscCheck(!(f < 0) && !(f >= prob->Nf), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, prob->Nf); 27502764a2aaSMatthew G. Knepley *off = 0; 27512764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 27529566063dSJacob Faibussowitsch PetscCall(PetscDSGetFieldSize(prob, g, &size)); 27534cd1e086SMatthew G. Knepley *off += size; 27542764a2aaSMatthew G. Knepley } 27552764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27562764a2aaSMatthew G. Knepley } 27572764a2aaSMatthew G. Knepley 2758bc4ae4beSMatthew G. Knepley /*@ 27595fedec97SMatthew G. Knepley PetscDSGetFieldOffsetCohesive - Returns the offset of the given field in the full space basis on a cohesive cell 27605fedec97SMatthew G. Knepley 27615fedec97SMatthew G. Knepley Not collective 27625fedec97SMatthew G. Knepley 27635fedec97SMatthew G. Knepley Input Parameters: 27645fedec97SMatthew G. Knepley + prob - The PetscDS object 27655fedec97SMatthew G. Knepley - f - The field number 27665fedec97SMatthew G. Knepley 27675fedec97SMatthew G. Knepley Output Parameter: 27685fedec97SMatthew G. Knepley . off - The offset 27695fedec97SMatthew G. Knepley 27705fedec97SMatthew G. Knepley Level: beginner 27715fedec97SMatthew G. Knepley 2772db781477SPatrick Sanan .seealso: `PetscDSGetFieldSize()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 27735fedec97SMatthew G. Knepley @*/ 27749371c9d4SSatish Balay PetscErrorCode PetscDSGetFieldOffsetCohesive(PetscDS ds, PetscInt f, PetscInt *off) { 27755fedec97SMatthew G. Knepley PetscInt size, g; 27765fedec97SMatthew G. Knepley 27775fedec97SMatthew G. Knepley PetscFunctionBegin; 27785fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 2779dadcf809SJacob Faibussowitsch PetscValidIntPointer(off, 3); 278063a3b9bcSJacob 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); 27815fedec97SMatthew G. Knepley *off = 0; 27825fedec97SMatthew G. Knepley for (g = 0; g < f; ++g) { 27835fedec97SMatthew G. Knepley PetscBool cohesive; 27845fedec97SMatthew G. Knepley 27859566063dSJacob Faibussowitsch PetscCall(PetscDSGetCohesive(ds, g, &cohesive)); 27869566063dSJacob Faibussowitsch PetscCall(PetscDSGetFieldSize(ds, g, &size)); 27875fedec97SMatthew G. Knepley *off += cohesive ? size : size * 2; 27885fedec97SMatthew G. Knepley } 27895fedec97SMatthew G. Knepley PetscFunctionReturn(0); 27905fedec97SMatthew G. Knepley } 27915fedec97SMatthew G. Knepley 27925fedec97SMatthew G. Knepley /*@ 279347e57110SSander Arens PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point 2794bc4ae4beSMatthew G. Knepley 2795bc4ae4beSMatthew G. Knepley Not collective 2796bc4ae4beSMatthew G. Knepley 279747e57110SSander Arens Input Parameter: 279847e57110SSander Arens . prob - The PetscDS object 2799bc4ae4beSMatthew G. Knepley 2800bc4ae4beSMatthew G. Knepley Output Parameter: 280147e57110SSander Arens . dimensions - The number of dimensions 2802bc4ae4beSMatthew G. Knepley 2803bc4ae4beSMatthew G. Knepley Level: beginner 2804bc4ae4beSMatthew G. Knepley 2805db781477SPatrick Sanan .seealso: `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 2806bc4ae4beSMatthew G. Knepley @*/ 28079371c9d4SSatish Balay PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[]) { 28082764a2aaSMatthew G. Knepley PetscFunctionBegin; 28092764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 28109566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 281147e57110SSander Arens PetscValidPointer(dimensions, 2); 281247e57110SSander Arens *dimensions = prob->Nb; 281347e57110SSander Arens PetscFunctionReturn(0); 28146ce16762SMatthew G. Knepley } 281547e57110SSander Arens 281647e57110SSander Arens /*@ 281747e57110SSander Arens PetscDSGetComponents - Returns the number of components for each field on an evaluation point 281847e57110SSander Arens 281947e57110SSander Arens Not collective 282047e57110SSander Arens 282147e57110SSander Arens Input Parameter: 282247e57110SSander Arens . prob - The PetscDS object 282347e57110SSander Arens 282447e57110SSander Arens Output Parameter: 282547e57110SSander Arens . components - The number of components 282647e57110SSander Arens 282747e57110SSander Arens Level: beginner 282847e57110SSander Arens 2829db781477SPatrick Sanan .seealso: `PetscDSGetComponentOffsets()`, `PetscDSGetNumFields()`, `PetscDSCreate()` 283047e57110SSander Arens @*/ 28319371c9d4SSatish Balay PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[]) { 283247e57110SSander Arens PetscFunctionBegin; 283347e57110SSander Arens PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 28349566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 283547e57110SSander Arens PetscValidPointer(components, 2); 283647e57110SSander Arens *components = prob->Nc; 28376ce16762SMatthew G. Knepley PetscFunctionReturn(0); 28386ce16762SMatthew G. Knepley } 28396ce16762SMatthew G. Knepley 28406ce16762SMatthew G. Knepley /*@ 28416ce16762SMatthew G. Knepley PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point 28426ce16762SMatthew G. Knepley 28436ce16762SMatthew G. Knepley Not collective 28446ce16762SMatthew G. Knepley 28456ce16762SMatthew G. Knepley Input Parameters: 28466ce16762SMatthew G. Knepley + prob - The PetscDS object 28476ce16762SMatthew G. Knepley - f - The field number 28486ce16762SMatthew G. Knepley 28496ce16762SMatthew G. Knepley Output Parameter: 28506ce16762SMatthew G. Knepley . off - The offset 28516ce16762SMatthew G. Knepley 28526ce16762SMatthew G. Knepley Level: beginner 28536ce16762SMatthew G. Knepley 2854db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()` 28556ce16762SMatthew G. Knepley @*/ 28569371c9d4SSatish Balay PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off) { 28576ce16762SMatthew G. Knepley PetscFunctionBegin; 28586ce16762SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2859dadcf809SJacob Faibussowitsch PetscValidIntPointer(off, 3); 286063a3b9bcSJacob 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); 28619566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 286247e57110SSander Arens *off = prob->off[f]; 28632764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 28642764a2aaSMatthew G. Knepley } 28652764a2aaSMatthew G. Knepley 2866194d53e6SMatthew G. Knepley /*@ 2867194d53e6SMatthew G. Knepley PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point 2868194d53e6SMatthew G. Knepley 2869194d53e6SMatthew G. Knepley Not collective 2870194d53e6SMatthew G. Knepley 2871194d53e6SMatthew G. Knepley Input Parameter: 2872194d53e6SMatthew G. Knepley . prob - The PetscDS object 2873194d53e6SMatthew G. Knepley 2874194d53e6SMatthew G. Knepley Output Parameter: 2875194d53e6SMatthew G. Knepley . offsets - The offsets 2876194d53e6SMatthew G. Knepley 2877194d53e6SMatthew G. Knepley Level: beginner 2878194d53e6SMatthew G. Knepley 2879db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()` 2880194d53e6SMatthew G. Knepley @*/ 28819371c9d4SSatish Balay PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[]) { 2882194d53e6SMatthew G. Knepley PetscFunctionBegin; 2883194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2884194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 28859566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 2886194d53e6SMatthew G. Knepley *offsets = prob->off; 2887194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2888194d53e6SMatthew G. Knepley } 2889194d53e6SMatthew G. Knepley 2890194d53e6SMatthew G. Knepley /*@ 2891194d53e6SMatthew G. Knepley PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point 2892194d53e6SMatthew G. Knepley 2893194d53e6SMatthew G. Knepley Not collective 2894194d53e6SMatthew G. Knepley 2895194d53e6SMatthew G. Knepley Input Parameter: 2896194d53e6SMatthew G. Knepley . prob - The PetscDS object 2897194d53e6SMatthew G. Knepley 2898194d53e6SMatthew G. Knepley Output Parameter: 2899194d53e6SMatthew G. Knepley . offsets - The offsets 2900194d53e6SMatthew G. Knepley 2901194d53e6SMatthew G. Knepley Level: beginner 2902194d53e6SMatthew G. Knepley 2903db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()` 2904194d53e6SMatthew G. Knepley @*/ 29059371c9d4SSatish Balay PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[]) { 2906194d53e6SMatthew G. Knepley PetscFunctionBegin; 2907194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2908194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 29099566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 2910194d53e6SMatthew G. Knepley *offsets = prob->offDer; 2911194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2912194d53e6SMatthew G. Knepley } 2913194d53e6SMatthew G. Knepley 29149ee2af8cSMatthew G. Knepley /*@ 29159ee2af8cSMatthew G. Knepley PetscDSGetComponentOffsetsCohesive - Returns the offset of each field on an evaluation point 29169ee2af8cSMatthew G. Knepley 29179ee2af8cSMatthew G. Knepley Not collective 29189ee2af8cSMatthew G. Knepley 29199ee2af8cSMatthew G. Knepley Input Parameters: 29209ee2af8cSMatthew G. Knepley + ds - The PetscDS object 29219ee2af8cSMatthew G. Knepley - s - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive 29229ee2af8cSMatthew G. Knepley 29239ee2af8cSMatthew G. Knepley Output Parameter: 29249ee2af8cSMatthew G. Knepley . offsets - The offsets 29259ee2af8cSMatthew G. Knepley 29269ee2af8cSMatthew G. Knepley Level: beginner 29279ee2af8cSMatthew G. Knepley 2928db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()` 29299ee2af8cSMatthew G. Knepley @*/ 29309371c9d4SSatish Balay PetscErrorCode PetscDSGetComponentOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[]) { 29319ee2af8cSMatthew G. Knepley PetscFunctionBegin; 29329ee2af8cSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 29339ee2af8cSMatthew G. Knepley PetscValidPointer(offsets, 3); 293428b400f6SJacob Faibussowitsch PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS"); 293563a3b9bcSJacob Faibussowitsch PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s); 29369566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(ds)); 29379ee2af8cSMatthew G. Knepley *offsets = ds->offCohesive[s]; 29389ee2af8cSMatthew G. Knepley PetscFunctionReturn(0); 29399ee2af8cSMatthew G. Knepley } 29409ee2af8cSMatthew G. Knepley 29419ee2af8cSMatthew G. Knepley /*@ 29429ee2af8cSMatthew G. Knepley PetscDSGetComponentDerivativeOffsetsCohesive - Returns the offset of each field derivative on an evaluation point 29439ee2af8cSMatthew G. Knepley 29449ee2af8cSMatthew G. Knepley Not collective 29459ee2af8cSMatthew G. Knepley 29469ee2af8cSMatthew G. Knepley Input Parameters: 29479ee2af8cSMatthew G. Knepley + ds - The PetscDS object 29489ee2af8cSMatthew G. Knepley - s - The cohesive side, 0 for negative, 1 for positive, 2 for cohesive 29499ee2af8cSMatthew G. Knepley 29509ee2af8cSMatthew G. Knepley Output Parameter: 29519ee2af8cSMatthew G. Knepley . offsets - The offsets 29529ee2af8cSMatthew G. Knepley 29539ee2af8cSMatthew G. Knepley Level: beginner 29549ee2af8cSMatthew G. Knepley 2955db781477SPatrick Sanan .seealso: `PetscDSGetNumFields()`, `PetscDSCreate()` 29569ee2af8cSMatthew G. Knepley @*/ 29579371c9d4SSatish Balay PetscErrorCode PetscDSGetComponentDerivativeOffsetsCohesive(PetscDS ds, PetscInt s, PetscInt *offsets[]) { 29589ee2af8cSMatthew G. Knepley PetscFunctionBegin; 29599ee2af8cSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 29609ee2af8cSMatthew G. Knepley PetscValidPointer(offsets, 3); 296128b400f6SJacob Faibussowitsch PetscCheck(ds->isCohesive, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Cohesive offsets are only valid for a cohesive DS"); 296263a3b9bcSJacob Faibussowitsch PetscCheck(!(s < 0) && !(s > 2), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cohesive side %" PetscInt_FMT " is not in [0, 2]", s); 29639566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(ds)); 29649ee2af8cSMatthew G. Knepley *offsets = ds->offDerCohesive[s]; 29659ee2af8cSMatthew G. Knepley PetscFunctionReturn(0); 29669ee2af8cSMatthew G. Knepley } 29679ee2af8cSMatthew G. Knepley 296868c9edb9SMatthew G. Knepley /*@C 296968c9edb9SMatthew G. Knepley PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization 297068c9edb9SMatthew G. Knepley 297168c9edb9SMatthew G. Knepley Not collective 297268c9edb9SMatthew G. Knepley 297368c9edb9SMatthew G. Knepley Input Parameter: 297468c9edb9SMatthew G. Knepley . prob - The PetscDS object 297568c9edb9SMatthew G. Knepley 2976ef0bb6c7SMatthew G. Knepley Output Parameter: 2977ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field 297868c9edb9SMatthew G. Knepley 297968c9edb9SMatthew G. Knepley Level: intermediate 298068c9edb9SMatthew G. Knepley 2981db781477SPatrick Sanan .seealso: `PetscDSCreate()` 298268c9edb9SMatthew G. Knepley @*/ 29839371c9d4SSatish Balay PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[]) { 29842764a2aaSMatthew G. Knepley PetscFunctionBegin; 29852764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2986ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 2); 29879566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 2988ef0bb6c7SMatthew G. Knepley *T = prob->T; 29892764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 29902764a2aaSMatthew G. Knepley } 29912764a2aaSMatthew G. Knepley 299268c9edb9SMatthew G. Knepley /*@C 29934d0b9603SSander Arens PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces 299468c9edb9SMatthew G. Knepley 299568c9edb9SMatthew G. Knepley Not collective 299668c9edb9SMatthew G. Knepley 299768c9edb9SMatthew G. Knepley Input Parameter: 299868c9edb9SMatthew G. Knepley . prob - The PetscDS object 299968c9edb9SMatthew G. Knepley 3000ef0bb6c7SMatthew G. Knepley Output Parameter: 3001a5b23f4aSJose E. Roman . Tf - The basis function and derivative tabulation on each local face at quadrature points for each and field 300268c9edb9SMatthew G. Knepley 300368c9edb9SMatthew G. Knepley Level: intermediate 300468c9edb9SMatthew G. Knepley 3005db781477SPatrick Sanan .seealso: `PetscDSGetTabulation()`, `PetscDSCreate()` 300668c9edb9SMatthew G. Knepley @*/ 30079371c9d4SSatish Balay PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[]) { 30082764a2aaSMatthew G. Knepley PetscFunctionBegin; 30092764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3010ef0bb6c7SMatthew G. Knepley PetscValidPointer(Tf, 2); 30119566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 3012ef0bb6c7SMatthew G. Knepley *Tf = prob->Tf; 30132764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30142764a2aaSMatthew G. Knepley } 30152764a2aaSMatthew G. Knepley 30169371c9d4SSatish Balay PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) { 30172764a2aaSMatthew G. Knepley PetscFunctionBegin; 30182764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30199566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 30209371c9d4SSatish Balay if (u) { 30219371c9d4SSatish Balay PetscValidPointer(u, 2); 30229371c9d4SSatish Balay *u = prob->u; 30239371c9d4SSatish Balay } 30249371c9d4SSatish Balay if (u_t) { 30259371c9d4SSatish Balay PetscValidPointer(u_t, 3); 30269371c9d4SSatish Balay *u_t = prob->u_t; 30279371c9d4SSatish Balay } 30289371c9d4SSatish Balay if (u_x) { 30299371c9d4SSatish Balay PetscValidPointer(u_x, 4); 30309371c9d4SSatish Balay *u_x = prob->u_x; 30319371c9d4SSatish Balay } 30322764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30332764a2aaSMatthew G. Knepley } 30342764a2aaSMatthew G. Knepley 30359371c9d4SSatish Balay PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) { 30362764a2aaSMatthew G. Knepley PetscFunctionBegin; 30372764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30389566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 30399371c9d4SSatish Balay if (f0) { 30409371c9d4SSatish Balay PetscValidPointer(f0, 2); 30419371c9d4SSatish Balay *f0 = prob->f0; 30429371c9d4SSatish Balay } 30439371c9d4SSatish Balay if (f1) { 30449371c9d4SSatish Balay PetscValidPointer(f1, 3); 30459371c9d4SSatish Balay *f1 = prob->f1; 30469371c9d4SSatish Balay } 30479371c9d4SSatish Balay if (g0) { 30489371c9d4SSatish Balay PetscValidPointer(g0, 4); 30499371c9d4SSatish Balay *g0 = prob->g0; 30509371c9d4SSatish Balay } 30519371c9d4SSatish Balay if (g1) { 30529371c9d4SSatish Balay PetscValidPointer(g1, 5); 30539371c9d4SSatish Balay *g1 = prob->g1; 30549371c9d4SSatish Balay } 30559371c9d4SSatish Balay if (g2) { 30569371c9d4SSatish Balay PetscValidPointer(g2, 6); 30579371c9d4SSatish Balay *g2 = prob->g2; 30589371c9d4SSatish Balay } 30599371c9d4SSatish Balay if (g3) { 30609371c9d4SSatish Balay PetscValidPointer(g3, 7); 30619371c9d4SSatish Balay *g3 = prob->g3; 30629371c9d4SSatish Balay } 30632764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30642764a2aaSMatthew G. Knepley } 30652764a2aaSMatthew G. Knepley 30669371c9d4SSatish Balay PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal) { 30672764a2aaSMatthew G. Knepley PetscFunctionBegin; 30682764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30699566063dSJacob Faibussowitsch PetscCall(PetscDSSetUp(prob)); 30709371c9d4SSatish Balay if (x) { 30719371c9d4SSatish Balay PetscValidPointer(x, 2); 30729371c9d4SSatish Balay *x = prob->x; 30739371c9d4SSatish Balay } 30749371c9d4SSatish Balay if (basisReal) { 30759371c9d4SSatish Balay PetscValidPointer(basisReal, 3); 30769371c9d4SSatish Balay *basisReal = prob->basisReal; 30779371c9d4SSatish Balay } 30789371c9d4SSatish Balay if (basisDerReal) { 30799371c9d4SSatish Balay PetscValidPointer(basisDerReal, 4); 30809371c9d4SSatish Balay *basisDerReal = prob->basisDerReal; 30819371c9d4SSatish Balay } 30829371c9d4SSatish Balay if (testReal) { 30839371c9d4SSatish Balay PetscValidPointer(testReal, 5); 30849371c9d4SSatish Balay *testReal = prob->testReal; 30859371c9d4SSatish Balay } 30869371c9d4SSatish Balay if (testDerReal) { 30879371c9d4SSatish Balay PetscValidPointer(testDerReal, 6); 30889371c9d4SSatish Balay *testDerReal = prob->testDerReal; 30899371c9d4SSatish Balay } 30902764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30912764a2aaSMatthew G. Knepley } 30922764a2aaSMatthew G. Knepley 309358ebd649SToby Isaac /*@C 30946aad120cSJose E. Roman PetscDSAddBoundary - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performed, using the kernels from PetscDSSetBdResidual(). 309558ebd649SToby Isaac 3096783e2ec8SMatthew G. Knepley Collective on ds 3097783e2ec8SMatthew G. Knepley 309858ebd649SToby Isaac Input Parameters: 309958ebd649SToby Isaac + ds - The PetscDS object 31002d47a189SJulian Andrej . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 310158ebd649SToby Isaac . name - The BC name 310245480ffeSMatthew G. Knepley . label - The label defining constrained points 310345480ffeSMatthew G. Knepley . Nv - The number of DMLabel values for constrained points 310445480ffeSMatthew G. Knepley . values - An array of label values for constrained points 310558ebd649SToby Isaac . field - The field to constrain 310645480ffeSMatthew G. Knepley . Nc - The number of constrained field components (0 will constrain all fields) 310758ebd649SToby Isaac . comps - An array of constrained component numbers 310858ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 3109a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL 311058ebd649SToby Isaac - ctx - An optional user context for bcFunc 311158ebd649SToby Isaac 311245480ffeSMatthew G. Knepley Output Parameters: 311345480ffeSMatthew G. Knepley - bd - The boundary number 311445480ffeSMatthew G. Knepley 311558ebd649SToby Isaac Options Database Keys: 311658ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 311758ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 311858ebd649SToby Isaac 311956cf3b9cSMatthew G. Knepley Note: 312056cf3b9cSMatthew G. Knepley Both bcFunc abd bcFunc_t will depend on the boundary condition type. If the type if DM_BC_ESSENTIAL, Then the calling sequence is: 312156cf3b9cSMatthew G. Knepley 312256cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[]) 312356cf3b9cSMatthew G. Knepley 312456cf3b9cSMatthew G. Knepley If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is: 312556cf3b9cSMatthew G. Knepley 312656cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux, 312756cf3b9cSMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 312856cf3b9cSMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 312956cf3b9cSMatthew G. Knepley $ PetscReal time, const PetscReal x[], PetscScalar bcval[]) 313056cf3b9cSMatthew G. Knepley 313156cf3b9cSMatthew G. Knepley + dim - the spatial dimension 313256cf3b9cSMatthew G. Knepley . Nf - the number of fields 313356cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 313456cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 313556cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point 313656cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 313756cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 313856cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 313956cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 314056cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point 314156cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 314256cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 314356cf3b9cSMatthew G. Knepley . t - current time 314456cf3b9cSMatthew G. Knepley . x - coordinates of the current point 314556cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters 314656cf3b9cSMatthew G. Knepley . constants - constant parameters 314756cf3b9cSMatthew G. Knepley - bcval - output values at the current point 314856cf3b9cSMatthew G. Knepley 314958ebd649SToby Isaac Level: developer 315058ebd649SToby Isaac 3151db781477SPatrick Sanan .seealso: `PetscDSAddBoundaryByName()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()` 315258ebd649SToby Isaac @*/ 31539371c9d4SSatish Balay 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) { 315445480ffeSMatthew G. Knepley DSBoundary head = ds->boundary, b; 315545480ffeSMatthew G. Knepley PetscInt n = 0; 315645480ffeSMatthew G. Knepley const char *lname; 315758ebd649SToby Isaac 315858ebd649SToby Isaac PetscFunctionBegin; 315958ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3160783e2ec8SMatthew G. Knepley PetscValidLogicalCollectiveEnum(ds, type, 2); 316145480ffeSMatthew G. Knepley PetscValidCharPointer(name, 3); 316245480ffeSMatthew G. Knepley PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4); 316345480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nv, 5); 316445480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, field, 7); 316545480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nc, 8); 3166d57bb9dbSMatthew G. Knepley if (Nc > 0) { 3167d57bb9dbSMatthew G. Knepley PetscInt *fcomps; 3168d57bb9dbSMatthew G. Knepley PetscInt c; 3169d57bb9dbSMatthew G. Knepley 31709566063dSJacob Faibussowitsch PetscCall(PetscDSGetComponents(ds, &fcomps)); 317163a3b9bcSJacob 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); 3172d57bb9dbSMatthew G. Knepley for (c = 0; c < Nc; ++c) { 31731dca8a05SBarry 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); 3174d57bb9dbSMatthew G. Knepley } 3175d57bb9dbSMatthew G. Knepley } 31769566063dSJacob Faibussowitsch PetscCall(PetscNew(&b)); 31779566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&b->name)); 31789566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf)); 31799566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf)); 31809566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nv, &b->values)); 31819566063dSJacob Faibussowitsch if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv)); 31829566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nc, &b->comps)); 31839566063dSJacob Faibussowitsch if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc)); 31849566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject)label, &lname)); 31859566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(lname, (char **)&b->lname)); 3186f971fd6bSMatthew G. Knepley b->type = type; 318745480ffeSMatthew G. Knepley b->label = label; 318845480ffeSMatthew G. Knepley b->Nv = Nv; 318958ebd649SToby Isaac b->field = field; 319045480ffeSMatthew G. Knepley b->Nc = Nc; 319158ebd649SToby Isaac b->func = bcFunc; 319256cf3b9cSMatthew G. Knepley b->func_t = bcFunc_t; 319358ebd649SToby Isaac b->ctx = ctx; 319445480ffeSMatthew G. Knepley b->next = NULL; 319545480ffeSMatthew G. Knepley /* Append to linked list so that we can preserve the order */ 319645480ffeSMatthew G. Knepley if (!head) ds->boundary = b; 319745480ffeSMatthew G. Knepley while (head) { 319845480ffeSMatthew G. Knepley if (!head->next) { 319945480ffeSMatthew G. Knepley head->next = b; 320045480ffeSMatthew G. Knepley head = b; 320145480ffeSMatthew G. Knepley } 320245480ffeSMatthew G. Knepley head = head->next; 320345480ffeSMatthew G. Knepley ++n; 320445480ffeSMatthew G. Knepley } 32059371c9d4SSatish Balay if (bd) { 32069371c9d4SSatish Balay PetscValidIntPointer(bd, 13); 32079371c9d4SSatish Balay *bd = n; 32089371c9d4SSatish Balay } 320945480ffeSMatthew G. Knepley PetscFunctionReturn(0); 321045480ffeSMatthew G. Knepley } 321145480ffeSMatthew G. Knepley 321245480ffeSMatthew G. Knepley /*@C 32136aad120cSJose E. Roman PetscDSAddBoundaryByName - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performed, using the kernels from PetscDSSetBdResidual(). 321445480ffeSMatthew G. Knepley 321545480ffeSMatthew G. Knepley Collective on ds 321645480ffeSMatthew G. Knepley 321745480ffeSMatthew G. Knepley Input Parameters: 321845480ffeSMatthew G. Knepley + ds - The PetscDS object 321945480ffeSMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 322045480ffeSMatthew G. Knepley . name - The BC name 322145480ffeSMatthew G. Knepley . lname - The naem of the label defining constrained points 322245480ffeSMatthew G. Knepley . Nv - The number of DMLabel values for constrained points 322345480ffeSMatthew G. Knepley . values - An array of label values for constrained points 322445480ffeSMatthew G. Knepley . field - The field to constrain 322545480ffeSMatthew G. Knepley . Nc - The number of constrained field components (0 will constrain all fields) 322645480ffeSMatthew G. Knepley . comps - An array of constrained component numbers 322745480ffeSMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 3228a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL 322945480ffeSMatthew G. Knepley - ctx - An optional user context for bcFunc 323045480ffeSMatthew G. Knepley 323145480ffeSMatthew G. Knepley Output Parameters: 323245480ffeSMatthew G. Knepley - bd - The boundary number 323345480ffeSMatthew G. Knepley 323445480ffeSMatthew G. Knepley Options Database Keys: 323545480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids 323645480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components 323745480ffeSMatthew G. Knepley 323845480ffeSMatthew G. Knepley Note: 323945480ffeSMatthew G. Knepley This function should only be used with DMForest currently, since labels cannot be defined before the underlygin Plex is built. 324045480ffeSMatthew G. Knepley 324145480ffeSMatthew G. Knepley Both bcFunc abd bcFunc_t will depend on the boundary condition type. If the type if DM_BC_ESSENTIAL, Then the calling sequence is: 324245480ffeSMatthew G. Knepley 324345480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[]) 324445480ffeSMatthew G. Knepley 324545480ffeSMatthew G. Knepley If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is: 324645480ffeSMatthew G. Knepley 324745480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux, 324845480ffeSMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 324945480ffeSMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 325045480ffeSMatthew G. Knepley $ PetscReal time, const PetscReal x[], PetscScalar bcval[]) 325145480ffeSMatthew G. Knepley 325245480ffeSMatthew G. Knepley + dim - the spatial dimension 325345480ffeSMatthew G. Knepley . Nf - the number of fields 325445480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 325545480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 325645480ffeSMatthew G. Knepley . u - each field evaluated at the current point 325745480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 325845480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 325945480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 326045480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 326145480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point 326245480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 326345480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 326445480ffeSMatthew G. Knepley . t - current time 326545480ffeSMatthew G. Knepley . x - coordinates of the current point 326645480ffeSMatthew G. Knepley . numConstants - number of constant parameters 326745480ffeSMatthew G. Knepley . constants - constant parameters 326845480ffeSMatthew G. Knepley - bcval - output values at the current point 326945480ffeSMatthew G. Knepley 327045480ffeSMatthew G. Knepley Level: developer 327145480ffeSMatthew G. Knepley 3272db781477SPatrick Sanan .seealso: `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSSetResidual()`, `PetscDSSetBdResidual()` 327345480ffeSMatthew G. Knepley @*/ 32749371c9d4SSatish Balay 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) { 327545480ffeSMatthew G. Knepley DSBoundary head = ds->boundary, b; 327645480ffeSMatthew G. Knepley PetscInt n = 0; 327745480ffeSMatthew G. Knepley 327845480ffeSMatthew G. Knepley PetscFunctionBegin; 327945480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 328045480ffeSMatthew G. Knepley PetscValidLogicalCollectiveEnum(ds, type, 2); 328145480ffeSMatthew G. Knepley PetscValidCharPointer(name, 3); 328245480ffeSMatthew G. Knepley PetscValidCharPointer(lname, 4); 328345480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nv, 5); 328445480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, field, 7); 328545480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nc, 8); 32869566063dSJacob Faibussowitsch PetscCall(PetscNew(&b)); 32879566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&b->name)); 32889566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf)); 32899566063dSJacob Faibussowitsch PetscCall(PetscWeakFormSetNumFields(b->wf, ds->Nf)); 32909566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nv, &b->values)); 32919566063dSJacob Faibussowitsch if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv)); 32929566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nc, &b->comps)); 32939566063dSJacob Faibussowitsch if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc)); 32949566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(lname, (char **)&b->lname)); 329545480ffeSMatthew G. Knepley b->type = type; 329645480ffeSMatthew G. Knepley b->label = NULL; 329745480ffeSMatthew G. Knepley b->Nv = Nv; 329845480ffeSMatthew G. Knepley b->field = field; 329945480ffeSMatthew G. Knepley b->Nc = Nc; 330045480ffeSMatthew G. Knepley b->func = bcFunc; 330145480ffeSMatthew G. Knepley b->func_t = bcFunc_t; 330245480ffeSMatthew G. Knepley b->ctx = ctx; 330345480ffeSMatthew G. Knepley b->next = NULL; 330445480ffeSMatthew G. Knepley /* Append to linked list so that we can preserve the order */ 330545480ffeSMatthew G. Knepley if (!head) ds->boundary = b; 330645480ffeSMatthew G. Knepley while (head) { 330745480ffeSMatthew G. Knepley if (!head->next) { 330845480ffeSMatthew G. Knepley head->next = b; 330945480ffeSMatthew G. Knepley head = b; 331045480ffeSMatthew G. Knepley } 331145480ffeSMatthew G. Knepley head = head->next; 331245480ffeSMatthew G. Knepley ++n; 331345480ffeSMatthew G. Knepley } 33149371c9d4SSatish Balay if (bd) { 33159371c9d4SSatish Balay PetscValidIntPointer(bd, 13); 33169371c9d4SSatish Balay *bd = n; 33179371c9d4SSatish Balay } 331858ebd649SToby Isaac PetscFunctionReturn(0); 331958ebd649SToby Isaac } 332058ebd649SToby Isaac 3321b67eacb3SMatthew G. Knepley /*@C 33226aad120cSJose E. Roman PetscDSUpdateBoundary - Change a boundary condition for the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performed, using the kernels from PetscDSSetBdResidual(). 3323b67eacb3SMatthew G. Knepley 3324b67eacb3SMatthew G. Knepley Input Parameters: 3325b67eacb3SMatthew G. Knepley + ds - The PetscDS object 3326b67eacb3SMatthew G. Knepley . bd - The boundary condition number 3327b67eacb3SMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 3328b67eacb3SMatthew G. Knepley . name - The BC name 332945480ffeSMatthew G. Knepley . label - The label defining constrained points 333045480ffeSMatthew G. Knepley . Nv - The number of DMLabel ids for constrained points 333145480ffeSMatthew G. Knepley . values - An array of ids for constrained points 3332b67eacb3SMatthew G. Knepley . field - The field to constrain 333345480ffeSMatthew G. Knepley . Nc - The number of constrained field components 3334b67eacb3SMatthew G. Knepley . comps - An array of constrained component numbers 3335b67eacb3SMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 3336a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL 3337b67eacb3SMatthew G. Knepley - ctx - An optional user context for bcFunc 3338b67eacb3SMatthew G. Knepley 333956cf3b9cSMatthew G. Knepley Note: 334056cf3b9cSMatthew G. Knepley The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from PetscDSGetNumBoundary(). See PetscDSAddBoundary() for a description of the calling sequences for the callbacks. 33419a6efb6aSMatthew G. Knepley 3342b67eacb3SMatthew G. Knepley Level: developer 3343b67eacb3SMatthew G. Knepley 3344db781477SPatrick Sanan .seealso: `PetscDSAddBoundary()`, `PetscDSGetBoundary()`, `PetscDSGetNumBoundary()` 3345b67eacb3SMatthew G. Knepley @*/ 33469371c9d4SSatish Balay 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) { 3347b67eacb3SMatthew G. Knepley DSBoundary b = ds->boundary; 3348b67eacb3SMatthew G. Knepley PetscInt n = 0; 3349b67eacb3SMatthew G. Knepley 3350b67eacb3SMatthew G. Knepley PetscFunctionBegin; 3351b67eacb3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3352b67eacb3SMatthew G. Knepley while (b) { 3353b67eacb3SMatthew G. Knepley if (n == bd) break; 3354b67eacb3SMatthew G. Knepley b = b->next; 3355b67eacb3SMatthew G. Knepley ++n; 3356b67eacb3SMatthew G. Knepley } 335763a3b9bcSJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n); 3358b67eacb3SMatthew G. Knepley if (name) { 33599566063dSJacob Faibussowitsch PetscCall(PetscFree(b->name)); 33609566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&b->name)); 3361b67eacb3SMatthew G. Knepley } 3362b67eacb3SMatthew G. Knepley b->type = type; 336345480ffeSMatthew G. Knepley if (label) { 336445480ffeSMatthew G. Knepley const char *name; 336545480ffeSMatthew G. Knepley 336645480ffeSMatthew G. Knepley b->label = label; 33679566063dSJacob Faibussowitsch PetscCall(PetscFree(b->lname)); 33689566063dSJacob Faibussowitsch PetscCall(PetscObjectGetName((PetscObject)label, &name)); 33699566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(name, (char **)&b->lname)); 337045480ffeSMatthew G. Knepley } 337145480ffeSMatthew G. Knepley if (Nv >= 0) { 337245480ffeSMatthew G. Knepley b->Nv = Nv; 33739566063dSJacob Faibussowitsch PetscCall(PetscFree(b->values)); 33749566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nv, &b->values)); 33759566063dSJacob Faibussowitsch if (Nv) PetscCall(PetscArraycpy(b->values, values, Nv)); 337645480ffeSMatthew G. Knepley } 337745480ffeSMatthew G. Knepley if (field >= 0) b->field = field; 337845480ffeSMatthew G. Knepley if (Nc >= 0) { 337945480ffeSMatthew G. Knepley b->Nc = Nc; 33809566063dSJacob Faibussowitsch PetscCall(PetscFree(b->comps)); 33819566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(Nc, &b->comps)); 33829566063dSJacob Faibussowitsch if (Nc) PetscCall(PetscArraycpy(b->comps, comps, Nc)); 338345480ffeSMatthew G. Knepley } 338445480ffeSMatthew G. Knepley if (bcFunc) b->func = bcFunc; 338545480ffeSMatthew G. Knepley if (bcFunc_t) b->func_t = bcFunc_t; 338645480ffeSMatthew G. Knepley if (ctx) b->ctx = ctx; 3387b67eacb3SMatthew G. Knepley PetscFunctionReturn(0); 3388b67eacb3SMatthew G. Knepley } 3389b67eacb3SMatthew G. Knepley 339058ebd649SToby Isaac /*@ 339158ebd649SToby Isaac PetscDSGetNumBoundary - Get the number of registered BC 339258ebd649SToby Isaac 339358ebd649SToby Isaac Input Parameters: 339458ebd649SToby Isaac . ds - The PetscDS object 339558ebd649SToby Isaac 339658ebd649SToby Isaac Output Parameters: 339758ebd649SToby Isaac . numBd - The number of BC 339858ebd649SToby Isaac 339958ebd649SToby Isaac Level: intermediate 340058ebd649SToby Isaac 3401db781477SPatrick Sanan .seealso: `PetscDSAddBoundary()`, `PetscDSGetBoundary()` 340258ebd649SToby Isaac @*/ 34039371c9d4SSatish Balay PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd) { 340458ebd649SToby Isaac DSBoundary b = ds->boundary; 340558ebd649SToby Isaac 340658ebd649SToby Isaac PetscFunctionBegin; 340758ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3408dadcf809SJacob Faibussowitsch PetscValidIntPointer(numBd, 2); 340958ebd649SToby Isaac *numBd = 0; 34109371c9d4SSatish Balay while (b) { 34119371c9d4SSatish Balay ++(*numBd); 34129371c9d4SSatish Balay b = b->next; 34139371c9d4SSatish Balay } 341458ebd649SToby Isaac PetscFunctionReturn(0); 341558ebd649SToby Isaac } 341658ebd649SToby Isaac 341758ebd649SToby Isaac /*@C 34189a6efb6aSMatthew G. Knepley PetscDSGetBoundary - Gets a boundary condition to the model 341958ebd649SToby Isaac 342058ebd649SToby Isaac Input Parameters: 342158ebd649SToby Isaac + ds - The PetscDS object 342258ebd649SToby Isaac - bd - The BC number 342358ebd649SToby Isaac 342458ebd649SToby Isaac Output Parameters: 342545480ffeSMatthew G. Knepley + wf - The PetscWeakForm holding the pointwise functions 342645480ffeSMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 342758ebd649SToby Isaac . name - The BC name 342845480ffeSMatthew G. Knepley . label - The label defining constrained points 342945480ffeSMatthew G. Knepley . Nv - The number of DMLabel ids for constrained points 343045480ffeSMatthew G. Knepley . values - An array of ids for constrained points 343158ebd649SToby Isaac . field - The field to constrain 343245480ffeSMatthew G. Knepley . Nc - The number of constrained field components 343358ebd649SToby Isaac . comps - An array of constrained component numbers 343458ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 3435a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values 343658ebd649SToby Isaac - ctx - An optional user context for bcFunc 343758ebd649SToby Isaac 343858ebd649SToby Isaac Options Database Keys: 343958ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 344058ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 344158ebd649SToby Isaac 344258ebd649SToby Isaac Level: developer 344358ebd649SToby Isaac 3444db781477SPatrick Sanan .seealso: `PetscDSAddBoundary()` 344558ebd649SToby Isaac @*/ 34469371c9d4SSatish Balay 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) { 344758ebd649SToby Isaac DSBoundary b = ds->boundary; 344858ebd649SToby Isaac PetscInt n = 0; 344958ebd649SToby Isaac 345058ebd649SToby Isaac PetscFunctionBegin; 345158ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 345258ebd649SToby Isaac while (b) { 345358ebd649SToby Isaac if (n == bd) break; 345458ebd649SToby Isaac b = b->next; 345558ebd649SToby Isaac ++n; 345658ebd649SToby Isaac } 345763a3b9bcSJacob Faibussowitsch PetscCheck(b, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %" PetscInt_FMT " is not in [0, %" PetscInt_FMT ")", bd, n); 345845480ffeSMatthew G. Knepley if (wf) { 345945480ffeSMatthew G. Knepley PetscValidPointer(wf, 3); 346045480ffeSMatthew G. Knepley *wf = b->wf; 346145480ffeSMatthew G. Knepley } 3462f971fd6bSMatthew G. Knepley if (type) { 346345480ffeSMatthew G. Knepley PetscValidPointer(type, 4); 3464f971fd6bSMatthew G. Knepley *type = b->type; 346558ebd649SToby Isaac } 346658ebd649SToby Isaac if (name) { 346745480ffeSMatthew G. Knepley PetscValidPointer(name, 5); 346858ebd649SToby Isaac *name = b->name; 346958ebd649SToby Isaac } 347045480ffeSMatthew G. Knepley if (label) { 347145480ffeSMatthew G. Knepley PetscValidPointer(label, 6); 347245480ffeSMatthew G. Knepley *label = b->label; 347345480ffeSMatthew G. Knepley } 347445480ffeSMatthew G. Knepley if (Nv) { 347545480ffeSMatthew G. Knepley PetscValidIntPointer(Nv, 7); 347645480ffeSMatthew G. Knepley *Nv = b->Nv; 347745480ffeSMatthew G. Knepley } 347845480ffeSMatthew G. Knepley if (values) { 347945480ffeSMatthew G. Knepley PetscValidPointer(values, 8); 348045480ffeSMatthew G. Knepley *values = b->values; 348158ebd649SToby Isaac } 348258ebd649SToby Isaac if (field) { 348345480ffeSMatthew G. Knepley PetscValidIntPointer(field, 9); 348458ebd649SToby Isaac *field = b->field; 348558ebd649SToby Isaac } 348645480ffeSMatthew G. Knepley if (Nc) { 348745480ffeSMatthew G. Knepley PetscValidIntPointer(Nc, 10); 348845480ffeSMatthew G. Knepley *Nc = b->Nc; 348958ebd649SToby Isaac } 349058ebd649SToby Isaac if (comps) { 349145480ffeSMatthew G. Knepley PetscValidPointer(comps, 11); 349258ebd649SToby Isaac *comps = b->comps; 349358ebd649SToby Isaac } 349458ebd649SToby Isaac if (func) { 349545480ffeSMatthew G. Knepley PetscValidPointer(func, 12); 349658ebd649SToby Isaac *func = b->func; 349758ebd649SToby Isaac } 349856cf3b9cSMatthew G. Knepley if (func_t) { 349945480ffeSMatthew G. Knepley PetscValidPointer(func_t, 13); 350056cf3b9cSMatthew G. Knepley *func_t = b->func_t; 350156cf3b9cSMatthew G. Knepley } 350258ebd649SToby Isaac if (ctx) { 350345480ffeSMatthew G. Knepley PetscValidPointer(ctx, 14); 350458ebd649SToby Isaac *ctx = b->ctx; 350558ebd649SToby Isaac } 350658ebd649SToby Isaac PetscFunctionReturn(0); 350758ebd649SToby Isaac } 350858ebd649SToby Isaac 35099371c9d4SSatish Balay static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew) { 351045480ffeSMatthew G. Knepley PetscFunctionBegin; 35119566063dSJacob Faibussowitsch PetscCall(PetscNew(bNew)); 35129566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf)); 35139566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCopy(b->wf, (*bNew)->wf)); 35149566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(b->name, (char **)&((*bNew)->name))); 35159566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(b->lname, (char **)&((*bNew)->lname))); 351645480ffeSMatthew G. Knepley (*bNew)->type = b->type; 351745480ffeSMatthew G. Knepley (*bNew)->label = b->label; 351845480ffeSMatthew G. Knepley (*bNew)->Nv = b->Nv; 35199566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(b->Nv, &(*bNew)->values)); 35209566063dSJacob Faibussowitsch PetscCall(PetscArraycpy((*bNew)->values, b->values, b->Nv)); 352145480ffeSMatthew G. Knepley (*bNew)->field = b->field; 352245480ffeSMatthew G. Knepley (*bNew)->Nc = b->Nc; 35239566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(b->Nc, &(*bNew)->comps)); 35249566063dSJacob Faibussowitsch PetscCall(PetscArraycpy((*bNew)->comps, b->comps, b->Nc)); 352545480ffeSMatthew G. Knepley (*bNew)->func = b->func; 352645480ffeSMatthew G. Knepley (*bNew)->func_t = b->func_t; 352745480ffeSMatthew G. Knepley (*bNew)->ctx = b->ctx; 352845480ffeSMatthew G. Knepley PetscFunctionReturn(0); 352945480ffeSMatthew G. Knepley } 353045480ffeSMatthew G. Knepley 35319252d075SMatthew G. Knepley /*@ 35329252d075SMatthew G. Knepley PetscDSCopyBoundary - Copy all boundary condition objects to the new problem 35339252d075SMatthew G. Knepley 35349252d075SMatthew G. Knepley Not collective 35359252d075SMatthew G. Knepley 353636951cb5SMatthew G. Knepley Input Parameters: 353736951cb5SMatthew G. Knepley + ds - The source PetscDS object 353836951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields 353936951cb5SMatthew G. Knepley - fields - The selected fields, or NULL for all fields 35409252d075SMatthew G. Knepley 35419252d075SMatthew G. Knepley Output Parameter: 354236951cb5SMatthew G. Knepley . newds - The target PetscDS, now with a copy of the boundary conditions 35439252d075SMatthew G. Knepley 35449252d075SMatthew G. Knepley Level: intermediate 35459252d075SMatthew G. Knepley 3546db781477SPatrick Sanan .seealso: `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 35479252d075SMatthew G. Knepley @*/ 35489371c9d4SSatish Balay PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds) { 354945480ffeSMatthew G. Knepley DSBoundary b, *lastnext; 3550dff059c6SToby Isaac 3551dff059c6SToby Isaac PetscFunctionBegin; 355236951cb5SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 355336951cb5SMatthew G. Knepley PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4); 355436951cb5SMatthew G. Knepley if (ds == newds) PetscFunctionReturn(0); 35559566063dSJacob Faibussowitsch PetscCall(PetscDSDestroyBoundary(newds)); 355636951cb5SMatthew G. Knepley lastnext = &(newds->boundary); 355736951cb5SMatthew G. Knepley for (b = ds->boundary; b; b = b->next) { 3558dff059c6SToby Isaac DSBoundary bNew; 355936951cb5SMatthew G. Knepley PetscInt fieldNew = -1; 3560dff059c6SToby Isaac 356136951cb5SMatthew G. Knepley if (numFields > 0 && fields) { 356236951cb5SMatthew G. Knepley PetscInt f; 356336951cb5SMatthew G. Knepley 35649371c9d4SSatish Balay for (f = 0; f < numFields; ++f) 35659371c9d4SSatish Balay if (b->field == fields[f]) break; 356636951cb5SMatthew G. Knepley if (f == numFields) continue; 356736951cb5SMatthew G. Knepley fieldNew = f; 356836951cb5SMatthew G. Knepley } 35699566063dSJacob Faibussowitsch PetscCall(DSBoundaryDuplicate_Internal(b, &bNew)); 357036951cb5SMatthew G. Knepley bNew->field = fieldNew < 0 ? b->field : fieldNew; 3571dff059c6SToby Isaac *lastnext = bNew; 3572dff059c6SToby Isaac lastnext = &(bNew->next); 3573dff059c6SToby Isaac } 3574dff059c6SToby Isaac PetscFunctionReturn(0); 3575dff059c6SToby Isaac } 3576dff059c6SToby Isaac 35776c1eb96dSMatthew G. Knepley /*@ 357845480ffeSMatthew G. Knepley PetscDSDestroyBoundary - Remove all DMBoundary objects from the PetscDS 357945480ffeSMatthew G. Knepley 358045480ffeSMatthew G. Knepley Not collective 358145480ffeSMatthew G. Knepley 358245480ffeSMatthew G. Knepley Input Parameter: 358345480ffeSMatthew G. Knepley . ds - The PetscDS object 358445480ffeSMatthew G. Knepley 358545480ffeSMatthew G. Knepley Level: intermediate 358645480ffeSMatthew G. Knepley 3587db781477SPatrick Sanan .seealso: `PetscDSCopyBoundary()`, `PetscDSCopyEquations()` 358845480ffeSMatthew G. Knepley @*/ 35899371c9d4SSatish Balay PetscErrorCode PetscDSDestroyBoundary(PetscDS ds) { 359045480ffeSMatthew G. Knepley DSBoundary next = ds->boundary; 359145480ffeSMatthew G. Knepley 359245480ffeSMatthew G. Knepley PetscFunctionBegin; 359345480ffeSMatthew G. Knepley while (next) { 359445480ffeSMatthew G. Knepley DSBoundary b = next; 359545480ffeSMatthew G. Knepley 359645480ffeSMatthew G. Knepley next = b->next; 35979566063dSJacob Faibussowitsch PetscCall(PetscWeakFormDestroy(&b->wf)); 35989566063dSJacob Faibussowitsch PetscCall(PetscFree(b->name)); 35999566063dSJacob Faibussowitsch PetscCall(PetscFree(b->lname)); 36009566063dSJacob Faibussowitsch PetscCall(PetscFree(b->values)); 36019566063dSJacob Faibussowitsch PetscCall(PetscFree(b->comps)); 36029566063dSJacob Faibussowitsch PetscCall(PetscFree(b)); 360345480ffeSMatthew G. Knepley } 360445480ffeSMatthew G. Knepley PetscFunctionReturn(0); 360545480ffeSMatthew G. Knepley } 360645480ffeSMatthew G. Knepley 360745480ffeSMatthew G. Knepley /*@ 36086c1eb96dSMatthew G. Knepley PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout 36096c1eb96dSMatthew G. Knepley 36106c1eb96dSMatthew G. Knepley Not collective 36116c1eb96dSMatthew G. Knepley 3612d8d19677SJose E. Roman Input Parameters: 36136c1eb96dSMatthew G. Knepley + prob - The PetscDS object 36146c1eb96dSMatthew G. Knepley . numFields - Number of new fields 36156c1eb96dSMatthew G. Knepley - fields - Old field number for each new field 36166c1eb96dSMatthew G. Knepley 36176c1eb96dSMatthew G. Knepley Output Parameter: 36186c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy 36196c1eb96dSMatthew G. Knepley 36206c1eb96dSMatthew G. Knepley Level: intermediate 36216c1eb96dSMatthew G. Knepley 3622db781477SPatrick Sanan .seealso: `PetscDSSelectEquations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 36236c1eb96dSMatthew G. Knepley @*/ 36249371c9d4SSatish Balay PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) { 36256c1eb96dSMatthew G. Knepley PetscInt Nf, Nfn, fn; 36266c1eb96dSMatthew G. Knepley 36276c1eb96dSMatthew G. Knepley PetscFunctionBegin; 36286c1eb96dSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3629dadcf809SJacob Faibussowitsch if (fields) PetscValidIntPointer(fields, 3); 36306c1eb96dSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 36319566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(prob, &Nf)); 36329566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(newprob, &Nfn)); 363345480ffeSMatthew G. Knepley numFields = numFields < 0 ? Nf : numFields; 36346c1eb96dSMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 36356c1eb96dSMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 36366c1eb96dSMatthew G. Knepley PetscObject disc; 36376c1eb96dSMatthew G. Knepley 36386c1eb96dSMatthew G. Knepley if (f >= Nf) continue; 36399566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, f, &disc)); 36409566063dSJacob Faibussowitsch PetscCall(PetscDSSetDiscretization(newprob, fn, disc)); 36416c1eb96dSMatthew G. Knepley } 36426c1eb96dSMatthew G. Knepley PetscFunctionReturn(0); 36436c1eb96dSMatthew G. Knepley } 36446c1eb96dSMatthew G. Knepley 36456c1eb96dSMatthew G. Knepley /*@ 36469252d075SMatthew G. Knepley PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout 36479252d075SMatthew G. Knepley 36489252d075SMatthew G. Knepley Not collective 36499252d075SMatthew G. Knepley 3650d8d19677SJose E. Roman Input Parameters: 36519252d075SMatthew G. Knepley + prob - The PetscDS object 36529252d075SMatthew G. Knepley . numFields - Number of new fields 36539252d075SMatthew G. Knepley - fields - Old field number for each new field 36549252d075SMatthew G. Knepley 36559252d075SMatthew G. Knepley Output Parameter: 36569252d075SMatthew G. Knepley . newprob - The PetscDS copy 36579252d075SMatthew G. Knepley 36589252d075SMatthew G. Knepley Level: intermediate 36599252d075SMatthew G. Knepley 3660db781477SPatrick Sanan .seealso: `PetscDSSelectDiscretizations()`, `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 36619252d075SMatthew G. Knepley @*/ 36629371c9d4SSatish Balay PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) { 36639252d075SMatthew G. Knepley PetscInt Nf, Nfn, fn, gn; 36649252d075SMatthew G. Knepley 36659252d075SMatthew G. Knepley PetscFunctionBegin; 36669252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3667dadcf809SJacob Faibussowitsch if (fields) PetscValidIntPointer(fields, 3); 36689252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 36699566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(prob, &Nf)); 36709566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(newprob, &Nfn)); 367163a3b9bcSJacob 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); 36729252d075SMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 36739252d075SMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 36749252d075SMatthew G. Knepley PetscPointFunc obj; 36759252d075SMatthew G. Knepley PetscPointFunc f0, f1; 36769252d075SMatthew G. Knepley PetscBdPointFunc f0Bd, f1Bd; 36779252d075SMatthew G. Knepley PetscRiemannFunc r; 36789252d075SMatthew G. Knepley 3679c52f1e13SMatthew G. Knepley if (f >= Nf) continue; 36809566063dSJacob Faibussowitsch PetscCall(PetscDSGetObjective(prob, f, &obj)); 36819566063dSJacob Faibussowitsch PetscCall(PetscDSGetResidual(prob, f, &f0, &f1)); 36829566063dSJacob Faibussowitsch PetscCall(PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd)); 36839566063dSJacob Faibussowitsch PetscCall(PetscDSGetRiemannSolver(prob, f, &r)); 36849566063dSJacob Faibussowitsch PetscCall(PetscDSSetObjective(newprob, fn, obj)); 36859566063dSJacob Faibussowitsch PetscCall(PetscDSSetResidual(newprob, fn, f0, f1)); 36869566063dSJacob Faibussowitsch PetscCall(PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd)); 36879566063dSJacob Faibussowitsch PetscCall(PetscDSSetRiemannSolver(newprob, fn, r)); 36889252d075SMatthew G. Knepley for (gn = 0; gn < numFields; ++gn) { 36899252d075SMatthew G. Knepley const PetscInt g = fields ? fields[gn] : gn; 36909252d075SMatthew G. Knepley PetscPointJac g0, g1, g2, g3; 36919252d075SMatthew G. Knepley PetscPointJac g0p, g1p, g2p, g3p; 36929252d075SMatthew G. Knepley PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd; 36939252d075SMatthew G. Knepley 3694c52f1e13SMatthew G. Knepley if (g >= Nf) continue; 36959566063dSJacob Faibussowitsch PetscCall(PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3)); 36969566063dSJacob Faibussowitsch PetscCall(PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p)); 36979566063dSJacob Faibussowitsch PetscCall(PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd)); 36989566063dSJacob Faibussowitsch PetscCall(PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3)); 36999566063dSJacob Faibussowitsch PetscCall(PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p)); 37009566063dSJacob Faibussowitsch PetscCall(PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd)); 37019252d075SMatthew G. Knepley } 37029252d075SMatthew G. Knepley } 37039252d075SMatthew G. Knepley PetscFunctionReturn(0); 37049252d075SMatthew G. Knepley } 37059252d075SMatthew G. Knepley 3706da51fcedSMatthew G. Knepley /*@ 3707da51fcedSMatthew G. Knepley PetscDSCopyEquations - Copy all pointwise function pointers to the new problem 3708da51fcedSMatthew G. Knepley 3709da51fcedSMatthew G. Knepley Not collective 3710da51fcedSMatthew G. Knepley 3711da51fcedSMatthew G. Knepley Input Parameter: 3712da51fcedSMatthew G. Knepley . prob - The PetscDS object 3713da51fcedSMatthew G. Knepley 3714da51fcedSMatthew G. Knepley Output Parameter: 3715da51fcedSMatthew G. Knepley . newprob - The PetscDS copy 3716da51fcedSMatthew G. Knepley 3717da51fcedSMatthew G. Knepley Level: intermediate 3718da51fcedSMatthew G. Knepley 3719db781477SPatrick Sanan .seealso: `PetscDSCopyBoundary()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 3720da51fcedSMatthew G. Knepley @*/ 37219371c9d4SSatish Balay PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob) { 3722b8025e53SMatthew G. Knepley PetscWeakForm wf, newwf; 37239252d075SMatthew G. Knepley PetscInt Nf, Ng; 3724da51fcedSMatthew G. Knepley 3725da51fcedSMatthew G. Knepley PetscFunctionBegin; 3726da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3727da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 37289566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(prob, &Nf)); 37299566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(newprob, &Ng)); 373063a3b9bcSJacob Faibussowitsch PetscCheck(Nf == Ng, PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %" PetscInt_FMT " != %" PetscInt_FMT, Nf, Ng); 37319566063dSJacob Faibussowitsch PetscCall(PetscDSGetWeakForm(prob, &wf)); 37329566063dSJacob Faibussowitsch PetscCall(PetscDSGetWeakForm(newprob, &newwf)); 37339566063dSJacob Faibussowitsch PetscCall(PetscWeakFormCopy(wf, newwf)); 37349252d075SMatthew G. Knepley PetscFunctionReturn(0); 37359252d075SMatthew G. Knepley } 373645480ffeSMatthew G. Knepley 37379252d075SMatthew G. Knepley /*@ 37389252d075SMatthew G. Knepley PetscDSCopyConstants - Copy all constants to the new problem 3739da51fcedSMatthew G. Knepley 37409252d075SMatthew G. Knepley Not collective 37419252d075SMatthew G. Knepley 37429252d075SMatthew G. Knepley Input Parameter: 37439252d075SMatthew G. Knepley . prob - The PetscDS object 37449252d075SMatthew G. Knepley 37459252d075SMatthew G. Knepley Output Parameter: 37469252d075SMatthew G. Knepley . newprob - The PetscDS copy 37479252d075SMatthew G. Knepley 37489252d075SMatthew G. Knepley Level: intermediate 37499252d075SMatthew G. Knepley 3750db781477SPatrick Sanan .seealso: `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 37519252d075SMatthew G. Knepley @*/ 37529371c9d4SSatish Balay PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob) { 37539252d075SMatthew G. Knepley PetscInt Nc; 37549252d075SMatthew G. Knepley const PetscScalar *constants; 37559252d075SMatthew G. Knepley 37569252d075SMatthew G. Knepley PetscFunctionBegin; 37579252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 37589252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 37599566063dSJacob Faibussowitsch PetscCall(PetscDSGetConstants(prob, &Nc, &constants)); 37609566063dSJacob Faibussowitsch PetscCall(PetscDSSetConstants(newprob, Nc, (PetscScalar *)constants)); 3761da51fcedSMatthew G. Knepley PetscFunctionReturn(0); 3762da51fcedSMatthew G. Knepley } 3763da51fcedSMatthew G. Knepley 376445480ffeSMatthew G. Knepley /*@ 376545480ffeSMatthew G. Knepley PetscDSCopyExactSolutions - Copy all exact solutions to the new problem 376645480ffeSMatthew G. Knepley 376745480ffeSMatthew G. Knepley Not collective 376845480ffeSMatthew G. Knepley 376945480ffeSMatthew G. Knepley Input Parameter: 377045480ffeSMatthew G. Knepley . ds - The PetscDS object 377145480ffeSMatthew G. Knepley 377245480ffeSMatthew G. Knepley Output Parameter: 377345480ffeSMatthew G. Knepley . newds - The PetscDS copy 377445480ffeSMatthew G. Knepley 377545480ffeSMatthew G. Knepley Level: intermediate 377645480ffeSMatthew G. Knepley 3777db781477SPatrick Sanan .seealso: `PetscDSCopyBoundary()`, `PetscDSCopyEquations()`, `PetscDSSetResidual()`, `PetscDSSetJacobian()`, `PetscDSSetRiemannSolver()`, `PetscDSSetBdResidual()`, `PetscDSSetBdJacobian()`, `PetscDSCreate()` 377845480ffeSMatthew G. Knepley @*/ 37799371c9d4SSatish Balay PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds) { 378045480ffeSMatthew G. Knepley PetscSimplePointFunc sol; 378145480ffeSMatthew G. Knepley void *ctx; 378245480ffeSMatthew G. Knepley PetscInt Nf, f; 378345480ffeSMatthew G. Knepley 378445480ffeSMatthew G. Knepley PetscFunctionBegin; 378545480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 378645480ffeSMatthew G. Knepley PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2); 37879566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 378845480ffeSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 37899566063dSJacob Faibussowitsch PetscCall(PetscDSGetExactSolution(ds, f, &sol, &ctx)); 37909566063dSJacob Faibussowitsch PetscCall(PetscDSSetExactSolution(newds, f, sol, ctx)); 37919566063dSJacob Faibussowitsch PetscCall(PetscDSGetExactSolutionTimeDerivative(ds, f, &sol, &ctx)); 37929566063dSJacob Faibussowitsch PetscCall(PetscDSSetExactSolutionTimeDerivative(newds, f, sol, ctx)); 379345480ffeSMatthew G. Knepley } 379445480ffeSMatthew G. Knepley PetscFunctionReturn(0); 379545480ffeSMatthew G. Knepley } 379645480ffeSMatthew G. Knepley 37979371c9d4SSatish Balay PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob) { 3798df3a45bdSMatthew G. Knepley PetscInt dim, Nf, f; 3799b1353e8eSMatthew G. Knepley 3800b1353e8eSMatthew G. Knepley PetscFunctionBegin; 3801b1353e8eSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3802b1353e8eSMatthew G. Knepley PetscValidPointer(subprob, 3); 38039371c9d4SSatish Balay if (height == 0) { 38049371c9d4SSatish Balay *subprob = prob; 38059371c9d4SSatish Balay PetscFunctionReturn(0); 38069371c9d4SSatish Balay } 38079566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(prob, &Nf)); 38089566063dSJacob Faibussowitsch PetscCall(PetscDSGetSpatialDimension(prob, &dim)); 380963a3b9bcSJacob 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); 38109566063dSJacob Faibussowitsch if (!prob->subprobs) PetscCall(PetscCalloc1(dim, &prob->subprobs)); 3811df3a45bdSMatthew G. Knepley if (!prob->subprobs[height - 1]) { 3812b1353e8eSMatthew G. Knepley PetscInt cdim; 3813b1353e8eSMatthew G. Knepley 38149566063dSJacob Faibussowitsch PetscCall(PetscDSCreate(PetscObjectComm((PetscObject)prob), &prob->subprobs[height - 1])); 38159566063dSJacob Faibussowitsch PetscCall(PetscDSGetCoordinateDimension(prob, &cdim)); 38169566063dSJacob Faibussowitsch PetscCall(PetscDSSetCoordinateDimension(prob->subprobs[height - 1], cdim)); 3817b1353e8eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3818b1353e8eSMatthew G. Knepley PetscFE subfe; 3819b1353e8eSMatthew G. Knepley PetscObject obj; 3820b1353e8eSMatthew G. Knepley PetscClassId id; 3821b1353e8eSMatthew G. Knepley 38229566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(prob, f, &obj)); 38239566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 38249566063dSJacob Faibussowitsch if (id == PETSCFE_CLASSID) PetscCall(PetscFEGetHeightSubspace((PetscFE)obj, height, &subfe)); 382563a3b9bcSJacob Faibussowitsch else SETERRQ(PetscObjectComm((PetscObject)prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %" PetscInt_FMT, f); 38269566063dSJacob Faibussowitsch PetscCall(PetscDSSetDiscretization(prob->subprobs[height - 1], f, (PetscObject)subfe)); 3827b1353e8eSMatthew G. Knepley } 3828b1353e8eSMatthew G. Knepley } 3829df3a45bdSMatthew G. Knepley *subprob = prob->subprobs[height - 1]; 3830b1353e8eSMatthew G. Knepley PetscFunctionReturn(0); 3831b1353e8eSMatthew G. Knepley } 3832b1353e8eSMatthew G. Knepley 38339371c9d4SSatish Balay PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype) { 3834c7bd5f0bSMatthew G. Knepley PetscObject obj; 3835c7bd5f0bSMatthew G. Knepley PetscClassId id; 3836c7bd5f0bSMatthew G. Knepley PetscInt Nf; 3837c7bd5f0bSMatthew G. Knepley 3838c7bd5f0bSMatthew G. Knepley PetscFunctionBegin; 3839c7bd5f0bSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3840665f567fSMatthew G. Knepley PetscValidPointer(disctype, 3); 3841665f567fSMatthew G. Knepley *disctype = PETSC_DISC_NONE; 38429566063dSJacob Faibussowitsch PetscCall(PetscDSGetNumFields(ds, &Nf)); 384363a3b9bcSJacob Faibussowitsch PetscCheck(f < Nf, PetscObjectComm((PetscObject)ds), PETSC_ERR_ARG_SIZ, "Field %" PetscInt_FMT " must be in [0, %" PetscInt_FMT ")", f, Nf); 38449566063dSJacob Faibussowitsch PetscCall(PetscDSGetDiscretization(ds, f, &obj)); 3845665f567fSMatthew G. Knepley if (obj) { 38469566063dSJacob Faibussowitsch PetscCall(PetscObjectGetClassId(obj, &id)); 3847665f567fSMatthew G. Knepley if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE; 3848665f567fSMatthew G. Knepley else *disctype = PETSC_DISC_FV; 3849665f567fSMatthew G. Knepley } 3850c7bd5f0bSMatthew G. Knepley PetscFunctionReturn(0); 3851c7bd5f0bSMatthew G. Knepley } 3852c7bd5f0bSMatthew G. Knepley 38539371c9d4SSatish Balay static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds) { 38542764a2aaSMatthew G. Knepley PetscFunctionBegin; 38559566063dSJacob Faibussowitsch PetscCall(PetscFree(ds->data)); 38562764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 38572764a2aaSMatthew G. Knepley } 38582764a2aaSMatthew G. Knepley 38599371c9d4SSatish Balay static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds) { 38602764a2aaSMatthew G. Knepley PetscFunctionBegin; 38616528b96dSMatthew G. Knepley ds->ops->setfromoptions = NULL; 38626528b96dSMatthew G. Knepley ds->ops->setup = NULL; 38636528b96dSMatthew G. Knepley ds->ops->view = NULL; 38646528b96dSMatthew G. Knepley ds->ops->destroy = PetscDSDestroy_Basic; 38652764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 38662764a2aaSMatthew G. Knepley } 38672764a2aaSMatthew G. Knepley 38682764a2aaSMatthew G. Knepley /*MC 38692764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 38702764a2aaSMatthew G. Knepley 38712764a2aaSMatthew G. Knepley Level: intermediate 38722764a2aaSMatthew G. Knepley 3873db781477SPatrick Sanan .seealso: `PetscDSType`, `PetscDSCreate()`, `PetscDSSetType()` 38742764a2aaSMatthew G. Knepley M*/ 38752764a2aaSMatthew G. Knepley 38769371c9d4SSatish Balay PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds) { 38772764a2aaSMatthew G. Knepley PetscDS_Basic *b; 38782764a2aaSMatthew G. Knepley 38792764a2aaSMatthew G. Knepley PetscFunctionBegin; 38806528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3881*4dfa11a4SJacob Faibussowitsch PetscCall(PetscNew(&b)); 38826528b96dSMatthew G. Knepley ds->data = b; 38832764a2aaSMatthew G. Knepley 38849566063dSJacob Faibussowitsch PetscCall(PetscDSInitialize_Basic(ds)); 38852764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 38862764a2aaSMatthew G. Knepley } 3887