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 522764a2aaSMatthew G. Knepley .keywords: PetscDS, register 532764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy() 542764a2aaSMatthew G. Knepley 552764a2aaSMatthew G. Knepley @*/ 562764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS)) 572764a2aaSMatthew G. Knepley { 582764a2aaSMatthew G. Knepley PetscErrorCode ierr; 592764a2aaSMatthew G. Knepley 602764a2aaSMatthew G. Knepley PetscFunctionBegin; 612764a2aaSMatthew G. Knepley ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr); 622764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 632764a2aaSMatthew G. Knepley } 642764a2aaSMatthew G. Knepley 652764a2aaSMatthew G. Knepley /*@C 662764a2aaSMatthew G. Knepley PetscDSSetType - Builds a particular PetscDS 672764a2aaSMatthew G. Knepley 682764a2aaSMatthew G. Knepley Collective on PetscDS 692764a2aaSMatthew G. Knepley 702764a2aaSMatthew G. Knepley Input Parameters: 712764a2aaSMatthew G. Knepley + prob - The PetscDS object 722764a2aaSMatthew G. Knepley - name - The kind of system 732764a2aaSMatthew G. Knepley 742764a2aaSMatthew G. Knepley Options Database Key: 752764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types 762764a2aaSMatthew G. Knepley 772764a2aaSMatthew G. Knepley Level: intermediate 782764a2aaSMatthew G. Knepley 79f5f57ec0SBarry Smith Not available from Fortran 80f5f57ec0SBarry Smith 812764a2aaSMatthew G. Knepley .keywords: PetscDS, set, type 822764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate() 832764a2aaSMatthew G. Knepley @*/ 842764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name) 852764a2aaSMatthew G. Knepley { 862764a2aaSMatthew G. Knepley PetscErrorCode (*r)(PetscDS); 872764a2aaSMatthew G. Knepley PetscBool match; 882764a2aaSMatthew G. Knepley PetscErrorCode ierr; 892764a2aaSMatthew G. Knepley 902764a2aaSMatthew G. Knepley PetscFunctionBegin; 912764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 922764a2aaSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr); 932764a2aaSMatthew G. Knepley if (match) PetscFunctionReturn(0); 942764a2aaSMatthew G. Knepley 950f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 962764a2aaSMatthew G. Knepley ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr); 972764a2aaSMatthew G. Knepley if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name); 982764a2aaSMatthew G. Knepley 992764a2aaSMatthew G. Knepley if (prob->ops->destroy) { 1002764a2aaSMatthew G. Knepley ierr = (*prob->ops->destroy)(prob);CHKERRQ(ierr); 1012764a2aaSMatthew G. Knepley prob->ops->destroy = NULL; 1022764a2aaSMatthew G. Knepley } 1032764a2aaSMatthew G. Knepley ierr = (*r)(prob);CHKERRQ(ierr); 1042764a2aaSMatthew G. Knepley ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr); 1052764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 1062764a2aaSMatthew G. Knepley } 1072764a2aaSMatthew G. Knepley 1082764a2aaSMatthew G. Knepley /*@C 1092764a2aaSMatthew G. Knepley PetscDSGetType - Gets the PetscDS type name (as a string) from the object. 1102764a2aaSMatthew G. Knepley 1112764a2aaSMatthew G. Knepley Not Collective 1122764a2aaSMatthew G. Knepley 1132764a2aaSMatthew G. Knepley Input Parameter: 1142764a2aaSMatthew G. Knepley . prob - The PetscDS 1152764a2aaSMatthew G. Knepley 1162764a2aaSMatthew G. Knepley Output Parameter: 1172764a2aaSMatthew G. Knepley . name - The PetscDS type name 1182764a2aaSMatthew G. Knepley 1192764a2aaSMatthew G. Knepley Level: intermediate 1202764a2aaSMatthew G. Knepley 121f5f57ec0SBarry Smith Not available from Fortran 122f5f57ec0SBarry Smith 1232764a2aaSMatthew G. Knepley .keywords: PetscDS, get, type, name 1242764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate() 1252764a2aaSMatthew G. Knepley @*/ 1262764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name) 1272764a2aaSMatthew G. Knepley { 1282764a2aaSMatthew G. Knepley PetscErrorCode ierr; 1292764a2aaSMatthew G. Knepley 1302764a2aaSMatthew G. Knepley PetscFunctionBegin; 1312764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 132c959eef4SJed Brown PetscValidPointer(name, 2); 1330f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 1342764a2aaSMatthew G. Knepley *name = ((PetscObject) prob)->type_name; 1352764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 1362764a2aaSMatthew G. Knepley } 1372764a2aaSMatthew G. Knepley 1387d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer) 1397d8a60eaSMatthew G. Knepley { 1407d8a60eaSMatthew G. Knepley PetscViewerFormat format; 14197b6e6e8SMatthew G. Knepley const PetscScalar *constants; 14297b6e6e8SMatthew G. Knepley PetscInt numConstants, f; 1437d8a60eaSMatthew G. Knepley PetscErrorCode ierr; 1447d8a60eaSMatthew G. Knepley 1457d8a60eaSMatthew G. Knepley PetscFunctionBegin; 1467d8a60eaSMatthew G. Knepley ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 1477d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr); 1487d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 1494727e194SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " cell total dim %D total comp %D\n", prob->totDim, prob->totComp);CHKERRQ(ierr); 1504727e194SMatthew G. Knepley if (prob->isHybrid) {ierr = PetscViewerASCIIPrintf(viewer, " hybrid cell\n");CHKERRQ(ierr);} 1517d8a60eaSMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 15240967b3bSMatthew G. Knepley DSBoundary b; 1537d8a60eaSMatthew G. Knepley PetscObject obj; 1547d8a60eaSMatthew G. Knepley PetscClassId id; 155f35450b9SMatthew G. Knepley PetscQuadrature q; 1567d8a60eaSMatthew G. Knepley const char *name; 157f35450b9SMatthew G. Knepley PetscInt Nc, Nq, Nqc; 1587d8a60eaSMatthew G. Knepley 1597d8a60eaSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 1607d8a60eaSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 1617d8a60eaSMatthew G. Knepley ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr); 1627d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr); 1634727e194SMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 1647d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 1657d8a60eaSMatthew G. Knepley ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr); 166f35450b9SMatthew G. Knepley ierr = PetscFEGetQuadrature((PetscFE) obj, &q);CHKERRQ(ierr); 1677d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr); 1687d8a60eaSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 1697d8a60eaSMatthew G. Knepley ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr); 170f35450b9SMatthew G. Knepley ierr = PetscFVGetQuadrature((PetscFV) obj, &q);CHKERRQ(ierr); 1717d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr); 1727d8a60eaSMatthew G. Knepley } 17397b6e6e8SMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f); 17497b6e6e8SMatthew G. Knepley if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%D components", Nc);CHKERRQ(ierr);} 17597b6e6e8SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, "%D component ", Nc);CHKERRQ(ierr);} 176249df284SMatthew G. Knepley if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);} 177249df284SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);} 178a6cbbb48SMatthew G. Knepley if (prob->adjacency[f*2+0]) { 179a6cbbb48SMatthew G. Knepley if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM++)");CHKERRQ(ierr);} 180a6cbbb48SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM)");CHKERRQ(ierr);} 181a6cbbb48SMatthew G. Knepley } else { 182a6cbbb48SMatthew G. Knepley if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FEM)");CHKERRQ(ierr);} 183a6cbbb48SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " (adj FUNKY)");CHKERRQ(ierr);} 184a6cbbb48SMatthew G. Knepley } 1853e60c2a6SMatthew G. Knepley if (q) { 186f35450b9SMatthew G. Knepley ierr = PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL);CHKERRQ(ierr); 187f35450b9SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " (Nq %D Nqc %D)", Nq, Nqc);CHKERRQ(ierr); 1883e60c2a6SMatthew G. Knepley } 1897d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 1904727e194SMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 1915d160056SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 1927d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);} 1937d8a60eaSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);} 1945d160056SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 19540967b3bSMatthew G. Knepley 19640967b3bSMatthew G. Knepley for (b = prob->boundary; b; b = b->next) { 19740967b3bSMatthew G. Knepley PetscInt c, i; 19840967b3bSMatthew G. Knepley 19940967b3bSMatthew G. Knepley if (b->field != f) continue; 20040967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 20140967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->labelname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr); 20240967b3bSMatthew G. Knepley if (!b->numcomps) { 20340967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " all components\n");CHKERRQ(ierr); 20440967b3bSMatthew G. Knepley } else { 20540967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " components: ");CHKERRQ(ierr); 20640967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 20740967b3bSMatthew G. Knepley for (c = 0; c < b->numcomps; ++c) { 20840967b3bSMatthew G. Knepley if (c > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 20940967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->comps[c]);CHKERRQ(ierr); 21040967b3bSMatthew G. Knepley } 21140967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 21240967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 21340967b3bSMatthew G. Knepley } 21440967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " ids: ");CHKERRQ(ierr); 21540967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 21640967b3bSMatthew G. Knepley for (i = 0; i < b->numids; ++i) { 21740967b3bSMatthew G. Knepley if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 21840967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->ids[i]);CHKERRQ(ierr); 21940967b3bSMatthew G. Knepley } 22040967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 22140967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 22240967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 22340967b3bSMatthew G. Knepley } 2247d8a60eaSMatthew G. Knepley } 22597b6e6e8SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr); 22697b6e6e8SMatthew G. Knepley if (numConstants) { 22797b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr); 22897b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 22957fc01e9SMatthew G. Knepley for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);} 23097b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 23197b6e6e8SMatthew G. Knepley } 2327d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 2337d8a60eaSMatthew G. Knepley PetscFunctionReturn(0); 2347d8a60eaSMatthew G. Knepley } 2357d8a60eaSMatthew G. Knepley 2362764a2aaSMatthew G. Knepley /*@C 2372764a2aaSMatthew G. Knepley PetscDSView - Views a PetscDS 2382764a2aaSMatthew G. Knepley 2392764a2aaSMatthew G. Knepley Collective on PetscDS 2402764a2aaSMatthew G. Knepley 2412764a2aaSMatthew G. Knepley Input Parameter: 2422764a2aaSMatthew G. Knepley + prob - the PetscDS object to view 2432764a2aaSMatthew G. Knepley - v - the viewer 2442764a2aaSMatthew G. Knepley 2452764a2aaSMatthew G. Knepley Level: developer 2462764a2aaSMatthew G. Knepley 2472764a2aaSMatthew G. Knepley .seealso PetscDSDestroy() 2482764a2aaSMatthew G. Knepley @*/ 2492764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v) 2502764a2aaSMatthew G. Knepley { 2517d8a60eaSMatthew G. Knepley PetscBool iascii; 2522764a2aaSMatthew G. Knepley PetscErrorCode ierr; 2532764a2aaSMatthew G. Knepley 2542764a2aaSMatthew G. Knepley PetscFunctionBegin; 2552764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2562764a2aaSMatthew G. Knepley if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);} 2577d8a60eaSMatthew G. Knepley else {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);} 2587d8a60eaSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 2597d8a60eaSMatthew G. Knepley if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);} 2602764a2aaSMatthew G. Knepley if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);} 2612764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 2622764a2aaSMatthew G. Knepley } 2632764a2aaSMatthew G. Knepley 2642764a2aaSMatthew G. Knepley /*@ 2652764a2aaSMatthew G. Knepley PetscDSSetFromOptions - sets parameters in a PetscDS from the options database 2662764a2aaSMatthew G. Knepley 2672764a2aaSMatthew G. Knepley Collective on PetscDS 2682764a2aaSMatthew G. Knepley 2692764a2aaSMatthew G. Knepley Input Parameter: 2702764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for 2712764a2aaSMatthew G. Knepley 2722764a2aaSMatthew G. Knepley Options Database: 27355c1f793SMatthew G. Knepley + -petscds_type <type> : Set the DS type 27455c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS 27555c1f793SMatthew G. Knepley . -petscds_jac_pre : Turn formation of a separate Jacobian preconditioner on and off 27655c1f793SMatthew G. Knepley . -bc_<name> <ids> : Specify a list of label ids for a boundary condition 27755c1f793SMatthew G. Knepley - -bc_<name>_comp <comps> : Specify a list of field components to constrain for a boundary condition 2782764a2aaSMatthew G. Knepley 2792764a2aaSMatthew G. Knepley Level: developer 2802764a2aaSMatthew G. Knepley 2812764a2aaSMatthew G. Knepley .seealso PetscDSView() 2822764a2aaSMatthew G. Knepley @*/ 2832764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob) 2842764a2aaSMatthew G. Knepley { 285f1fd5e65SToby Isaac DSBoundary b; 2862764a2aaSMatthew G. Knepley const char *defaultType; 2872764a2aaSMatthew G. Knepley char name[256]; 2882764a2aaSMatthew G. Knepley PetscBool flg; 2892764a2aaSMatthew G. Knepley PetscErrorCode ierr; 2902764a2aaSMatthew G. Knepley 2912764a2aaSMatthew G. Knepley PetscFunctionBegin; 2922764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2932764a2aaSMatthew G. Knepley if (!((PetscObject) prob)->type_name) { 2942764a2aaSMatthew G. Knepley defaultType = PETSCDSBASIC; 2952764a2aaSMatthew G. Knepley } else { 2962764a2aaSMatthew G. Knepley defaultType = ((PetscObject) prob)->type_name; 2972764a2aaSMatthew G. Knepley } 2980f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 2992764a2aaSMatthew G. Knepley 3002764a2aaSMatthew G. Knepley ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr); 301f1fd5e65SToby Isaac for (b = prob->boundary; b; b = b->next) { 302f1fd5e65SToby Isaac char optname[1024]; 303f1fd5e65SToby Isaac PetscInt ids[1024], len = 1024; 304f1fd5e65SToby Isaac PetscBool flg; 305f1fd5e65SToby Isaac 306f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr); 307f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 308f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr); 309f1fd5e65SToby Isaac if (flg) { 310f1fd5e65SToby Isaac b->numids = len; 311f1fd5e65SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 312f1fd5e65SToby Isaac ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr); 313f1fd5e65SToby Isaac ierr = PetscMemcpy(b->ids, ids, len*sizeof(PetscInt));CHKERRQ(ierr); 314f1fd5e65SToby Isaac } 315e7b0402cSSander Arens len = 1024; 316f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr); 317f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 318f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr); 319f1fd5e65SToby Isaac if (flg) { 320f1fd5e65SToby Isaac b->numcomps = len; 321f1fd5e65SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 322f1fd5e65SToby Isaac ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr); 323f1fd5e65SToby Isaac ierr = PetscMemcpy(b->comps, ids, len*sizeof(PetscInt));CHKERRQ(ierr); 324f1fd5e65SToby Isaac } 325f1fd5e65SToby Isaac } 3262764a2aaSMatthew G. Knepley ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr); 3272764a2aaSMatthew G. Knepley if (flg) { 3282764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, name);CHKERRQ(ierr); 3292764a2aaSMatthew G. Knepley } else if (!((PetscObject) prob)->type_name) { 3302764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr); 3312764a2aaSMatthew G. Knepley } 33255c1f793SMatthew G. Knepley ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr); 3332764a2aaSMatthew G. Knepley if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);} 3342764a2aaSMatthew G. Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 3350633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr); 3362764a2aaSMatthew G. Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 3375d160056SMatthew G. Knepley if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);} 3382764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 3392764a2aaSMatthew G. Knepley } 3402764a2aaSMatthew G. Knepley 3412764a2aaSMatthew G. Knepley /*@C 3422764a2aaSMatthew G. Knepley PetscDSSetUp - Construct data structures for the PetscDS 3432764a2aaSMatthew G. Knepley 3442764a2aaSMatthew G. Knepley Collective on PetscDS 3452764a2aaSMatthew G. Knepley 3462764a2aaSMatthew G. Knepley Input Parameter: 3472764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup 3482764a2aaSMatthew G. Knepley 3492764a2aaSMatthew G. Knepley Level: developer 3502764a2aaSMatthew G. Knepley 3512764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy() 3522764a2aaSMatthew G. Knepley @*/ 3532764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob) 3542764a2aaSMatthew G. Knepley { 3552764a2aaSMatthew G. Knepley const PetscInt Nf = prob->Nf; 35694a5e212SMatthew G. Knepley PetscInt dim, dimEmbed, work, NcMax = 0, NqMax = 0, NsMax = 1, f; 3572764a2aaSMatthew G. Knepley PetscErrorCode ierr; 3582764a2aaSMatthew G. Knepley 3592764a2aaSMatthew G. Knepley PetscFunctionBegin; 3602764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3612764a2aaSMatthew G. Knepley if (prob->setup) PetscFunctionReturn(0); 3622764a2aaSMatthew G. Knepley /* Calculate sizes */ 3632764a2aaSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 364d1506c7cSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr); 365f744cafaSSander Arens prob->totDim = prob->totComp = 0; 36647e57110SSander Arens ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr); 367f744cafaSSander Arens ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr); 368f744cafaSSander Arens ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisFace,Nf,&prob->basisDerFace);CHKERRQ(ierr); 3692764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3709de99aefSMatthew G. Knepley PetscObject obj; 3719de99aefSMatthew G. Knepley PetscClassId id; 3722764a2aaSMatthew G. Knepley PetscQuadrature q; 3739de99aefSMatthew G. Knepley PetscInt Nq = 0, Nb, Nc; 3742764a2aaSMatthew G. Knepley 3759de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 3769de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3779de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 3789de99aefSMatthew G. Knepley PetscFE fe = (PetscFE) obj; 3799de99aefSMatthew G. Knepley 3802764a2aaSMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr); 3812764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 3822764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 3832764a2aaSMatthew G. Knepley ierr = PetscFEGetDefaultTabulation(fe, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr); 3844d0b9603SSander Arens ierr = PetscFEGetFaceTabulation(fe, &prob->basisFace[f], &prob->basisDerFace[f], NULL);CHKERRQ(ierr); 3859de99aefSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 3869de99aefSMatthew G. Knepley PetscFV fv = (PetscFV) obj; 3879de99aefSMatthew G. Knepley 3889de99aefSMatthew G. Knepley ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr); 3899de99aefSMatthew G. Knepley ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr); 3909c3cf19fSMatthew G. Knepley Nb = Nc; 3916c1a3d01SMatthew G. Knepley ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr); 3924d0b9603SSander Arens /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */ 393abac5ca0SMatthew G. Knepley } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f); 39447e57110SSander Arens prob->Nc[f] = Nc; 39547e57110SSander Arens prob->Nb[f] = Nb; 396194d53e6SMatthew G. Knepley prob->off[f+1] = Nc + prob->off[f]; 397194d53e6SMatthew G. Knepley prob->offDer[f+1] = Nc*dim + prob->offDer[f]; 398a6b92713SMatthew G. Knepley if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);} 3992764a2aaSMatthew G. Knepley NqMax = PetscMax(NqMax, Nq); 4002764a2aaSMatthew G. Knepley NcMax = PetscMax(NcMax, Nc); 4019c3cf19fSMatthew G. Knepley prob->totDim += Nb; 4022764a2aaSMatthew G. Knepley prob->totComp += Nc; 40394a5e212SMatthew G. Knepley /* There are two faces for all fields but the cohesive field on a hybrid cell */ 40494a5e212SMatthew G. Knepley if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb; 4052764a2aaSMatthew G. Knepley } 4062764a2aaSMatthew G. Knepley work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim)); 4072764a2aaSMatthew G. Knepley /* Allocate works space */ 40894a5e212SMatthew G. Knepley if (prob->isHybrid) NsMax = 2; 40994a5e212SMatthew G. Knepley ierr = PetscMalloc5(NsMax*prob->totComp,&prob->u,NsMax*prob->totComp,&prob->u_t,NsMax*prob->totComp*dimEmbed,&prob->u_x,dimEmbed,&prob->x,work,&prob->refSpaceDer);CHKERRQ(ierr); 41094a5e212SMatthew G. Knepley ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dim,&prob->f1, 41194a5e212SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dim,&prob->g1, 41294a5e212SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax*dim,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dim*dim,&prob->g3);CHKERRQ(ierr); 4132764a2aaSMatthew G. Knepley if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);} 4142764a2aaSMatthew G. Knepley prob->setup = PETSC_TRUE; 4152764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4162764a2aaSMatthew G. Knepley } 4172764a2aaSMatthew G. Knepley 4182764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob) 4192764a2aaSMatthew G. Knepley { 4202764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4212764a2aaSMatthew G. Knepley 4222764a2aaSMatthew G. Knepley PetscFunctionBegin; 42347e57110SSander Arens ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr); 424f744cafaSSander Arens ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr); 425f744cafaSSander Arens ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisFace,prob->basisDerFace);CHKERRQ(ierr); 4262764a2aaSMatthew G. Knepley ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr); 4272764a2aaSMatthew G. Knepley ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr); 4282764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4292764a2aaSMatthew G. Knepley } 4302764a2aaSMatthew G. Knepley 4312764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew) 4322764a2aaSMatthew G. Knepley { 433f744cafaSSander Arens PetscObject *tmpd; 434a6cbbb48SMatthew G. Knepley PetscBool *tmpi, *tmpa; 43532d2bbc9SMatthew G. Knepley PetscPointFunc *tmpobj, *tmpf, *tmpup; 436b7e05686SMatthew G. Knepley PetscPointJac *tmpg, *tmpgp, *tmpgt; 4372aa1fc23SMatthew G. Knepley PetscBdPointFunc *tmpfbd; 4382aa1fc23SMatthew G. Knepley PetscBdPointJac *tmpgbd; 439194d53e6SMatthew G. Knepley PetscRiemannFunc *tmpr; 440c371a6d1SMatthew G. Knepley PetscSimplePointFunc *tmpexactSol; 441*95cbbfd3SMatthew G. Knepley void **tmpexactCtx; 4420c2f2876SMatthew G. Knepley void **tmpctx; 443a6cbbb48SMatthew G. Knepley PetscInt Nf = prob->Nf, f, i; 4442764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4452764a2aaSMatthew G. Knepley 4462764a2aaSMatthew G. Knepley PetscFunctionBegin; 4472764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 4482764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 4492764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr); 450f744cafaSSander Arens ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr); 451f744cafaSSander Arens for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; for (i = 0; i < 2; ++i) tmpa[f*2+i] = prob->adjacency[f*2+i];} 452f744cafaSSander Arens for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpa[f*2+0] = PETSC_FALSE; tmpa[f*2+1] = PETSC_TRUE;} 453f744cafaSSander Arens ierr = PetscFree3(prob->disc, prob->implicit, prob->adjacency);CHKERRQ(ierr); 4542764a2aaSMatthew G. Knepley prob->Nf = NfNew; 4552764a2aaSMatthew G. Knepley prob->disc = tmpd; 456249df284SMatthew G. Knepley prob->implicit = tmpi; 457a6cbbb48SMatthew G. Knepley prob->adjacency = tmpa; 458b7e05686SMatthew G. Knepley ierr = PetscCalloc7(NfNew, &tmpobj, NfNew*2, &tmpf, NfNew*NfNew*4, &tmpg, NfNew*NfNew*4, &tmpgp, NfNew*NfNew*4, &tmpgt, NfNew, &tmpr, NfNew, &tmpctx);CHKERRQ(ierr); 45932d2bbc9SMatthew G. Knepley ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr); 4602764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f]; 4612764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f]; 4622764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f]; 463475e0ac9SMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f]; 4640c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f]; 46532d2bbc9SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f]; 4660c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f]; 4672764a2aaSMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL; 4682764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL; 4692764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL; 470475e0ac9SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL; 471b7e05686SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL; 4720c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL; 47332d2bbc9SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL; 4740c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL; 475b7e05686SMatthew G. Knepley ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr); 47632d2bbc9SMatthew G. Knepley ierr = PetscFree(prob->update);CHKERRQ(ierr); 4772764a2aaSMatthew G. Knepley prob->obj = tmpobj; 4782764a2aaSMatthew G. Knepley prob->f = tmpf; 4792764a2aaSMatthew G. Knepley prob->g = tmpg; 480475e0ac9SMatthew G. Knepley prob->gp = tmpgp; 481b7e05686SMatthew G. Knepley prob->gt = tmpgt; 4820c2f2876SMatthew G. Knepley prob->r = tmpr; 48332d2bbc9SMatthew G. Knepley prob->update = tmpup; 4840c2f2876SMatthew G. Knepley prob->ctx = tmpctx; 485*95cbbfd3SMatthew G. Knepley ierr = PetscCalloc4(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew, &tmpexactSol, NfNew, &tmpexactCtx);CHKERRQ(ierr); 4862764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f]; 4872764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f]; 488c371a6d1SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f]; 489*95cbbfd3SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f]; 4902764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL; 4912764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL; 492c371a6d1SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL; 493*95cbbfd3SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL; 494*95cbbfd3SMatthew G. Knepley ierr = PetscFree4(prob->fBd, prob->gBd, prob->exactSol, prob->exactCtx);CHKERRQ(ierr); 4952764a2aaSMatthew G. Knepley prob->fBd = tmpfbd; 4962764a2aaSMatthew G. Knepley prob->gBd = tmpgbd; 497c371a6d1SMatthew G. Knepley prob->exactSol = tmpexactSol; 498*95cbbfd3SMatthew G. Knepley prob->exactCtx = tmpexactCtx; 4992764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5002764a2aaSMatthew G. Knepley } 5012764a2aaSMatthew G. Knepley 5022764a2aaSMatthew G. Knepley /*@ 5032764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 5042764a2aaSMatthew G. Knepley 5052764a2aaSMatthew G. Knepley Collective on PetscDS 5062764a2aaSMatthew G. Knepley 5072764a2aaSMatthew G. Knepley Input Parameter: 5082764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 5092764a2aaSMatthew G. Knepley 5102764a2aaSMatthew G. Knepley Level: developer 5112764a2aaSMatthew G. Knepley 5122764a2aaSMatthew G. Knepley .seealso PetscDSView() 5132764a2aaSMatthew G. Knepley @*/ 5142764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob) 5152764a2aaSMatthew G. Knepley { 5162764a2aaSMatthew G. Knepley PetscInt f; 51758ebd649SToby Isaac DSBoundary next; 5182764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5192764a2aaSMatthew G. Knepley 5202764a2aaSMatthew G. Knepley PetscFunctionBegin; 5212764a2aaSMatthew G. Knepley if (!*prob) PetscFunctionReturn(0); 5222764a2aaSMatthew G. Knepley PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1); 5232764a2aaSMatthew G. Knepley 5242764a2aaSMatthew G. Knepley if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);} 5252764a2aaSMatthew G. Knepley ((PetscObject) (*prob))->refct = 0; 526df3a45bdSMatthew G. Knepley if ((*prob)->subprobs) { 527df3a45bdSMatthew G. Knepley PetscInt dim, d; 528df3a45bdSMatthew G. Knepley 529df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(*prob, &dim);CHKERRQ(ierr); 530df3a45bdSMatthew G. Knepley for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*prob)->subprobs[d]);CHKERRQ(ierr);} 531df3a45bdSMatthew G. Knepley } 532df3a45bdSMatthew G. Knepley ierr = PetscFree((*prob)->subprobs);CHKERRQ(ierr); 5332764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr); 5342764a2aaSMatthew G. Knepley for (f = 0; f < (*prob)->Nf; ++f) { 5352764a2aaSMatthew G. Knepley ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr); 5362764a2aaSMatthew G. Knepley } 537f744cafaSSander Arens ierr = PetscFree3((*prob)->disc, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr); 538b7e05686SMatthew G. Knepley ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr); 53932d2bbc9SMatthew G. Knepley ierr = PetscFree((*prob)->update);CHKERRQ(ierr); 540*95cbbfd3SMatthew G. Knepley ierr = PetscFree4((*prob)->fBd,(*prob)->gBd,(*prob)->exactSol,(*prob)->exactCtx);CHKERRQ(ierr); 5412764a2aaSMatthew G. Knepley if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);} 54258ebd649SToby Isaac next = (*prob)->boundary; 54358ebd649SToby Isaac while (next) { 54458ebd649SToby Isaac DSBoundary b = next; 54558ebd649SToby Isaac 54658ebd649SToby Isaac next = b->next; 54758ebd649SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 54858ebd649SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 54958ebd649SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 55058ebd649SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 55158ebd649SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 55258ebd649SToby Isaac } 55397b6e6e8SMatthew G. Knepley ierr = PetscFree((*prob)->constants);CHKERRQ(ierr); 5542764a2aaSMatthew G. Knepley ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr); 5552764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5562764a2aaSMatthew G. Knepley } 5572764a2aaSMatthew G. Knepley 5582764a2aaSMatthew G. Knepley /*@ 5592764a2aaSMatthew G. Knepley PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType(). 5602764a2aaSMatthew G. Knepley 5612764a2aaSMatthew G. Knepley Collective on MPI_Comm 5622764a2aaSMatthew G. Knepley 5632764a2aaSMatthew G. Knepley Input Parameter: 5642764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object 5652764a2aaSMatthew G. Knepley 5662764a2aaSMatthew G. Knepley Output Parameter: 5672764a2aaSMatthew G. Knepley . prob - The PetscDS object 5682764a2aaSMatthew G. Knepley 5692764a2aaSMatthew G. Knepley Level: beginner 5702764a2aaSMatthew G. Knepley 5712764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC 5722764a2aaSMatthew G. Knepley @*/ 5732764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob) 5742764a2aaSMatthew G. Knepley { 5752764a2aaSMatthew G. Knepley PetscDS p; 5762764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5772764a2aaSMatthew G. Knepley 5782764a2aaSMatthew G. Knepley PetscFunctionBegin; 5792764a2aaSMatthew G. Knepley PetscValidPointer(prob, 2); 5802764a2aaSMatthew G. Knepley *prob = NULL; 5812764a2aaSMatthew G. Knepley ierr = PetscDSInitializePackage();CHKERRQ(ierr); 5822764a2aaSMatthew G. Knepley 58373107ff1SLisandro Dalcin ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr); 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; 59003d90f89SMatthew G. Knepley p->defaultAdj[0] = PETSC_FALSE; 59103d90f89SMatthew G. Knepley p->defaultAdj[1] = PETSC_TRUE; 59255c1f793SMatthew G. Knepley p->useJacPre = PETSC_TRUE; 5932764a2aaSMatthew G. Knepley 5942764a2aaSMatthew G. Knepley *prob = p; 5952764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5962764a2aaSMatthew G. Knepley } 5972764a2aaSMatthew G. Knepley 598bc4ae4beSMatthew G. Knepley /*@ 599bc4ae4beSMatthew G. Knepley PetscDSGetNumFields - Returns the number of fields in the DS 600bc4ae4beSMatthew G. Knepley 601bc4ae4beSMatthew G. Knepley Not collective 602bc4ae4beSMatthew G. Knepley 603bc4ae4beSMatthew G. Knepley Input Parameter: 604bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 605bc4ae4beSMatthew G. Knepley 606bc4ae4beSMatthew G. Knepley Output Parameter: 607bc4ae4beSMatthew G. Knepley . Nf - The number of fields 608bc4ae4beSMatthew G. Knepley 609bc4ae4beSMatthew G. Knepley Level: beginner 610bc4ae4beSMatthew G. Knepley 611bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate() 612bc4ae4beSMatthew G. Knepley @*/ 6132764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) 6142764a2aaSMatthew G. Knepley { 6152764a2aaSMatthew G. Knepley PetscFunctionBegin; 6162764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6172764a2aaSMatthew G. Knepley PetscValidPointer(Nf, 2); 6182764a2aaSMatthew G. Knepley *Nf = prob->Nf; 6192764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6202764a2aaSMatthew G. Knepley } 6212764a2aaSMatthew G. Knepley 622bc4ae4beSMatthew G. Knepley /*@ 623a859676bSMatthew G. Knepley PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations 624bc4ae4beSMatthew G. Knepley 625bc4ae4beSMatthew G. Knepley Not collective 626bc4ae4beSMatthew G. Knepley 627bc4ae4beSMatthew G. Knepley Input Parameter: 628bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 629bc4ae4beSMatthew G. Knepley 630bc4ae4beSMatthew G. Knepley Output Parameter: 631bc4ae4beSMatthew G. Knepley . dim - The spatial dimension 632bc4ae4beSMatthew G. Knepley 633bc4ae4beSMatthew G. Knepley Level: beginner 634bc4ae4beSMatthew G. Knepley 635a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate() 636bc4ae4beSMatthew G. Knepley @*/ 6372764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) 6382764a2aaSMatthew G. Knepley { 6392764a2aaSMatthew G. Knepley PetscErrorCode ierr; 6402764a2aaSMatthew G. Knepley 6412764a2aaSMatthew G. Knepley PetscFunctionBegin; 6422764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6432764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 6442764a2aaSMatthew G. Knepley *dim = 0; 6459de99aefSMatthew G. Knepley if (prob->Nf) { 6469de99aefSMatthew G. Knepley PetscObject obj; 6479de99aefSMatthew G. Knepley PetscClassId id; 6489de99aefSMatthew G. Knepley 6499de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 6509de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 6519de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);} 6529de99aefSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);} 6539de99aefSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 6549de99aefSMatthew G. Knepley } 6552764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6562764a2aaSMatthew G. Knepley } 6572764a2aaSMatthew G. Knepley 658bc4ae4beSMatthew G. Knepley /*@ 659a859676bSMatthew G. Knepley PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 660a859676bSMatthew G. Knepley 661a859676bSMatthew G. Knepley Not collective 662a859676bSMatthew G. Knepley 663a859676bSMatthew G. Knepley Input Parameter: 664a859676bSMatthew G. Knepley . prob - The PetscDS object 665a859676bSMatthew G. Knepley 666a859676bSMatthew G. Knepley Output Parameter: 667a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension 668a859676bSMatthew G. Knepley 669a859676bSMatthew G. Knepley Level: beginner 670a859676bSMatthew G. Knepley 671a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 672a859676bSMatthew G. Knepley @*/ 673a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed) 674a859676bSMatthew G. Knepley { 675a859676bSMatthew G. Knepley PetscFunctionBegin; 676a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 677a859676bSMatthew G. Knepley PetscValidPointer(dimEmbed, 2); 678a859676bSMatthew G. Knepley if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS"); 679a859676bSMatthew G. Knepley *dimEmbed = prob->dimEmbed; 680a859676bSMatthew G. Knepley PetscFunctionReturn(0); 681a859676bSMatthew G. Knepley } 682a859676bSMatthew G. Knepley 683a859676bSMatthew G. Knepley /*@ 684a859676bSMatthew G. Knepley PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 685a859676bSMatthew G. Knepley 686ebfe4b0dSMatthew G. Knepley Logically collective on DS 687a859676bSMatthew G. Knepley 688a859676bSMatthew G. Knepley Input Parameters: 689a859676bSMatthew G. Knepley + prob - The PetscDS object 690a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension 691a859676bSMatthew G. Knepley 692a859676bSMatthew G. Knepley Level: beginner 693a859676bSMatthew G. Knepley 694a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 695a859676bSMatthew G. Knepley @*/ 696a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed) 697a859676bSMatthew G. Knepley { 698a859676bSMatthew G. Knepley PetscFunctionBegin; 699a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 700ebfe4b0dSMatthew G. Knepley if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed); 701a859676bSMatthew G. Knepley prob->dimEmbed = dimEmbed; 702a859676bSMatthew G. Knepley PetscFunctionReturn(0); 703a859676bSMatthew G. Knepley } 704a859676bSMatthew G. Knepley 705a859676bSMatthew G. Knepley /*@ 7068edf6225SMatthew G. Knepley PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell 7078edf6225SMatthew G. Knepley 7088edf6225SMatthew G. Knepley Not collective 7098edf6225SMatthew G. Knepley 7108edf6225SMatthew G. Knepley Input Parameter: 7118edf6225SMatthew G. Knepley . prob - The PetscDS object 7128edf6225SMatthew G. Knepley 7138edf6225SMatthew G. Knepley Output Parameter: 7148edf6225SMatthew G. Knepley . isHybrid - The flag 7158edf6225SMatthew G. Knepley 7168edf6225SMatthew G. Knepley Level: developer 7178edf6225SMatthew G. Knepley 7188edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate() 7198edf6225SMatthew G. Knepley @*/ 7208edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid) 7218edf6225SMatthew G. Knepley { 7228edf6225SMatthew G. Knepley PetscFunctionBegin; 7238edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7248edf6225SMatthew G. Knepley PetscValidPointer(isHybrid, 2); 7258edf6225SMatthew G. Knepley *isHybrid = prob->isHybrid; 7268edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7278edf6225SMatthew G. Knepley } 7288edf6225SMatthew G. Knepley 7298edf6225SMatthew G. Knepley /*@ 7308edf6225SMatthew G. Knepley PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell 7318edf6225SMatthew G. Knepley 7328edf6225SMatthew G. Knepley Not collective 7338edf6225SMatthew G. Knepley 7348edf6225SMatthew G. Knepley Input Parameters: 7358edf6225SMatthew G. Knepley + prob - The PetscDS object 7368edf6225SMatthew G. Knepley - isHybrid - The flag 7378edf6225SMatthew G. Knepley 7388edf6225SMatthew G. Knepley Level: developer 7398edf6225SMatthew G. Knepley 7408edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate() 7418edf6225SMatthew G. Knepley @*/ 7428edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid) 7438edf6225SMatthew G. Knepley { 7448edf6225SMatthew G. Knepley PetscFunctionBegin; 7458edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7468edf6225SMatthew G. Knepley prob->isHybrid = isHybrid; 7478edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7488edf6225SMatthew G. Knepley } 7498edf6225SMatthew G. Knepley 7508edf6225SMatthew G. Knepley /*@ 751bc4ae4beSMatthew G. Knepley PetscDSGetTotalDimension - Returns the total size of the approximation space for this system 752bc4ae4beSMatthew G. Knepley 753bc4ae4beSMatthew G. Knepley Not collective 754bc4ae4beSMatthew G. Knepley 755bc4ae4beSMatthew G. Knepley Input Parameter: 756bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 757bc4ae4beSMatthew G. Knepley 758bc4ae4beSMatthew G. Knepley Output Parameter: 759bc4ae4beSMatthew G. Knepley . dim - The total problem dimension 760bc4ae4beSMatthew G. Knepley 761bc4ae4beSMatthew G. Knepley Level: beginner 762bc4ae4beSMatthew G. Knepley 763bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 764bc4ae4beSMatthew G. Knepley @*/ 7652764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) 7662764a2aaSMatthew G. Knepley { 7672764a2aaSMatthew G. Knepley PetscErrorCode ierr; 7682764a2aaSMatthew G. Knepley 7692764a2aaSMatthew G. Knepley PetscFunctionBegin; 7702764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7712764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 7722764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 7732764a2aaSMatthew G. Knepley *dim = prob->totDim; 7742764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 7752764a2aaSMatthew G. Knepley } 7762764a2aaSMatthew G. Knepley 777bc4ae4beSMatthew G. Knepley /*@ 778bc4ae4beSMatthew G. Knepley PetscDSGetTotalComponents - Returns the total number of components in this system 779bc4ae4beSMatthew G. Knepley 780bc4ae4beSMatthew G. Knepley Not collective 781bc4ae4beSMatthew G. Knepley 782bc4ae4beSMatthew G. Knepley Input Parameter: 783bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 784bc4ae4beSMatthew G. Knepley 785bc4ae4beSMatthew G. Knepley Output Parameter: 786bc4ae4beSMatthew G. Knepley . dim - The total number of components 787bc4ae4beSMatthew G. Knepley 788bc4ae4beSMatthew G. Knepley Level: beginner 789bc4ae4beSMatthew G. Knepley 790bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 791bc4ae4beSMatthew G. Knepley @*/ 7922764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) 7932764a2aaSMatthew G. Knepley { 7942764a2aaSMatthew G. Knepley PetscErrorCode ierr; 7952764a2aaSMatthew G. Knepley 7962764a2aaSMatthew G. Knepley PetscFunctionBegin; 7972764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7982764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 7992764a2aaSMatthew G. Knepley PetscValidPointer(Nc, 2); 8002764a2aaSMatthew G. Knepley *Nc = prob->totComp; 8012764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8022764a2aaSMatthew G. Knepley } 8032764a2aaSMatthew G. Knepley 804bc4ae4beSMatthew G. Knepley /*@ 805bc4ae4beSMatthew G. Knepley PetscDSGetDiscretization - Returns the discretization object for the given field 806bc4ae4beSMatthew G. Knepley 807bc4ae4beSMatthew G. Knepley Not collective 808bc4ae4beSMatthew G. Knepley 809bc4ae4beSMatthew G. Knepley Input Parameters: 810bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 811bc4ae4beSMatthew G. Knepley - f - The field number 812bc4ae4beSMatthew G. Knepley 813bc4ae4beSMatthew G. Knepley Output Parameter: 814bc4ae4beSMatthew G. Knepley . disc - The discretization object 815bc4ae4beSMatthew G. Knepley 816bc4ae4beSMatthew G. Knepley Level: beginner 817bc4ae4beSMatthew G. Knepley 818f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 819bc4ae4beSMatthew G. Knepley @*/ 8202764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 8212764a2aaSMatthew G. Knepley { 8222764a2aaSMatthew G. Knepley PetscFunctionBegin; 8232764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8242764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 8252764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 8262764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 8272764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8282764a2aaSMatthew G. Knepley } 8292764a2aaSMatthew G. Knepley 830bc4ae4beSMatthew G. Knepley /*@ 831bc4ae4beSMatthew G. Knepley PetscDSSetDiscretization - Sets the discretization object for the given field 832bc4ae4beSMatthew G. Knepley 833bc4ae4beSMatthew G. Knepley Not collective 834bc4ae4beSMatthew G. Knepley 835bc4ae4beSMatthew G. Knepley Input Parameters: 836bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 837bc4ae4beSMatthew G. Knepley . f - The field number 838bc4ae4beSMatthew G. Knepley - disc - The discretization object 839bc4ae4beSMatthew G. Knepley 840bc4ae4beSMatthew G. Knepley Level: beginner 841bc4ae4beSMatthew G. Knepley 842bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 843bc4ae4beSMatthew G. Knepley @*/ 8442764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 8452764a2aaSMatthew G. Knepley { 8462764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8472764a2aaSMatthew G. Knepley 8482764a2aaSMatthew G. Knepley PetscFunctionBegin; 8492764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8502764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 8512764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 8522764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 853c10f2116SMatthew G. Knepley ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr); 8542764a2aaSMatthew G. Knepley prob->disc[f] = disc; 8552764a2aaSMatthew G. Knepley ierr = PetscObjectReference(disc);CHKERRQ(ierr); 856249df284SMatthew G. Knepley { 857249df284SMatthew G. Knepley PetscClassId id; 858249df284SMatthew G. Knepley 859249df284SMatthew G. Knepley ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr); 8601cf84007SMatthew G. Knepley if (id == PETSCFE_CLASSID) { 8611cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr); 8621cf84007SMatthew G. Knepley ierr = PetscDSSetAdjacency(prob, f, PETSC_FALSE, PETSC_TRUE);CHKERRQ(ierr); 8631cf84007SMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 8641cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr); 8651cf84007SMatthew G. Knepley ierr = PetscDSSetAdjacency(prob, f, PETSC_TRUE, PETSC_FALSE);CHKERRQ(ierr); 866a6cbbb48SMatthew G. Knepley } 867249df284SMatthew G. Knepley } 8682764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8692764a2aaSMatthew G. Knepley } 8702764a2aaSMatthew G. Knepley 871bc4ae4beSMatthew G. Knepley /*@ 872bc4ae4beSMatthew G. Knepley PetscDSAddDiscretization - Adds a discretization object 873bc4ae4beSMatthew G. Knepley 874bc4ae4beSMatthew G. Knepley Not collective 875bc4ae4beSMatthew G. Knepley 876bc4ae4beSMatthew G. Knepley Input Parameters: 877bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 878bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object 879bc4ae4beSMatthew G. Knepley 880bc4ae4beSMatthew G. Knepley Level: beginner 881bc4ae4beSMatthew G. Knepley 882bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 883bc4ae4beSMatthew G. Knepley @*/ 8842764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) 8852764a2aaSMatthew G. Knepley { 8862764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8872764a2aaSMatthew G. Knepley 8882764a2aaSMatthew G. Knepley PetscFunctionBegin; 8892764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr); 8902764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8912764a2aaSMatthew G. Knepley } 8922764a2aaSMatthew G. Knepley 893249df284SMatthew G. Knepley /*@ 894249df284SMatthew G. Knepley PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX 895249df284SMatthew G. Knepley 896249df284SMatthew G. Knepley Not collective 897249df284SMatthew G. Knepley 898249df284SMatthew G. Knepley Input Parameters: 899249df284SMatthew G. Knepley + prob - The PetscDS object 900249df284SMatthew G. Knepley - f - The field number 901249df284SMatthew G. Knepley 902249df284SMatthew G. Knepley Output Parameter: 903249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field 904249df284SMatthew G. Knepley 905249df284SMatthew G. Knepley Level: developer 906249df284SMatthew G. Knepley 907f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 908249df284SMatthew G. Knepley @*/ 909249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit) 910249df284SMatthew G. Knepley { 911249df284SMatthew G. Knepley PetscFunctionBegin; 912249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 913249df284SMatthew G. Knepley PetscValidPointer(implicit, 3); 914249df284SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 915249df284SMatthew G. Knepley *implicit = prob->implicit[f]; 916249df284SMatthew G. Knepley PetscFunctionReturn(0); 917249df284SMatthew G. Knepley } 918249df284SMatthew G. Knepley 919249df284SMatthew G. Knepley /*@ 920249df284SMatthew G. Knepley PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX 921249df284SMatthew G. Knepley 922249df284SMatthew G. Knepley Not collective 923249df284SMatthew G. Knepley 924249df284SMatthew G. Knepley Input Parameters: 925249df284SMatthew G. Knepley + prob - The PetscDS object 926249df284SMatthew G. Knepley . f - The field number 927249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field 928249df284SMatthew G. Knepley 929249df284SMatthew G. Knepley Level: developer 930249df284SMatthew G. Knepley 931f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 932249df284SMatthew G. Knepley @*/ 933249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit) 934249df284SMatthew G. Knepley { 935249df284SMatthew G. Knepley PetscFunctionBegin; 936249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 937249df284SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 938249df284SMatthew G. Knepley prob->implicit[f] = implicit; 939249df284SMatthew G. Knepley PetscFunctionReturn(0); 940249df284SMatthew G. Knepley } 941249df284SMatthew G. Knepley 942a6cbbb48SMatthew G. Knepley /*@ 943a6cbbb48SMatthew G. Knepley PetscDSGetAdjacency - Returns the flags for determining variable influence 944a6cbbb48SMatthew G. Knepley 945a6cbbb48SMatthew G. Knepley Not collective 946a6cbbb48SMatthew G. Knepley 947a6cbbb48SMatthew G. Knepley Input Parameters: 948a6cbbb48SMatthew G. Knepley + prob - The PetscDS object 949a6cbbb48SMatthew G. Knepley - f - The field number 950a6cbbb48SMatthew G. Knepley 951a6cbbb48SMatthew G. Knepley Output Parameter: 952a6cbbb48SMatthew G. Knepley + useCone - Flag for variable influence starting with the cone operation 953a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure 954a6cbbb48SMatthew G. Knepley 955a6cbbb48SMatthew G. Knepley Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure() 956a6cbbb48SMatthew G. Knepley 957a6cbbb48SMatthew G. Knepley Level: developer 958a6cbbb48SMatthew G. Knepley 959f744cafaSSander Arens .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 960a6cbbb48SMatthew G. Knepley @*/ 961a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure) 962a6cbbb48SMatthew G. Knepley { 963a6cbbb48SMatthew G. Knepley PetscFunctionBegin; 964a6cbbb48SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 9651cf84007SMatthew G. Knepley if (useCone) PetscValidPointer(useCone, 3); 9661cf84007SMatthew G. Knepley if (useClosure) PetscValidPointer(useClosure, 4); 96706cc46feSMatthew G. Knepley if (f < 0) { 96806cc46feSMatthew G. Knepley if (useCone) *useCone = prob->defaultAdj[0]; 96906cc46feSMatthew G. Knepley if (useClosure) *useClosure = prob->defaultAdj[1]; 97006cc46feSMatthew G. Knepley } else { 97106cc46feSMatthew G. Knepley if (f >= prob->Nf) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 9721cf84007SMatthew G. Knepley if (useCone) *useCone = prob->adjacency[f*2+0]; 9731cf84007SMatthew G. Knepley if (useClosure) *useClosure = prob->adjacency[f*2+1]; 97406cc46feSMatthew G. Knepley } 975a6cbbb48SMatthew G. Knepley PetscFunctionReturn(0); 976a6cbbb48SMatthew G. Knepley } 977a6cbbb48SMatthew G. Knepley 978a6cbbb48SMatthew G. Knepley /*@ 979a6cbbb48SMatthew G. Knepley PetscDSSetAdjacency - Set the flags for determining variable influence 980a6cbbb48SMatthew G. Knepley 981a6cbbb48SMatthew G. Knepley Not collective 982a6cbbb48SMatthew G. Knepley 983a6cbbb48SMatthew G. Knepley Input Parameters: 984a6cbbb48SMatthew G. Knepley + prob - The PetscDS object 985a6cbbb48SMatthew G. Knepley . f - The field number 986a6cbbb48SMatthew G. Knepley . useCone - Flag for variable influence starting with the cone operation 987a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure 988a6cbbb48SMatthew G. Knepley 989a6cbbb48SMatthew G. Knepley Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure() 990a6cbbb48SMatthew G. Knepley 991a6cbbb48SMatthew G. Knepley Level: developer 992a6cbbb48SMatthew G. Knepley 993f744cafaSSander Arens .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 994a6cbbb48SMatthew G. Knepley @*/ 995a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure) 996a6cbbb48SMatthew G. Knepley { 997a6cbbb48SMatthew G. Knepley PetscFunctionBegin; 998a6cbbb48SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 99906cc46feSMatthew G. Knepley if (f < 0) { 100006cc46feSMatthew G. Knepley prob->defaultAdj[0] = useCone; 100106cc46feSMatthew G. Knepley prob->defaultAdj[1] = useClosure; 100206cc46feSMatthew G. Knepley } else { 100306cc46feSMatthew G. Knepley if (f >= prob->Nf) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 1004a6cbbb48SMatthew G. Knepley prob->adjacency[f*2+0] = useCone; 1005a6cbbb48SMatthew G. Knepley prob->adjacency[f*2+1] = useClosure; 100606cc46feSMatthew G. Knepley } 1007a6cbbb48SMatthew G. Knepley PetscFunctionReturn(0); 1008a6cbbb48SMatthew G. Knepley } 1009a6cbbb48SMatthew G. Knepley 10102764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f, 101130b9ff8bSMatthew G. Knepley void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1012194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1013194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 101497b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 10152764a2aaSMatthew G. Knepley { 10162764a2aaSMatthew G. Knepley PetscFunctionBegin; 10172764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 10182764a2aaSMatthew G. Knepley PetscValidPointer(obj, 2); 10192764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 10202764a2aaSMatthew G. Knepley *obj = prob->obj[f]; 10212764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10222764a2aaSMatthew G. Knepley } 10232764a2aaSMatthew G. Knepley 10242764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f, 102530b9ff8bSMatthew G. Knepley void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1026194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1027194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 102897b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 10292764a2aaSMatthew G. Knepley { 10302764a2aaSMatthew G. Knepley PetscErrorCode ierr; 10312764a2aaSMatthew G. Knepley 10322764a2aaSMatthew G. Knepley PetscFunctionBegin; 10332764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1034de716cbcSToby Isaac if (obj) PetscValidFunction(obj, 2); 10352764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 10362764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 10372764a2aaSMatthew G. Knepley prob->obj[f] = obj; 10382764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10392764a2aaSMatthew G. Knepley } 10402764a2aaSMatthew G. Knepley 1041194d53e6SMatthew G. Knepley /*@C 1042194d53e6SMatthew G. Knepley PetscDSGetResidual - Get the pointwise residual function for a given test field 1043194d53e6SMatthew G. Knepley 1044194d53e6SMatthew G. Knepley Not collective 1045194d53e6SMatthew G. Knepley 1046194d53e6SMatthew G. Knepley Input Parameters: 1047194d53e6SMatthew G. Knepley + prob - The PetscDS 1048194d53e6SMatthew G. Knepley - f - The test field number 1049194d53e6SMatthew G. Knepley 1050194d53e6SMatthew G. Knepley Output Parameters: 1051194d53e6SMatthew G. Knepley + f0 - integrand for the test function term 1052194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1053194d53e6SMatthew G. Knepley 1054194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1055194d53e6SMatthew G. Knepley 1056194d53e6SMatthew 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) 1057194d53e6SMatthew G. Knepley 1058194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1059194d53e6SMatthew G. Knepley 106030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1061194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1062194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 106330b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1064194d53e6SMatthew G. Knepley 1065194d53e6SMatthew G. Knepley + dim - the spatial dimension 1066194d53e6SMatthew G. Knepley . Nf - the number of fields 1067194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1068194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1069194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1070194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1071194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1072194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1073194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1074194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1075194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1076194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1077194d53e6SMatthew G. Knepley . t - current time 1078194d53e6SMatthew G. Knepley . x - coordinates of the current point 107997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 108097b6e6e8SMatthew G. Knepley . constants - constant parameters 1081194d53e6SMatthew G. Knepley - f0 - output values at the current point 1082194d53e6SMatthew G. Knepley 1083194d53e6SMatthew G. Knepley Level: intermediate 1084194d53e6SMatthew G. Knepley 1085194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual() 1086194d53e6SMatthew G. Knepley @*/ 10872764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f, 108830b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1089194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1090194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 109197b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 109230b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1093194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1094194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 109597b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 10962764a2aaSMatthew G. Knepley { 10972764a2aaSMatthew G. Knepley PetscFunctionBegin; 10982764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 10992764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 11002764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];} 11012764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];} 11022764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11032764a2aaSMatthew G. Knepley } 11042764a2aaSMatthew G. Knepley 1105194d53e6SMatthew G. Knepley /*@C 1106194d53e6SMatthew G. Knepley PetscDSSetResidual - Set the pointwise residual function for a given test field 1107194d53e6SMatthew G. Knepley 1108194d53e6SMatthew G. Knepley Not collective 1109194d53e6SMatthew G. Knepley 1110194d53e6SMatthew G. Knepley Input Parameters: 1111194d53e6SMatthew G. Knepley + prob - The PetscDS 1112194d53e6SMatthew G. Knepley . f - The test field number 1113194d53e6SMatthew G. Knepley . f0 - integrand for the test function term 1114194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1115194d53e6SMatthew G. Knepley 1116194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1117194d53e6SMatthew G. Knepley 1118194d53e6SMatthew 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) 1119194d53e6SMatthew G. Knepley 1120194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1121194d53e6SMatthew G. Knepley 112230b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1123194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1124194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 112530b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1126194d53e6SMatthew G. Knepley 1127194d53e6SMatthew G. Knepley + dim - the spatial dimension 1128194d53e6SMatthew G. Knepley . Nf - the number of fields 1129194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1130194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1131194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1132194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1133194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1134194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1135194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1136194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1137194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1138194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1139194d53e6SMatthew G. Knepley . t - current time 1140194d53e6SMatthew G. Knepley . x - coordinates of the current point 114197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 114297b6e6e8SMatthew G. Knepley . constants - constant parameters 1143194d53e6SMatthew G. Knepley - f0 - output values at the current point 1144194d53e6SMatthew G. Knepley 1145194d53e6SMatthew G. Knepley Level: intermediate 1146194d53e6SMatthew G. Knepley 1147194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual() 1148194d53e6SMatthew G. Knepley @*/ 11492764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f, 115030b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1151194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1152194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 115397b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 115430b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1155194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1156194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 115797b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 11582764a2aaSMatthew G. Knepley { 11592764a2aaSMatthew G. Knepley PetscErrorCode ierr; 11602764a2aaSMatthew G. Knepley 11612764a2aaSMatthew G. Knepley PetscFunctionBegin; 11622764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1163f866a1d0SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1164f866a1d0SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 11652764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 11662764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 11672764a2aaSMatthew G. Knepley prob->f[f*2+0] = f0; 11682764a2aaSMatthew G. Knepley prob->f[f*2+1] = f1; 11692764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11702764a2aaSMatthew G. Knepley } 11712764a2aaSMatthew G. Knepley 11723e75805dSMatthew G. Knepley /*@C 11733e75805dSMatthew G. Knepley PetscDSHasJacobian - Signals that Jacobian functions have been set 11743e75805dSMatthew G. Knepley 11753e75805dSMatthew G. Knepley Not collective 11763e75805dSMatthew G. Knepley 11773e75805dSMatthew G. Knepley Input Parameter: 11783e75805dSMatthew G. Knepley . prob - The PetscDS 11793e75805dSMatthew G. Knepley 11803e75805dSMatthew G. Knepley Output Parameter: 11813e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set 11823e75805dSMatthew G. Knepley 11833e75805dSMatthew G. Knepley Level: intermediate 11843e75805dSMatthew G. Knepley 11853e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 11863e75805dSMatthew G. Knepley @*/ 11873e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac) 11883e75805dSMatthew G. Knepley { 11893e75805dSMatthew G. Knepley PetscInt f, g, h; 11903e75805dSMatthew G. Knepley 11913e75805dSMatthew G. Knepley PetscFunctionBegin; 11923e75805dSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 11933e75805dSMatthew G. Knepley *hasJac = PETSC_FALSE; 11943e75805dSMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 11953e75805dSMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 11963e75805dSMatthew G. Knepley for (h = 0; h < 4; ++h) { 11973e75805dSMatthew G. Knepley if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE; 11983e75805dSMatthew G. Knepley } 11993e75805dSMatthew G. Knepley } 12003e75805dSMatthew G. Knepley } 12013e75805dSMatthew G. Knepley PetscFunctionReturn(0); 12023e75805dSMatthew G. Knepley } 12033e75805dSMatthew G. Knepley 1204194d53e6SMatthew G. Knepley /*@C 1205194d53e6SMatthew G. Knepley PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field 1206194d53e6SMatthew G. Knepley 1207194d53e6SMatthew G. Knepley Not collective 1208194d53e6SMatthew G. Knepley 1209194d53e6SMatthew G. Knepley Input Parameters: 1210194d53e6SMatthew G. Knepley + prob - The PetscDS 1211194d53e6SMatthew G. Knepley . f - The test field number 1212194d53e6SMatthew G. Knepley - g - The field number 1213194d53e6SMatthew G. Knepley 1214194d53e6SMatthew G. Knepley Output Parameters: 1215194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1216194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1217194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1218194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1219194d53e6SMatthew G. Knepley 1220194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1221194d53e6SMatthew G. Knepley 1222194d53e6SMatthew 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 1223194d53e6SMatthew G. Knepley 1224194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1225194d53e6SMatthew G. Knepley 122630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1227194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1228194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 122930b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1230194d53e6SMatthew G. Knepley 1231194d53e6SMatthew G. Knepley + dim - the spatial dimension 1232194d53e6SMatthew G. Knepley . Nf - the number of fields 1233194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1234194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1235194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1236194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1237194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1238194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1239194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1240194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1241194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1242194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1243194d53e6SMatthew G. Knepley . t - current time 12442aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1245194d53e6SMatthew G. Knepley . x - coordinates of the current point 124697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 124797b6e6e8SMatthew G. Knepley . constants - constant parameters 1248194d53e6SMatthew G. Knepley - g0 - output values at the current point 1249194d53e6SMatthew G. Knepley 1250194d53e6SMatthew G. Knepley Level: intermediate 1251194d53e6SMatthew G. Knepley 1252194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1253194d53e6SMatthew G. Knepley @*/ 12542764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g, 125530b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1256194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1257194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 125897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 125930b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1260194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1261194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 126297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 126330b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1264194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1265194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 126697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 126730b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1268194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1269194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 127097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 12712764a2aaSMatthew G. Knepley { 12722764a2aaSMatthew G. Knepley PetscFunctionBegin; 12732764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 12742764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 12752764a2aaSMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 12762764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];} 12772764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];} 12782764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];} 12792764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];} 12802764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 12812764a2aaSMatthew G. Knepley } 12822764a2aaSMatthew G. Knepley 1283194d53e6SMatthew G. Knepley /*@C 1284194d53e6SMatthew G. Knepley PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields 1285194d53e6SMatthew G. Knepley 1286194d53e6SMatthew G. Knepley Not collective 1287194d53e6SMatthew G. Knepley 1288194d53e6SMatthew G. Knepley Input Parameters: 1289194d53e6SMatthew G. Knepley + prob - The PetscDS 1290194d53e6SMatthew G. Knepley . f - The test field number 1291194d53e6SMatthew G. Knepley . g - The field number 1292194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1293194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1294194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1295194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1296194d53e6SMatthew G. Knepley 1297194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1298194d53e6SMatthew G. Knepley 1299194d53e6SMatthew 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 1300194d53e6SMatthew G. Knepley 1301194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1302194d53e6SMatthew G. Knepley 130330b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1304194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1305194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 130630b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1307194d53e6SMatthew G. Knepley 1308194d53e6SMatthew G. Knepley + dim - the spatial dimension 1309194d53e6SMatthew G. Knepley . Nf - the number of fields 1310194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1311194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1312194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1313194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1314194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1315194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1316194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1317194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1318194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1319194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1320194d53e6SMatthew G. Knepley . t - current time 13212aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1322194d53e6SMatthew G. Knepley . x - coordinates of the current point 132397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 132497b6e6e8SMatthew G. Knepley . constants - constant parameters 1325194d53e6SMatthew G. Knepley - g0 - output values at the current point 1326194d53e6SMatthew G. Knepley 1327194d53e6SMatthew G. Knepley Level: intermediate 1328194d53e6SMatthew G. Knepley 1329194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1330194d53e6SMatthew G. Knepley @*/ 13312764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g, 133230b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1333194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1334194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 133597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 133630b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1337194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1338194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 133997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 134030b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1341194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1342194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 134397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 134430b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1345194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1346194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 134797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 13482764a2aaSMatthew G. Knepley { 13492764a2aaSMatthew G. Knepley PetscErrorCode ierr; 13502764a2aaSMatthew G. Knepley 13512764a2aaSMatthew G. Knepley PetscFunctionBegin; 13522764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13532764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 13542764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 13552764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 13562764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 13572764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 13582764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 13592764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 13602764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+0] = g0; 13612764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+1] = g1; 13622764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+2] = g2; 13632764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+3] = g3; 13642764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 13652764a2aaSMatthew G. Knepley } 13662764a2aaSMatthew G. Knepley 1367475e0ac9SMatthew G. Knepley /*@C 136855c1f793SMatthew G. Knepley PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner 136955c1f793SMatthew G. Knepley 137055c1f793SMatthew G. Knepley Not collective 137155c1f793SMatthew G. Knepley 137255c1f793SMatthew G. Knepley Input Parameters: 137355c1f793SMatthew G. Knepley + prob - The PetscDS 137455c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner 137555c1f793SMatthew G. Knepley 137655c1f793SMatthew G. Knepley Level: intermediate 137755c1f793SMatthew G. Knepley 137855c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 137955c1f793SMatthew G. Knepley @*/ 138055c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre) 138155c1f793SMatthew G. Knepley { 138255c1f793SMatthew G. Knepley PetscFunctionBegin; 138355c1f793SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 138455c1f793SMatthew G. Knepley prob->useJacPre = useJacPre; 138555c1f793SMatthew G. Knepley PetscFunctionReturn(0); 138655c1f793SMatthew G. Knepley } 138755c1f793SMatthew G. Knepley 138855c1f793SMatthew G. Knepley /*@C 1389475e0ac9SMatthew G. Knepley PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set 1390475e0ac9SMatthew G. Knepley 1391475e0ac9SMatthew G. Knepley Not collective 1392475e0ac9SMatthew G. Knepley 1393475e0ac9SMatthew G. Knepley Input Parameter: 1394475e0ac9SMatthew G. Knepley . prob - The PetscDS 1395475e0ac9SMatthew G. Knepley 1396475e0ac9SMatthew G. Knepley Output Parameter: 1397475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set 1398475e0ac9SMatthew G. Knepley 1399475e0ac9SMatthew G. Knepley Level: intermediate 1400475e0ac9SMatthew G. Knepley 1401475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1402475e0ac9SMatthew G. Knepley @*/ 1403475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre) 1404475e0ac9SMatthew G. Knepley { 1405475e0ac9SMatthew G. Knepley PetscInt f, g, h; 1406475e0ac9SMatthew G. Knepley 1407475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1408475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1409475e0ac9SMatthew G. Knepley *hasJacPre = PETSC_FALSE; 141055c1f793SMatthew G. Knepley if (!prob->useJacPre) PetscFunctionReturn(0); 1411475e0ac9SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1412475e0ac9SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1413475e0ac9SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1414475e0ac9SMatthew G. Knepley if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE; 1415475e0ac9SMatthew G. Knepley } 1416475e0ac9SMatthew G. Knepley } 1417475e0ac9SMatthew G. Knepley } 1418475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1419475e0ac9SMatthew G. Knepley } 1420475e0ac9SMatthew G. Knepley 1421475e0ac9SMatthew G. Knepley /*@C 1422475e0ac9SMatthew 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. 1423475e0ac9SMatthew G. Knepley 1424475e0ac9SMatthew G. Knepley Not collective 1425475e0ac9SMatthew G. Knepley 1426475e0ac9SMatthew G. Knepley Input Parameters: 1427475e0ac9SMatthew G. Knepley + prob - The PetscDS 1428475e0ac9SMatthew G. Knepley . f - The test field number 1429475e0ac9SMatthew G. Knepley - g - The field number 1430475e0ac9SMatthew G. Knepley 1431475e0ac9SMatthew G. Knepley Output Parameters: 1432475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term 1433475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1434475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1435475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1436475e0ac9SMatthew G. Knepley 1437475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1438475e0ac9SMatthew G. Knepley 1439475e0ac9SMatthew 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 1440475e0ac9SMatthew G. Knepley 1441475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1442475e0ac9SMatthew G. Knepley 1443475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1444475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1445475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1446475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1447475e0ac9SMatthew G. Knepley 1448475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1449475e0ac9SMatthew G. Knepley . Nf - the number of fields 1450475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1451475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1452475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1453475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1454475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1455475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1456475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1457475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1458475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1459475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1460475e0ac9SMatthew G. Knepley . t - current time 1461475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1462475e0ac9SMatthew G. Knepley . x - coordinates of the current point 146397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 146497b6e6e8SMatthew G. Knepley . constants - constant parameters 1465475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1466475e0ac9SMatthew G. Knepley 1467475e0ac9SMatthew G. Knepley Level: intermediate 1468475e0ac9SMatthew G. Knepley 1469475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1470475e0ac9SMatthew G. Knepley @*/ 1471475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1472475e0ac9SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1473475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1474475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 147597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1476475e0ac9SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1477475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1478475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 147997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1480475e0ac9SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1481475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1482475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 148397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1484475e0ac9SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1485475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1486475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 148797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1488475e0ac9SMatthew G. Knepley { 1489475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1490475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1491475e0ac9SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 1492475e0ac9SMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 1493475e0ac9SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];} 1494475e0ac9SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];} 1495475e0ac9SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];} 1496475e0ac9SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];} 1497475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1498475e0ac9SMatthew G. Knepley } 1499475e0ac9SMatthew G. Knepley 1500475e0ac9SMatthew G. Knepley /*@C 1501475e0ac9SMatthew 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. 1502475e0ac9SMatthew G. Knepley 1503475e0ac9SMatthew G. Knepley Not collective 1504475e0ac9SMatthew G. Knepley 1505475e0ac9SMatthew G. Knepley Input Parameters: 1506475e0ac9SMatthew G. Knepley + prob - The PetscDS 1507475e0ac9SMatthew G. Knepley . f - The test field number 1508475e0ac9SMatthew G. Knepley . g - The field number 1509475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term 1510475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1511475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1512475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1513475e0ac9SMatthew G. Knepley 1514475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1515475e0ac9SMatthew G. Knepley 1516475e0ac9SMatthew 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 1517475e0ac9SMatthew G. Knepley 1518475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1519475e0ac9SMatthew G. Knepley 1520475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1521475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1522475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1523475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1524475e0ac9SMatthew G. Knepley 1525475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1526475e0ac9SMatthew G. Knepley . Nf - the number of fields 1527475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1528475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1529475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1530475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1531475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1532475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1533475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1534475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1535475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1536475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1537475e0ac9SMatthew G. Knepley . t - current time 1538475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1539475e0ac9SMatthew G. Knepley . x - coordinates of the current point 154097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 154197b6e6e8SMatthew G. Knepley . constants - constant parameters 1542475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1543475e0ac9SMatthew G. Knepley 1544475e0ac9SMatthew G. Knepley Level: intermediate 1545475e0ac9SMatthew G. Knepley 1546475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian() 1547475e0ac9SMatthew G. Knepley @*/ 1548475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1549475e0ac9SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1550475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1551475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 155297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1553475e0ac9SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1554475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1555475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 155697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1557475e0ac9SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1558475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1559475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 156097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1561475e0ac9SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1562475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1563475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 156497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1565475e0ac9SMatthew G. Knepley { 1566475e0ac9SMatthew G. Knepley PetscErrorCode ierr; 1567475e0ac9SMatthew G. Knepley 1568475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1569475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1570475e0ac9SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1571475e0ac9SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1572475e0ac9SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1573475e0ac9SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1574475e0ac9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1575475e0ac9SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1576475e0ac9SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1577475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+0] = g0; 1578475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+1] = g1; 1579475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+2] = g2; 1580475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+3] = g3; 1581475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1582475e0ac9SMatthew G. Knepley } 1583475e0ac9SMatthew G. Knepley 1584b7e05686SMatthew G. Knepley /*@C 1585b7e05686SMatthew G. Knepley PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set 1586b7e05686SMatthew G. Knepley 1587b7e05686SMatthew G. Knepley Not collective 1588b7e05686SMatthew G. Knepley 1589b7e05686SMatthew G. Knepley Input Parameter: 1590b7e05686SMatthew G. Knepley . prob - The PetscDS 1591b7e05686SMatthew G. Knepley 1592b7e05686SMatthew G. Knepley Output Parameter: 1593b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set 1594b7e05686SMatthew G. Knepley 1595b7e05686SMatthew G. Knepley Level: intermediate 1596b7e05686SMatthew G. Knepley 1597b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian() 1598b7e05686SMatthew G. Knepley @*/ 1599b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac) 1600b7e05686SMatthew G. Knepley { 1601b7e05686SMatthew G. Knepley PetscInt f, g, h; 1602b7e05686SMatthew G. Knepley 1603b7e05686SMatthew G. Knepley PetscFunctionBegin; 1604b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1605b7e05686SMatthew G. Knepley *hasDynJac = PETSC_FALSE; 1606b7e05686SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1607b7e05686SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1608b7e05686SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1609b7e05686SMatthew G. Knepley if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE; 1610b7e05686SMatthew G. Knepley } 1611b7e05686SMatthew G. Knepley } 1612b7e05686SMatthew G. Knepley } 1613b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1614b7e05686SMatthew G. Knepley } 1615b7e05686SMatthew G. Knepley 1616b7e05686SMatthew G. Knepley /*@C 1617b7e05686SMatthew G. Knepley PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field 1618b7e05686SMatthew G. Knepley 1619b7e05686SMatthew G. Knepley Not collective 1620b7e05686SMatthew G. Knepley 1621b7e05686SMatthew G. Knepley Input Parameters: 1622b7e05686SMatthew G. Knepley + prob - The PetscDS 1623b7e05686SMatthew G. Knepley . f - The test field number 1624b7e05686SMatthew G. Knepley - g - The field number 1625b7e05686SMatthew G. Knepley 1626b7e05686SMatthew G. Knepley Output Parameters: 1627b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term 1628b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1629b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1630b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1631b7e05686SMatthew G. Knepley 1632b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1633b7e05686SMatthew G. Knepley 1634b7e05686SMatthew 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 1635b7e05686SMatthew G. Knepley 1636b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1637b7e05686SMatthew G. Knepley 1638b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1639b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1640b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1641b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1642b7e05686SMatthew G. Knepley 1643b7e05686SMatthew G. Knepley + dim - the spatial dimension 1644b7e05686SMatthew G. Knepley . Nf - the number of fields 1645b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1646b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1647b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1648b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1649b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1650b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1651b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1652b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1653b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1654b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1655b7e05686SMatthew G. Knepley . t - current time 1656b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1657b7e05686SMatthew G. Knepley . x - coordinates of the current point 165897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 165997b6e6e8SMatthew G. Knepley . constants - constant parameters 1660b7e05686SMatthew G. Knepley - g0 - output values at the current point 1661b7e05686SMatthew G. Knepley 1662b7e05686SMatthew G. Knepley Level: intermediate 1663b7e05686SMatthew G. Knepley 1664b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1665b7e05686SMatthew G. Knepley @*/ 1666b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1667b7e05686SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1668b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1669b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 167097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1671b7e05686SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1672b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1673b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 167497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1675b7e05686SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1676b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1677b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 167897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1679b7e05686SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1680b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1681b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 168297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1683b7e05686SMatthew G. Knepley { 1684b7e05686SMatthew G. Knepley PetscFunctionBegin; 1685b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1686b7e05686SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 1687b7e05686SMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 1688b7e05686SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];} 1689b7e05686SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];} 1690b7e05686SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];} 1691b7e05686SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];} 1692b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1693b7e05686SMatthew G. Knepley } 1694b7e05686SMatthew G. Knepley 1695b7e05686SMatthew G. Knepley /*@C 1696b7e05686SMatthew G. Knepley PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields 1697b7e05686SMatthew G. Knepley 1698b7e05686SMatthew G. Knepley Not collective 1699b7e05686SMatthew G. Knepley 1700b7e05686SMatthew G. Knepley Input Parameters: 1701b7e05686SMatthew G. Knepley + prob - The PetscDS 1702b7e05686SMatthew G. Knepley . f - The test field number 1703b7e05686SMatthew G. Knepley . g - The field number 1704b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term 1705b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1706b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1707b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1708b7e05686SMatthew G. Knepley 1709b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1710b7e05686SMatthew G. Knepley 1711b7e05686SMatthew 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 1712b7e05686SMatthew G. Knepley 1713b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1714b7e05686SMatthew G. Knepley 1715b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1716b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1717b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1718b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1719b7e05686SMatthew G. Knepley 1720b7e05686SMatthew G. Knepley + dim - the spatial dimension 1721b7e05686SMatthew G. Knepley . Nf - the number of fields 1722b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1723b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1724b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1725b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1726b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1727b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1728b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1729b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1730b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1731b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1732b7e05686SMatthew G. Knepley . t - current time 1733b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1734b7e05686SMatthew G. Knepley . x - coordinates of the current point 173597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 173697b6e6e8SMatthew G. Knepley . constants - constant parameters 1737b7e05686SMatthew G. Knepley - g0 - output values at the current point 1738b7e05686SMatthew G. Knepley 1739b7e05686SMatthew G. Knepley Level: intermediate 1740b7e05686SMatthew G. Knepley 1741b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1742b7e05686SMatthew G. Knepley @*/ 1743b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1744b7e05686SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1745b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1746b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 174797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1748b7e05686SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1749b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1750b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 175197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1752b7e05686SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1753b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1754b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 175597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1756b7e05686SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1757b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1758b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 175997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1760b7e05686SMatthew G. Knepley { 1761b7e05686SMatthew G. Knepley PetscErrorCode ierr; 1762b7e05686SMatthew G. Knepley 1763b7e05686SMatthew G. Knepley PetscFunctionBegin; 1764b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1765b7e05686SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1766b7e05686SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1767b7e05686SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1768b7e05686SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1769b7e05686SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1770b7e05686SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1771b7e05686SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1772b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+0] = g0; 1773b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+1] = g1; 1774b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+2] = g2; 1775b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+3] = g3; 1776b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1777b7e05686SMatthew G. Knepley } 1778b7e05686SMatthew G. Knepley 17790c2f2876SMatthew G. Knepley /*@C 17800c2f2876SMatthew G. Knepley PetscDSGetRiemannSolver - Returns the Riemann solver for the given field 17810c2f2876SMatthew G. Knepley 17820c2f2876SMatthew G. Knepley Not collective 17830c2f2876SMatthew G. Knepley 17840c2f2876SMatthew G. Knepley Input Arguments: 17850c2f2876SMatthew G. Knepley + prob - The PetscDS object 17860c2f2876SMatthew G. Knepley - f - The field number 17870c2f2876SMatthew G. Knepley 17880c2f2876SMatthew G. Knepley Output Argument: 17890c2f2876SMatthew G. Knepley . r - Riemann solver 17900c2f2876SMatthew G. Knepley 17910c2f2876SMatthew G. Knepley Calling sequence for r: 17920c2f2876SMatthew G. Knepley 17935db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 17940c2f2876SMatthew G. Knepley 17955db36cf9SMatthew G. Knepley + dim - The spatial dimension 17965db36cf9SMatthew G. Knepley . Nf - The number of fields 17975db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 17980c2f2876SMatthew G. Knepley . n - The normal vector to the interface 17990c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 18000c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 18010c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 180297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 180397b6e6e8SMatthew G. Knepley . constants - constant parameters 18040c2f2876SMatthew G. Knepley - ctx - optional user context 18050c2f2876SMatthew G. Knepley 18060c2f2876SMatthew G. Knepley Level: intermediate 18070c2f2876SMatthew G. Knepley 18080c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver() 18090c2f2876SMatthew G. Knepley @*/ 18100c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f, 181197b6e6e8SMatthew G. Knepley 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)) 18120c2f2876SMatthew G. Knepley { 18130c2f2876SMatthew G. Knepley PetscFunctionBegin; 18140c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 18150c2f2876SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 18160c2f2876SMatthew G. Knepley PetscValidPointer(r, 3); 18170c2f2876SMatthew G. Knepley *r = prob->r[f]; 18180c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18190c2f2876SMatthew G. Knepley } 18200c2f2876SMatthew G. Knepley 18210c2f2876SMatthew G. Knepley /*@C 18220c2f2876SMatthew G. Knepley PetscDSSetRiemannSolver - Sets the Riemann solver for the given field 18230c2f2876SMatthew G. Knepley 18240c2f2876SMatthew G. Knepley Not collective 18250c2f2876SMatthew G. Knepley 18260c2f2876SMatthew G. Knepley Input Arguments: 18270c2f2876SMatthew G. Knepley + prob - The PetscDS object 18280c2f2876SMatthew G. Knepley . f - The field number 18290c2f2876SMatthew G. Knepley - r - Riemann solver 18300c2f2876SMatthew G. Knepley 18310c2f2876SMatthew G. Knepley Calling sequence for r: 18320c2f2876SMatthew G. Knepley 18335db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 18340c2f2876SMatthew G. Knepley 18355db36cf9SMatthew G. Knepley + dim - The spatial dimension 18365db36cf9SMatthew G. Knepley . Nf - The number of fields 18375db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 18380c2f2876SMatthew G. Knepley . n - The normal vector to the interface 18390c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 18400c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 18410c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 184297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 184397b6e6e8SMatthew G. Knepley . constants - constant parameters 18440c2f2876SMatthew G. Knepley - ctx - optional user context 18450c2f2876SMatthew G. Knepley 18460c2f2876SMatthew G. Knepley Level: intermediate 18470c2f2876SMatthew G. Knepley 18480c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver() 18490c2f2876SMatthew G. Knepley @*/ 18500c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f, 185197b6e6e8SMatthew G. Knepley 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)) 18520c2f2876SMatthew G. Knepley { 18530c2f2876SMatthew G. Knepley PetscErrorCode ierr; 18540c2f2876SMatthew G. Knepley 18550c2f2876SMatthew G. Knepley PetscFunctionBegin; 18560c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1857de716cbcSToby Isaac if (r) PetscValidFunction(r, 3); 18580c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 18590c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 18600c2f2876SMatthew G. Knepley prob->r[f] = r; 18610c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18620c2f2876SMatthew G. Knepley } 18630c2f2876SMatthew G. Knepley 186432d2bbc9SMatthew G. Knepley /*@C 186532d2bbc9SMatthew G. Knepley PetscDSGetUpdate - Get the pointwise update function for a given field 186632d2bbc9SMatthew G. Knepley 186732d2bbc9SMatthew G. Knepley Not collective 186832d2bbc9SMatthew G. Knepley 186932d2bbc9SMatthew G. Knepley Input Parameters: 187032d2bbc9SMatthew G. Knepley + prob - The PetscDS 187132d2bbc9SMatthew G. Knepley - f - The field number 187232d2bbc9SMatthew G. Knepley 187332d2bbc9SMatthew G. Knepley Output Parameters: 187432d2bbc9SMatthew G. Knepley + update - update function 187532d2bbc9SMatthew G. Knepley 187632d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 187732d2bbc9SMatthew G. Knepley 187832d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 187932d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 188032d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 188132d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 188232d2bbc9SMatthew G. Knepley 188332d2bbc9SMatthew G. Knepley + dim - the spatial dimension 188432d2bbc9SMatthew G. Knepley . Nf - the number of fields 188532d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 188632d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 188732d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 188832d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 188932d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 189032d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 189132d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 189232d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 189332d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 189432d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 189532d2bbc9SMatthew G. Knepley . t - current time 189632d2bbc9SMatthew G. Knepley . x - coordinates of the current point 189732d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point 189832d2bbc9SMatthew G. Knepley 189932d2bbc9SMatthew G. Knepley Level: intermediate 190032d2bbc9SMatthew G. Knepley 190132d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual() 190232d2bbc9SMatthew G. Knepley @*/ 190332d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f, 190432d2bbc9SMatthew G. Knepley void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 190532d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 190632d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 19073fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 190832d2bbc9SMatthew G. Knepley { 190932d2bbc9SMatthew G. Knepley PetscFunctionBegin; 191032d2bbc9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 191132d2bbc9SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 191232d2bbc9SMatthew G. Knepley if (update) {PetscValidPointer(update, 3); *update = prob->update[f];} 191332d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 191432d2bbc9SMatthew G. Knepley } 191532d2bbc9SMatthew G. Knepley 191632d2bbc9SMatthew G. Knepley /*@C 19173fa77dffSMatthew G. Knepley PetscDSSetUpdate - Set the pointwise update function for a given field 191832d2bbc9SMatthew G. Knepley 191932d2bbc9SMatthew G. Knepley Not collective 192032d2bbc9SMatthew G. Knepley 192132d2bbc9SMatthew G. Knepley Input Parameters: 192232d2bbc9SMatthew G. Knepley + prob - The PetscDS 192332d2bbc9SMatthew G. Knepley . f - The field number 192432d2bbc9SMatthew G. Knepley - update - update function 192532d2bbc9SMatthew G. Knepley 192632d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 192732d2bbc9SMatthew G. Knepley 192832d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 192932d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 193032d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 193132d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 193232d2bbc9SMatthew G. Knepley 193332d2bbc9SMatthew G. Knepley + dim - the spatial dimension 193432d2bbc9SMatthew G. Knepley . Nf - the number of fields 193532d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 193632d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 193732d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 193832d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 193932d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 194032d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 194132d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 194232d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 194332d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 194432d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 194532d2bbc9SMatthew G. Knepley . t - current time 194632d2bbc9SMatthew G. Knepley . x - coordinates of the current point 194732d2bbc9SMatthew G. Knepley - uNew - new field values at the current point 194832d2bbc9SMatthew G. Knepley 194932d2bbc9SMatthew G. Knepley Level: intermediate 195032d2bbc9SMatthew G. Knepley 195132d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual() 195232d2bbc9SMatthew G. Knepley @*/ 195332d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f, 195432d2bbc9SMatthew G. Knepley void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 195532d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 195632d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 19573fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 195832d2bbc9SMatthew G. Knepley { 195932d2bbc9SMatthew G. Knepley PetscErrorCode ierr; 196032d2bbc9SMatthew G. Knepley 196132d2bbc9SMatthew G. Knepley PetscFunctionBegin; 196232d2bbc9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 196332d2bbc9SMatthew G. Knepley if (update) PetscValidFunction(update, 3); 196432d2bbc9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 196532d2bbc9SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 196632d2bbc9SMatthew G. Knepley prob->update[f] = update; 196732d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 196832d2bbc9SMatthew G. Knepley } 196932d2bbc9SMatthew G. Knepley 19700c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx) 19710c2f2876SMatthew G. Knepley { 19720c2f2876SMatthew G. Knepley PetscFunctionBegin; 19730c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19740c2f2876SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 19750c2f2876SMatthew G. Knepley PetscValidPointer(ctx, 3); 19760c2f2876SMatthew G. Knepley *ctx = prob->ctx[f]; 19770c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19780c2f2876SMatthew G. Knepley } 19790c2f2876SMatthew G. Knepley 19800c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx) 19810c2f2876SMatthew G. Knepley { 19820c2f2876SMatthew G. Knepley PetscErrorCode ierr; 19830c2f2876SMatthew G. Knepley 19840c2f2876SMatthew G. Knepley PetscFunctionBegin; 19850c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19860c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 19870c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 19880c2f2876SMatthew G. Knepley prob->ctx[f] = ctx; 19890c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19900c2f2876SMatthew G. Knepley } 19910c2f2876SMatthew G. Knepley 1992194d53e6SMatthew G. Knepley /*@C 1993194d53e6SMatthew G. Knepley PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field 1994194d53e6SMatthew G. Knepley 1995194d53e6SMatthew G. Knepley Not collective 1996194d53e6SMatthew G. Knepley 1997194d53e6SMatthew G. Knepley Input Parameters: 1998194d53e6SMatthew G. Knepley + prob - The PetscDS 1999194d53e6SMatthew G. Knepley - f - The test field number 2000194d53e6SMatthew G. Knepley 2001194d53e6SMatthew G. Knepley Output Parameters: 2002194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term 2003194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2004194d53e6SMatthew G. Knepley 2005194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2006194d53e6SMatthew G. Knepley 2007194d53e6SMatthew 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 2008194d53e6SMatthew G. Knepley 2009194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2010194d53e6SMatthew G. Knepley 201130b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2012194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2013194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 201430b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2015194d53e6SMatthew G. Knepley 2016194d53e6SMatthew G. Knepley + dim - the spatial dimension 2017194d53e6SMatthew G. Knepley . Nf - the number of fields 2018194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2019194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2020194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2021194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2022194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2023194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2024194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2025194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2026194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2027194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2028194d53e6SMatthew G. Knepley . t - current time 2029194d53e6SMatthew G. Knepley . x - coordinates of the current point 2030194d53e6SMatthew G. Knepley . n - unit normal at the current point 203197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 203297b6e6e8SMatthew G. Knepley . constants - constant parameters 2033194d53e6SMatthew G. Knepley - f0 - output values at the current point 2034194d53e6SMatthew G. Knepley 2035194d53e6SMatthew G. Knepley Level: intermediate 2036194d53e6SMatthew G. Knepley 2037194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual() 2038194d53e6SMatthew G. Knepley @*/ 20392764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f, 204030b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2041194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2042194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 204397b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 204430b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2045194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2046194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 204797b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 20482764a2aaSMatthew G. Knepley { 20492764a2aaSMatthew G. Knepley PetscFunctionBegin; 20502764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 20512764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 20522764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];} 20532764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];} 20542764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 20552764a2aaSMatthew G. Knepley } 20562764a2aaSMatthew G. Knepley 2057194d53e6SMatthew G. Knepley /*@C 2058194d53e6SMatthew G. Knepley PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field 2059194d53e6SMatthew G. Knepley 2060194d53e6SMatthew G. Knepley Not collective 2061194d53e6SMatthew G. Knepley 2062194d53e6SMatthew G. Knepley Input Parameters: 2063194d53e6SMatthew G. Knepley + prob - The PetscDS 2064194d53e6SMatthew G. Knepley . f - The test field number 2065194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term 2066194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2067194d53e6SMatthew G. Knepley 2068194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2069194d53e6SMatthew G. Knepley 2070194d53e6SMatthew 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 2071194d53e6SMatthew G. Knepley 2072194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2073194d53e6SMatthew G. Knepley 207430b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2075194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2076194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 207730b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2078194d53e6SMatthew G. Knepley 2079194d53e6SMatthew G. Knepley + dim - the spatial dimension 2080194d53e6SMatthew G. Knepley . Nf - the number of fields 2081194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2082194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2083194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2084194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2085194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2086194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2087194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2088194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2089194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2090194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2091194d53e6SMatthew G. Knepley . t - current time 2092194d53e6SMatthew G. Knepley . x - coordinates of the current point 2093194d53e6SMatthew G. Knepley . n - unit normal at the current point 209497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 209597b6e6e8SMatthew G. Knepley . constants - constant parameters 2096194d53e6SMatthew G. Knepley - f0 - output values at the current point 2097194d53e6SMatthew G. Knepley 2098194d53e6SMatthew G. Knepley Level: intermediate 2099194d53e6SMatthew G. Knepley 2100194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual() 2101194d53e6SMatthew G. Knepley @*/ 21022764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f, 210330b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2104194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2105194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 210697b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 210730b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2108194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2109194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 211097b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 21112764a2aaSMatthew G. Knepley { 21122764a2aaSMatthew G. Knepley PetscErrorCode ierr; 21132764a2aaSMatthew G. Knepley 21142764a2aaSMatthew G. Knepley PetscFunctionBegin; 21152764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 21162764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 21172764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 21182764a2aaSMatthew G. Knepley if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;} 21192764a2aaSMatthew G. Knepley if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;} 21202764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21212764a2aaSMatthew G. Knepley } 21222764a2aaSMatthew G. Knepley 2123194d53e6SMatthew G. Knepley /*@C 2124194d53e6SMatthew G. Knepley PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field 2125194d53e6SMatthew G. Knepley 2126194d53e6SMatthew G. Knepley Not collective 2127194d53e6SMatthew G. Knepley 2128194d53e6SMatthew G. Knepley Input Parameters: 2129194d53e6SMatthew G. Knepley + prob - The PetscDS 2130194d53e6SMatthew G. Knepley . f - The test field number 2131194d53e6SMatthew G. Knepley - g - The field number 2132194d53e6SMatthew G. Knepley 2133194d53e6SMatthew G. Knepley Output Parameters: 2134194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 2135194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2136194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2137194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2138194d53e6SMatthew G. Knepley 2139194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2140194d53e6SMatthew G. Knepley 2141194d53e6SMatthew 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 2142194d53e6SMatthew G. Knepley 2143194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2144194d53e6SMatthew G. Knepley 214530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2146194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2147194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 214830b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2149194d53e6SMatthew G. Knepley 2150194d53e6SMatthew G. Knepley + dim - the spatial dimension 2151194d53e6SMatthew G. Knepley . Nf - the number of fields 2152194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2153194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2154194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2155194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2156194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2157194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2158194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2159194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2160194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2161194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2162194d53e6SMatthew G. Knepley . t - current time 21632aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2164194d53e6SMatthew G. Knepley . x - coordinates of the current point 2165194d53e6SMatthew G. Knepley . n - normal at the current point 216697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 216797b6e6e8SMatthew G. Knepley . constants - constant parameters 2168194d53e6SMatthew G. Knepley - g0 - output values at the current point 2169194d53e6SMatthew G. Knepley 2170194d53e6SMatthew G. Knepley Level: intermediate 2171194d53e6SMatthew G. Knepley 2172194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian() 2173194d53e6SMatthew G. Knepley @*/ 21742764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 217530b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2176194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2177194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 217897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 217930b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2180194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2181194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 218297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 218330b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2184194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2185194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 218697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 218730b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2188194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2189194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 219097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 21912764a2aaSMatthew G. Knepley { 21922764a2aaSMatthew G. Knepley PetscFunctionBegin; 21932764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 21942764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 21952764a2aaSMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 21962764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];} 21972764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];} 21982764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];} 21992764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];} 22002764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22012764a2aaSMatthew G. Knepley } 22022764a2aaSMatthew G. Knepley 2203194d53e6SMatthew G. Knepley /*@C 2204194d53e6SMatthew G. Knepley PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field 2205194d53e6SMatthew G. Knepley 2206194d53e6SMatthew G. Knepley Not collective 2207194d53e6SMatthew G. Knepley 2208194d53e6SMatthew G. Knepley Input Parameters: 2209194d53e6SMatthew G. Knepley + prob - The PetscDS 2210194d53e6SMatthew G. Knepley . f - The test field number 2211194d53e6SMatthew G. Knepley . g - The field number 2212194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 2213194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2214194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2215194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2216194d53e6SMatthew G. Knepley 2217194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2218194d53e6SMatthew G. Knepley 2219194d53e6SMatthew 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 2220194d53e6SMatthew G. Knepley 2221194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2222194d53e6SMatthew G. Knepley 222330b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2224194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2225194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 222630b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2227194d53e6SMatthew G. Knepley 2228194d53e6SMatthew G. Knepley + dim - the spatial dimension 2229194d53e6SMatthew G. Knepley . Nf - the number of fields 2230194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2231194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2232194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2233194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2234194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2235194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2236194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2237194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2238194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2239194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2240194d53e6SMatthew G. Knepley . t - current time 22412aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2242194d53e6SMatthew G. Knepley . x - coordinates of the current point 2243194d53e6SMatthew G. Knepley . n - normal at the current point 224497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 224597b6e6e8SMatthew G. Knepley . constants - constant parameters 2246194d53e6SMatthew G. Knepley - g0 - output values at the current point 2247194d53e6SMatthew G. Knepley 2248194d53e6SMatthew G. Knepley Level: intermediate 2249194d53e6SMatthew G. Knepley 2250194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian() 2251194d53e6SMatthew G. Knepley @*/ 22522764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 225330b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2254194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2255194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 225697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 225730b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2258194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2259194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 226097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 226130b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2262194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2263194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 226497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 226530b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2266194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2267194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 226897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 22692764a2aaSMatthew G. Knepley { 22702764a2aaSMatthew G. Knepley PetscErrorCode ierr; 22712764a2aaSMatthew G. Knepley 22722764a2aaSMatthew G. Knepley PetscFunctionBegin; 22732764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 22742764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 22752764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 22762764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 22772764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 22782764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 22792764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 22802764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 22812764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+0] = g0; 22822764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+1] = g1; 22832764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+2] = g2; 22842764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+3] = g3; 22852764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22862764a2aaSMatthew G. Knepley } 22872764a2aaSMatthew G. Knepley 22880d3e9b51SMatthew G. Knepley /*@C 2289c371a6d1SMatthew G. Knepley PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field 2290c371a6d1SMatthew G. Knepley 2291c371a6d1SMatthew G. Knepley Not collective 2292c371a6d1SMatthew G. Knepley 2293c371a6d1SMatthew G. Knepley Input Parameters: 2294c371a6d1SMatthew G. Knepley + prob - The PetscDS 2295c371a6d1SMatthew G. Knepley - f - The test field number 2296c371a6d1SMatthew G. Knepley 2297c371a6d1SMatthew G. Knepley Output Parameter: 2298*95cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field 2299*95cbbfd3SMatthew G. Knepley - exactCtx - exact solution context 2300c371a6d1SMatthew G. Knepley 2301c371a6d1SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2302c371a6d1SMatthew G. Knepley 2303c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2304c371a6d1SMatthew G. Knepley 2305c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2306c371a6d1SMatthew G. Knepley . t - current time 2307c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2308c371a6d1SMatthew G. Knepley . Nc - the number of field components 2309c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2310c371a6d1SMatthew G. Knepley - ctx - a user context 2311c371a6d1SMatthew G. Knepley 2312c371a6d1SMatthew G. Knepley Level: intermediate 2313c371a6d1SMatthew G. Knepley 2314c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution() 2315c371a6d1SMatthew G. Knepley @*/ 2316*95cbbfd3SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx) 2317c371a6d1SMatthew G. Knepley { 2318c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2319c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2320c371a6d1SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 2321c371a6d1SMatthew G. Knepley if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];} 2322*95cbbfd3SMatthew G. Knepley if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];} 2323c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2324c371a6d1SMatthew G. Knepley } 2325c371a6d1SMatthew G. Knepley 2326c371a6d1SMatthew G. Knepley /*@C 2327c371a6d1SMatthew G. Knepley PetscDSSetExactSolution - Get the pointwise exact solution function for a given test field 2328c371a6d1SMatthew G. Knepley 2329c371a6d1SMatthew G. Knepley Not collective 2330c371a6d1SMatthew G. Knepley 2331c371a6d1SMatthew G. Knepley Input Parameters: 2332c371a6d1SMatthew G. Knepley + prob - The PetscDS 2333c371a6d1SMatthew G. Knepley . f - The test field number 2334*95cbbfd3SMatthew G. Knepley . sol - solution function for the test fields 2335*95cbbfd3SMatthew G. Knepley - ctx - solution context or NULL 2336c371a6d1SMatthew G. Knepley 2337c371a6d1SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2338c371a6d1SMatthew G. Knepley 2339c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2340c371a6d1SMatthew G. Knepley 2341c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2342c371a6d1SMatthew G. Knepley . t - current time 2343c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2344c371a6d1SMatthew G. Knepley . Nc - the number of field components 2345c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2346c371a6d1SMatthew G. Knepley - ctx - a user context 2347c371a6d1SMatthew G. Knepley 2348c371a6d1SMatthew G. Knepley Level: intermediate 2349c371a6d1SMatthew G. Knepley 2350c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution() 2351c371a6d1SMatthew G. Knepley @*/ 2352*95cbbfd3SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx) 2353c371a6d1SMatthew G. Knepley { 2354c371a6d1SMatthew G. Knepley PetscErrorCode ierr; 2355c371a6d1SMatthew G. Knepley 2356c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2357c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2358c371a6d1SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 2359c371a6d1SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 2360c371a6d1SMatthew G. Knepley if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;} 2361*95cbbfd3SMatthew G. Knepley if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;} 2362c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2363c371a6d1SMatthew G. Knepley } 2364c371a6d1SMatthew G. Knepley 23655638fd0eSMatthew G. Knepley /*@C 236697b6e6e8SMatthew G. Knepley PetscDSGetConstants - Returns the array of constants passed to point functions 236797b6e6e8SMatthew G. Knepley 236897b6e6e8SMatthew G. Knepley Not collective 236997b6e6e8SMatthew G. Knepley 237097b6e6e8SMatthew G. Knepley Input Parameter: 237197b6e6e8SMatthew G. Knepley . prob - The PetscDS object 237297b6e6e8SMatthew G. Knepley 237397b6e6e8SMatthew G. Knepley Output Parameters: 237497b6e6e8SMatthew G. Knepley + numConstants - The number of constants 237597b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 237697b6e6e8SMatthew G. Knepley 237797b6e6e8SMatthew G. Knepley Level: intermediate 237897b6e6e8SMatthew G. Knepley 237997b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate() 238097b6e6e8SMatthew G. Knepley @*/ 238197b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[]) 238297b6e6e8SMatthew G. Knepley { 238397b6e6e8SMatthew G. Knepley PetscFunctionBegin; 238497b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 238597b6e6e8SMatthew G. Knepley if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;} 238697b6e6e8SMatthew G. Knepley if (constants) {PetscValidPointer(constants, 3); *constants = prob->constants;} 238797b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 238897b6e6e8SMatthew G. Knepley } 238997b6e6e8SMatthew G. Knepley 23900d3e9b51SMatthew G. Knepley /*@C 239197b6e6e8SMatthew G. Knepley PetscDSSetConstants - Set the array of constants passed to point functions 239297b6e6e8SMatthew G. Knepley 239397b6e6e8SMatthew G. Knepley Not collective 239497b6e6e8SMatthew G. Knepley 239597b6e6e8SMatthew G. Knepley Input Parameters: 239697b6e6e8SMatthew G. Knepley + prob - The PetscDS object 239797b6e6e8SMatthew G. Knepley . numConstants - The number of constants 239897b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 239997b6e6e8SMatthew G. Knepley 240097b6e6e8SMatthew G. Knepley Level: intermediate 240197b6e6e8SMatthew G. Knepley 240297b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate() 240397b6e6e8SMatthew G. Knepley @*/ 240497b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[]) 240597b6e6e8SMatthew G. Knepley { 240697b6e6e8SMatthew G. Knepley PetscErrorCode ierr; 240797b6e6e8SMatthew G. Knepley 240897b6e6e8SMatthew G. Knepley PetscFunctionBegin; 240997b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 241097b6e6e8SMatthew G. Knepley if (numConstants != prob->numConstants) { 241197b6e6e8SMatthew G. Knepley ierr = PetscFree(prob->constants);CHKERRQ(ierr); 241297b6e6e8SMatthew G. Knepley prob->numConstants = numConstants; 241397b6e6e8SMatthew G. Knepley if (prob->numConstants) { 241497b6e6e8SMatthew G. Knepley ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr); 241520be0f5bSMatthew G. Knepley } else { 241620be0f5bSMatthew G. Knepley prob->constants = NULL; 241720be0f5bSMatthew G. Knepley } 241820be0f5bSMatthew G. Knepley } 241920be0f5bSMatthew G. Knepley if (prob->numConstants) { 242020be0f5bSMatthew G. Knepley PetscValidPointer(constants, 3); 242197b6e6e8SMatthew G. Knepley ierr = PetscMemcpy(prob->constants, constants, prob->numConstants * sizeof(PetscScalar));CHKERRQ(ierr); 242297b6e6e8SMatthew G. Knepley } 242397b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 242497b6e6e8SMatthew G. Knepley } 242597b6e6e8SMatthew G. Knepley 24264cd1e086SMatthew G. Knepley /*@ 24274cd1e086SMatthew G. Knepley PetscDSGetFieldIndex - Returns the index of the given field 24284cd1e086SMatthew G. Knepley 24294cd1e086SMatthew G. Knepley Not collective 24304cd1e086SMatthew G. Knepley 24314cd1e086SMatthew G. Knepley Input Parameters: 24324cd1e086SMatthew G. Knepley + prob - The PetscDS object 24334cd1e086SMatthew G. Knepley - disc - The discretization object 24344cd1e086SMatthew G. Knepley 24354cd1e086SMatthew G. Knepley Output Parameter: 24364cd1e086SMatthew G. Knepley . f - The field number 24374cd1e086SMatthew G. Knepley 24384cd1e086SMatthew G. Knepley Level: beginner 24394cd1e086SMatthew G. Knepley 2440f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 24414cd1e086SMatthew G. Knepley @*/ 24424cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f) 24434cd1e086SMatthew G. Knepley { 24444cd1e086SMatthew G. Knepley PetscInt g; 24454cd1e086SMatthew G. Knepley 24464cd1e086SMatthew G. Knepley PetscFunctionBegin; 24474cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 24484cd1e086SMatthew G. Knepley PetscValidPointer(f, 3); 24494cd1e086SMatthew G. Knepley *f = -1; 24504cd1e086SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;} 24514cd1e086SMatthew G. Knepley if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS."); 24524cd1e086SMatthew G. Knepley *f = g; 24534cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 24544cd1e086SMatthew G. Knepley } 24554cd1e086SMatthew G. Knepley 24564cd1e086SMatthew G. Knepley /*@ 24574cd1e086SMatthew G. Knepley PetscDSGetFieldSize - Returns the size of the given field in the full space basis 24584cd1e086SMatthew G. Knepley 24594cd1e086SMatthew G. Knepley Not collective 24604cd1e086SMatthew G. Knepley 24614cd1e086SMatthew G. Knepley Input Parameters: 24624cd1e086SMatthew G. Knepley + prob - The PetscDS object 24634cd1e086SMatthew G. Knepley - f - The field number 24644cd1e086SMatthew G. Knepley 24654cd1e086SMatthew G. Knepley Output Parameter: 24664cd1e086SMatthew G. Knepley . size - The size 24674cd1e086SMatthew G. Knepley 24684cd1e086SMatthew G. Knepley Level: beginner 24694cd1e086SMatthew G. Knepley 2470f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate() 24714cd1e086SMatthew G. Knepley @*/ 24724cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size) 24734cd1e086SMatthew G. Knepley { 24742166fd64SMatthew G. Knepley PetscErrorCode ierr; 24752166fd64SMatthew G. Knepley 24764cd1e086SMatthew G. Knepley PetscFunctionBegin; 24774cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 24784cd1e086SMatthew G. Knepley PetscValidPointer(size, 3); 24794cd1e086SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 24802166fd64SMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2481d4742ddaSMatthew G. Knepley *size = prob->Nb[f]; 24824cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 24834cd1e086SMatthew G. Knepley } 24844cd1e086SMatthew G. Knepley 2485bc4ae4beSMatthew G. Knepley /*@ 2486bc4ae4beSMatthew G. Knepley PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis 2487bc4ae4beSMatthew G. Knepley 2488bc4ae4beSMatthew G. Knepley Not collective 2489bc4ae4beSMatthew G. Knepley 2490bc4ae4beSMatthew G. Knepley Input Parameters: 2491bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 2492bc4ae4beSMatthew G. Knepley - f - The field number 2493bc4ae4beSMatthew G. Knepley 2494bc4ae4beSMatthew G. Knepley Output Parameter: 2495bc4ae4beSMatthew G. Knepley . off - The offset 2496bc4ae4beSMatthew G. Knepley 2497bc4ae4beSMatthew G. Knepley Level: beginner 2498bc4ae4beSMatthew G. Knepley 2499f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate() 2500bc4ae4beSMatthew G. Knepley @*/ 25012764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 25022764a2aaSMatthew G. Knepley { 25034cd1e086SMatthew G. Knepley PetscInt size, g; 25042764a2aaSMatthew G. Knepley PetscErrorCode ierr; 25052764a2aaSMatthew G. Knepley 25062764a2aaSMatthew G. Knepley PetscFunctionBegin; 25072764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 25082764a2aaSMatthew G. Knepley PetscValidPointer(off, 3); 25092764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 25102764a2aaSMatthew G. Knepley *off = 0; 25112764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 25124cd1e086SMatthew G. Knepley ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr); 25134cd1e086SMatthew G. Knepley *off += size; 25142764a2aaSMatthew G. Knepley } 25152764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 25162764a2aaSMatthew G. Knepley } 25172764a2aaSMatthew G. Knepley 2518bc4ae4beSMatthew G. Knepley /*@ 251947e57110SSander Arens PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point 2520bc4ae4beSMatthew G. Knepley 2521bc4ae4beSMatthew G. Knepley Not collective 2522bc4ae4beSMatthew G. Knepley 252347e57110SSander Arens Input Parameter: 252447e57110SSander Arens . prob - The PetscDS object 2525bc4ae4beSMatthew G. Knepley 2526bc4ae4beSMatthew G. Knepley Output Parameter: 252747e57110SSander Arens . dimensions - The number of dimensions 2528bc4ae4beSMatthew G. Knepley 2529bc4ae4beSMatthew G. Knepley Level: beginner 2530bc4ae4beSMatthew G. Knepley 253147e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 2532bc4ae4beSMatthew G. Knepley @*/ 253347e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[]) 25342764a2aaSMatthew G. Knepley { 25352764a2aaSMatthew G. Knepley PetscErrorCode ierr; 25362764a2aaSMatthew G. Knepley 25372764a2aaSMatthew G. Knepley PetscFunctionBegin; 25382764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 253947e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 254047e57110SSander Arens PetscValidPointer(dimensions, 2); 254147e57110SSander Arens *dimensions = prob->Nb; 254247e57110SSander Arens PetscFunctionReturn(0); 25436ce16762SMatthew G. Knepley } 254447e57110SSander Arens 254547e57110SSander Arens /*@ 254647e57110SSander Arens PetscDSGetComponents - Returns the number of components for each field on an evaluation point 254747e57110SSander Arens 254847e57110SSander Arens Not collective 254947e57110SSander Arens 255047e57110SSander Arens Input Parameter: 255147e57110SSander Arens . prob - The PetscDS object 255247e57110SSander Arens 255347e57110SSander Arens Output Parameter: 255447e57110SSander Arens . components - The number of components 255547e57110SSander Arens 255647e57110SSander Arens Level: beginner 255747e57110SSander Arens 255847e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 255947e57110SSander Arens @*/ 256047e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[]) 256147e57110SSander Arens { 256247e57110SSander Arens PetscErrorCode ierr; 256347e57110SSander Arens 256447e57110SSander Arens PetscFunctionBegin; 256547e57110SSander Arens PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 256647e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 256747e57110SSander Arens PetscValidPointer(components, 2); 256847e57110SSander Arens *components = prob->Nc; 25696ce16762SMatthew G. Knepley PetscFunctionReturn(0); 25706ce16762SMatthew G. Knepley } 25716ce16762SMatthew G. Knepley 25726ce16762SMatthew G. Knepley /*@ 25736ce16762SMatthew G. Knepley PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point 25746ce16762SMatthew G. Knepley 25756ce16762SMatthew G. Knepley Not collective 25766ce16762SMatthew G. Knepley 25776ce16762SMatthew G. Knepley Input Parameters: 25786ce16762SMatthew G. Knepley + prob - The PetscDS object 25796ce16762SMatthew G. Knepley - f - The field number 25806ce16762SMatthew G. Knepley 25816ce16762SMatthew G. Knepley Output Parameter: 25826ce16762SMatthew G. Knepley . off - The offset 25836ce16762SMatthew G. Knepley 25846ce16762SMatthew G. Knepley Level: beginner 25856ce16762SMatthew G. Knepley 2586f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 25876ce16762SMatthew G. Knepley @*/ 25886ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off) 25896ce16762SMatthew G. Knepley { 25906ce16762SMatthew G. Knepley PetscFunctionBegin; 25916ce16762SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 25926ce16762SMatthew G. Knepley PetscValidPointer(off, 3); 25936ce16762SMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 259447e57110SSander Arens *off = prob->off[f]; 25952764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 25962764a2aaSMatthew G. Knepley } 25972764a2aaSMatthew G. Knepley 2598194d53e6SMatthew G. Knepley /*@ 2599194d53e6SMatthew G. Knepley PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point 2600194d53e6SMatthew G. Knepley 2601194d53e6SMatthew G. Knepley Not collective 2602194d53e6SMatthew G. Knepley 2603194d53e6SMatthew G. Knepley Input Parameter: 2604194d53e6SMatthew G. Knepley . prob - The PetscDS object 2605194d53e6SMatthew G. Knepley 2606194d53e6SMatthew G. Knepley Output Parameter: 2607194d53e6SMatthew G. Knepley . offsets - The offsets 2608194d53e6SMatthew G. Knepley 2609194d53e6SMatthew G. Knepley Level: beginner 2610194d53e6SMatthew G. Knepley 2611f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2612194d53e6SMatthew G. Knepley @*/ 2613194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[]) 2614194d53e6SMatthew G. Knepley { 2615194d53e6SMatthew G. Knepley PetscFunctionBegin; 2616194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2617194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2618194d53e6SMatthew G. Knepley *offsets = prob->off; 2619194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2620194d53e6SMatthew G. Knepley } 2621194d53e6SMatthew G. Knepley 2622194d53e6SMatthew G. Knepley /*@ 2623194d53e6SMatthew G. Knepley PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point 2624194d53e6SMatthew G. Knepley 2625194d53e6SMatthew G. Knepley Not collective 2626194d53e6SMatthew G. Knepley 2627194d53e6SMatthew G. Knepley Input Parameter: 2628194d53e6SMatthew G. Knepley . prob - The PetscDS object 2629194d53e6SMatthew G. Knepley 2630194d53e6SMatthew G. Knepley Output Parameter: 2631194d53e6SMatthew G. Knepley . offsets - The offsets 2632194d53e6SMatthew G. Knepley 2633194d53e6SMatthew G. Knepley Level: beginner 2634194d53e6SMatthew G. Knepley 2635f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2636194d53e6SMatthew G. Knepley @*/ 2637194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[]) 2638194d53e6SMatthew G. Knepley { 2639194d53e6SMatthew G. Knepley PetscFunctionBegin; 2640194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2641194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2642194d53e6SMatthew G. Knepley *offsets = prob->offDer; 2643194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2644194d53e6SMatthew G. Knepley } 2645194d53e6SMatthew G. Knepley 264668c9edb9SMatthew G. Knepley /*@C 264768c9edb9SMatthew G. Knepley PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization 264868c9edb9SMatthew G. Knepley 264968c9edb9SMatthew G. Knepley Not collective 265068c9edb9SMatthew G. Knepley 265168c9edb9SMatthew G. Knepley Input Parameter: 265268c9edb9SMatthew G. Knepley . prob - The PetscDS object 265368c9edb9SMatthew G. Knepley 265468c9edb9SMatthew G. Knepley Output Parameters: 265568c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points 265668c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points 265768c9edb9SMatthew G. Knepley 265868c9edb9SMatthew G. Knepley Level: intermediate 265968c9edb9SMatthew G. Knepley 2660f744cafaSSander Arens .seealso: PetscDSCreate() 266168c9edb9SMatthew G. Knepley @*/ 26622764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer) 26632764a2aaSMatthew G. Knepley { 26642764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26652764a2aaSMatthew G. Knepley 26662764a2aaSMatthew G. Knepley PetscFunctionBegin; 26672764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26682764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 26692764a2aaSMatthew G. Knepley if (basis) {PetscValidPointer(basis, 2); *basis = prob->basis;} 26702764a2aaSMatthew G. Knepley if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;} 26712764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26722764a2aaSMatthew G. Knepley } 26732764a2aaSMatthew G. Knepley 267468c9edb9SMatthew G. Knepley /*@C 26754d0b9603SSander Arens PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces 267668c9edb9SMatthew G. Knepley 267768c9edb9SMatthew G. Knepley Not collective 267868c9edb9SMatthew G. Knepley 267968c9edb9SMatthew G. Knepley Input Parameter: 268068c9edb9SMatthew G. Knepley . prob - The PetscDS object 268168c9edb9SMatthew G. Knepley 268268c9edb9SMatthew G. Knepley Output Parameters: 26834d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points 26844d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points 268568c9edb9SMatthew G. Knepley 268668c9edb9SMatthew G. Knepley Level: intermediate 268768c9edb9SMatthew G. Knepley 268868c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate() 268968c9edb9SMatthew G. Knepley @*/ 26904d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer) 26912764a2aaSMatthew G. Knepley { 26922764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26932764a2aaSMatthew G. Knepley 26942764a2aaSMatthew G. Knepley PetscFunctionBegin; 26952764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26962764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 26974d0b9603SSander Arens if (basis) {PetscValidPointer(basis, 2); *basis = prob->basisFace;} 26984d0b9603SSander Arens if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;} 26992764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27002764a2aaSMatthew G. Knepley } 27012764a2aaSMatthew G. Knepley 27022764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) 27032764a2aaSMatthew G. Knepley { 27042764a2aaSMatthew G. Knepley PetscErrorCode ierr; 27052764a2aaSMatthew G. Knepley 27062764a2aaSMatthew G. Knepley PetscFunctionBegin; 27072764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 27082764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 27092764a2aaSMatthew G. Knepley if (u) {PetscValidPointer(u, 2); *u = prob->u;} 27102764a2aaSMatthew G. Knepley if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;} 27112764a2aaSMatthew G. Knepley if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;} 27122764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27132764a2aaSMatthew G. Knepley } 27142764a2aaSMatthew G. Knepley 27152764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) 27162764a2aaSMatthew G. Knepley { 27172764a2aaSMatthew G. Knepley PetscErrorCode ierr; 27182764a2aaSMatthew G. Knepley 27192764a2aaSMatthew G. Knepley PetscFunctionBegin; 27202764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 27212764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 27222764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;} 27232764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;} 27242764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;} 27252764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;} 27262764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;} 27272764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;} 27282764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27292764a2aaSMatthew G. Knepley } 27302764a2aaSMatthew G. Knepley 27312764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer) 27322764a2aaSMatthew G. Knepley { 27332764a2aaSMatthew G. Knepley PetscErrorCode ierr; 27342764a2aaSMatthew G. Knepley 27352764a2aaSMatthew G. Knepley PetscFunctionBegin; 27362764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 27372764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 27382764a2aaSMatthew G. Knepley if (x) {PetscValidPointer(x, 2); *x = prob->x;} 27392764a2aaSMatthew G. Knepley if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;} 27402764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27412764a2aaSMatthew G. Knepley } 27422764a2aaSMatthew G. Knepley 274358ebd649SToby Isaac /*@C 274458ebd649SToby Isaac PetscDSAddBoundary - Add a boundary condition to the model 274558ebd649SToby Isaac 274658ebd649SToby Isaac Input Parameters: 274758ebd649SToby Isaac + ds - The PetscDS object 27482d47a189SJulian Andrej . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 274958ebd649SToby Isaac . name - The BC name 275058ebd649SToby Isaac . labelname - The label defining constrained points 275158ebd649SToby Isaac . field - The field to constrain 2752e8ecbf3fSStefano Zampini . numcomps - The number of constrained field components (0 will constrain all fields) 275358ebd649SToby Isaac . comps - An array of constrained component numbers 275458ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 275558ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 275658ebd649SToby Isaac . ids - An array of ids for constrained points 275758ebd649SToby Isaac - ctx - An optional user context for bcFunc 275858ebd649SToby Isaac 275958ebd649SToby Isaac Options Database Keys: 276058ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 276158ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 276258ebd649SToby Isaac 276358ebd649SToby Isaac Level: developer 276458ebd649SToby Isaac 276558ebd649SToby Isaac .seealso: PetscDSGetBoundary() 276658ebd649SToby Isaac @*/ 2767a30ec4eaSSatish Balay PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), PetscInt numids, const PetscInt *ids, void *ctx) 276858ebd649SToby Isaac { 276958ebd649SToby Isaac DSBoundary b; 277058ebd649SToby Isaac PetscErrorCode ierr; 277158ebd649SToby Isaac 277258ebd649SToby Isaac PetscFunctionBegin; 277358ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 277458ebd649SToby Isaac ierr = PetscNew(&b);CHKERRQ(ierr); 277558ebd649SToby Isaac ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 277658ebd649SToby Isaac ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 277758ebd649SToby Isaac ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 277858ebd649SToby Isaac if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);} 277958ebd649SToby Isaac ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 278058ebd649SToby Isaac if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);} 2781f971fd6bSMatthew G. Knepley b->type = type; 278258ebd649SToby Isaac b->field = field; 278358ebd649SToby Isaac b->numcomps = numcomps; 278458ebd649SToby Isaac b->func = bcFunc; 278558ebd649SToby Isaac b->numids = numids; 278658ebd649SToby Isaac b->ctx = ctx; 278758ebd649SToby Isaac b->next = ds->boundary; 278858ebd649SToby Isaac ds->boundary = b; 278958ebd649SToby Isaac PetscFunctionReturn(0); 279058ebd649SToby Isaac } 279158ebd649SToby Isaac 2792b67eacb3SMatthew G. Knepley /*@C 2793b67eacb3SMatthew G. Knepley PetscDSUpdateBoundary - Change a boundary condition for the model 2794b67eacb3SMatthew G. Knepley 2795b67eacb3SMatthew G. Knepley Input Parameters: 2796b67eacb3SMatthew G. Knepley + ds - The PetscDS object 2797b67eacb3SMatthew G. Knepley . bd - The boundary condition number 2798b67eacb3SMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 2799b67eacb3SMatthew G. Knepley . name - The BC name 2800b67eacb3SMatthew G. Knepley . labelname - The label defining constrained points 2801b67eacb3SMatthew G. Knepley . field - The field to constrain 2802b67eacb3SMatthew G. Knepley . numcomps - The number of constrained field components 2803b67eacb3SMatthew G. Knepley . comps - An array of constrained component numbers 2804b67eacb3SMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 2805b67eacb3SMatthew G. Knepley . numids - The number of DMLabel ids for constrained points 2806b67eacb3SMatthew G. Knepley . ids - An array of ids for constrained points 2807b67eacb3SMatthew G. Knepley - ctx - An optional user context for bcFunc 2808b67eacb3SMatthew G. Knepley 28099a6efb6aSMatthew G. Knepley Note: The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from PetscDSGetNumBoundary(). 28109a6efb6aSMatthew G. Knepley 2811b67eacb3SMatthew G. Knepley Level: developer 2812b67eacb3SMatthew G. Knepley 28139a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary() 2814b67eacb3SMatthew G. Knepley @*/ 2815b67eacb3SMatthew G. Knepley PetscErrorCode PetscDSUpdateBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), PetscInt numids, const PetscInt *ids, void *ctx) 2816b67eacb3SMatthew G. Knepley { 2817b67eacb3SMatthew G. Knepley DSBoundary b = ds->boundary; 2818b67eacb3SMatthew G. Knepley PetscInt n = 0; 2819b67eacb3SMatthew G. Knepley PetscErrorCode ierr; 2820b67eacb3SMatthew G. Knepley 2821b67eacb3SMatthew G. Knepley PetscFunctionBegin; 2822b67eacb3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 2823b67eacb3SMatthew G. Knepley while (b) { 2824b67eacb3SMatthew G. Knepley if (n == bd) break; 2825b67eacb3SMatthew G. Knepley b = b->next; 2826b67eacb3SMatthew G. Knepley ++n; 2827b67eacb3SMatthew G. Knepley } 2828b67eacb3SMatthew G. Knepley if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 2829b67eacb3SMatthew G. Knepley if (name) { 2830b67eacb3SMatthew G. Knepley ierr = PetscFree(b->name);CHKERRQ(ierr); 2831b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 2832b67eacb3SMatthew G. Knepley } 2833b67eacb3SMatthew G. Knepley if (labelname) { 2834b67eacb3SMatthew G. Knepley ierr = PetscFree(b->labelname);CHKERRQ(ierr); 2835b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 2836b67eacb3SMatthew G. Knepley } 2837b67eacb3SMatthew G. Knepley if (numcomps >= 0 && numcomps != b->numcomps) { 2838b67eacb3SMatthew G. Knepley b->numcomps = numcomps; 2839b67eacb3SMatthew G. Knepley ierr = PetscFree(b->comps);CHKERRQ(ierr); 2840b67eacb3SMatthew G. Knepley ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 2841b67eacb3SMatthew G. Knepley if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);} 2842b67eacb3SMatthew G. Knepley } 2843b67eacb3SMatthew G. Knepley if (numids >= 0 && numids != b->numids) { 2844b67eacb3SMatthew G. Knepley b->numids = numids; 2845b67eacb3SMatthew G. Knepley ierr = PetscFree(b->ids);CHKERRQ(ierr); 2846b67eacb3SMatthew G. Knepley ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 2847b67eacb3SMatthew G. Knepley if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);} 2848b67eacb3SMatthew G. Knepley } 2849b67eacb3SMatthew G. Knepley b->type = type; 2850b67eacb3SMatthew G. Knepley if (field >= 0) {b->field = field;} 2851b67eacb3SMatthew G. Knepley if (bcFunc) {b->func = bcFunc;} 2852b67eacb3SMatthew G. Knepley if (ctx) {b->ctx = ctx;} 2853b67eacb3SMatthew G. Knepley PetscFunctionReturn(0); 2854b67eacb3SMatthew G. Knepley } 2855b67eacb3SMatthew G. Knepley 285658ebd649SToby Isaac /*@ 285758ebd649SToby Isaac PetscDSGetNumBoundary - Get the number of registered BC 285858ebd649SToby Isaac 285958ebd649SToby Isaac Input Parameters: 286058ebd649SToby Isaac . ds - The PetscDS object 286158ebd649SToby Isaac 286258ebd649SToby Isaac Output Parameters: 286358ebd649SToby Isaac . numBd - The number of BC 286458ebd649SToby Isaac 286558ebd649SToby Isaac Level: intermediate 286658ebd649SToby Isaac 286758ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary() 286858ebd649SToby Isaac @*/ 286958ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd) 287058ebd649SToby Isaac { 287158ebd649SToby Isaac DSBoundary b = ds->boundary; 287258ebd649SToby Isaac 287358ebd649SToby Isaac PetscFunctionBegin; 287458ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 287558ebd649SToby Isaac PetscValidPointer(numBd, 2); 287658ebd649SToby Isaac *numBd = 0; 287758ebd649SToby Isaac while (b) {++(*numBd); b = b->next;} 287858ebd649SToby Isaac PetscFunctionReturn(0); 287958ebd649SToby Isaac } 288058ebd649SToby Isaac 288158ebd649SToby Isaac /*@C 28829a6efb6aSMatthew G. Knepley PetscDSGetBoundary - Gets a boundary condition to the model 288358ebd649SToby Isaac 288458ebd649SToby Isaac Input Parameters: 288558ebd649SToby Isaac + ds - The PetscDS object 288658ebd649SToby Isaac - bd - The BC number 288758ebd649SToby Isaac 288858ebd649SToby Isaac Output Parameters: 28892d47a189SJulian Andrej + type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 289058ebd649SToby Isaac . name - The BC name 289158ebd649SToby Isaac . labelname - The label defining constrained points 289258ebd649SToby Isaac . field - The field to constrain 289358ebd649SToby Isaac . numcomps - The number of constrained field components 289458ebd649SToby Isaac . comps - An array of constrained component numbers 289558ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 289658ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 289758ebd649SToby Isaac . ids - An array of ids for constrained points 289858ebd649SToby Isaac - ctx - An optional user context for bcFunc 289958ebd649SToby Isaac 290058ebd649SToby Isaac Options Database Keys: 290158ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 290258ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 290358ebd649SToby Isaac 290458ebd649SToby Isaac Level: developer 290558ebd649SToby Isaac 290658ebd649SToby Isaac .seealso: PetscDSAddBoundary() 290758ebd649SToby Isaac @*/ 2908a30ec4eaSSatish Balay PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType *type, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(void), PetscInt *numids, const PetscInt **ids, void **ctx) 290958ebd649SToby Isaac { 291058ebd649SToby Isaac DSBoundary b = ds->boundary; 291158ebd649SToby Isaac PetscInt n = 0; 291258ebd649SToby Isaac 291358ebd649SToby Isaac PetscFunctionBegin; 291458ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 291558ebd649SToby Isaac while (b) { 291658ebd649SToby Isaac if (n == bd) break; 291758ebd649SToby Isaac b = b->next; 291858ebd649SToby Isaac ++n; 291958ebd649SToby Isaac } 292058ebd649SToby Isaac if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 2921f971fd6bSMatthew G. Knepley if (type) { 2922f971fd6bSMatthew G. Knepley PetscValidPointer(type, 3); 2923f971fd6bSMatthew G. Knepley *type = b->type; 292458ebd649SToby Isaac } 292558ebd649SToby Isaac if (name) { 292658ebd649SToby Isaac PetscValidPointer(name, 4); 292758ebd649SToby Isaac *name = b->name; 292858ebd649SToby Isaac } 292958ebd649SToby Isaac if (labelname) { 293058ebd649SToby Isaac PetscValidPointer(labelname, 5); 293158ebd649SToby Isaac *labelname = b->labelname; 293258ebd649SToby Isaac } 293358ebd649SToby Isaac if (field) { 293458ebd649SToby Isaac PetscValidPointer(field, 6); 293558ebd649SToby Isaac *field = b->field; 293658ebd649SToby Isaac } 293758ebd649SToby Isaac if (numcomps) { 293858ebd649SToby Isaac PetscValidPointer(numcomps, 7); 293958ebd649SToby Isaac *numcomps = b->numcomps; 294058ebd649SToby Isaac } 294158ebd649SToby Isaac if (comps) { 294258ebd649SToby Isaac PetscValidPointer(comps, 8); 294358ebd649SToby Isaac *comps = b->comps; 294458ebd649SToby Isaac } 294558ebd649SToby Isaac if (func) { 294658ebd649SToby Isaac PetscValidPointer(func, 9); 294758ebd649SToby Isaac *func = b->func; 294858ebd649SToby Isaac } 294958ebd649SToby Isaac if (numids) { 295058ebd649SToby Isaac PetscValidPointer(numids, 10); 295158ebd649SToby Isaac *numids = b->numids; 295258ebd649SToby Isaac } 295358ebd649SToby Isaac if (ids) { 295458ebd649SToby Isaac PetscValidPointer(ids, 11); 295558ebd649SToby Isaac *ids = b->ids; 295658ebd649SToby Isaac } 295758ebd649SToby Isaac if (ctx) { 295858ebd649SToby Isaac PetscValidPointer(ctx, 12); 295958ebd649SToby Isaac *ctx = b->ctx; 296058ebd649SToby Isaac } 296158ebd649SToby Isaac PetscFunctionReturn(0); 296258ebd649SToby Isaac } 296358ebd649SToby Isaac 29649252d075SMatthew G. Knepley /*@ 29659252d075SMatthew G. Knepley PetscDSCopyBoundary - Copy all boundary condition objects to the new problem 29669252d075SMatthew G. Knepley 29679252d075SMatthew G. Knepley Not collective 29689252d075SMatthew G. Knepley 29699252d075SMatthew G. Knepley Input Parameter: 29709252d075SMatthew G. Knepley . prob - The PetscDS object 29719252d075SMatthew G. Knepley 29729252d075SMatthew G. Knepley Output Parameter: 29739252d075SMatthew G. Knepley . newprob - The PetscDS copy 29749252d075SMatthew G. Knepley 29759252d075SMatthew G. Knepley Level: intermediate 29769252d075SMatthew G. Knepley 29779252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 29789252d075SMatthew G. Knepley @*/ 2979dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB) 2980dff059c6SToby Isaac { 2981dff059c6SToby Isaac DSBoundary b, next, *lastnext; 2982dff059c6SToby Isaac PetscErrorCode ierr; 2983dff059c6SToby Isaac 2984dff059c6SToby Isaac PetscFunctionBegin; 2985dff059c6SToby Isaac PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1); 2986dff059c6SToby Isaac PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2); 2987dff059c6SToby Isaac if (probA == probB) PetscFunctionReturn(0); 2988dff059c6SToby Isaac next = probB->boundary; 2989dff059c6SToby Isaac while (next) { 2990dff059c6SToby Isaac DSBoundary b = next; 2991dff059c6SToby Isaac 2992dff059c6SToby Isaac next = b->next; 2993dff059c6SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 2994dff059c6SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 2995dff059c6SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 2996dff059c6SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 2997dff059c6SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 2998dff059c6SToby Isaac } 2999dff059c6SToby Isaac lastnext = &(probB->boundary); 3000dff059c6SToby Isaac for (b = probA->boundary; b; b = b->next) { 3001dff059c6SToby Isaac DSBoundary bNew; 3002dff059c6SToby Isaac 3003459726d8SSatish Balay ierr = PetscNew(&bNew);CHKERRQ(ierr); 3004dff059c6SToby Isaac bNew->numcomps = b->numcomps; 3005dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr); 3006dff059c6SToby Isaac ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr); 3007dff059c6SToby Isaac bNew->numids = b->numids; 3008dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr); 3009dff059c6SToby Isaac ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr); 3010dff059c6SToby Isaac ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr); 3011dff059c6SToby Isaac ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr); 3012dff059c6SToby Isaac bNew->ctx = b->ctx; 3013f971fd6bSMatthew G. Knepley bNew->type = b->type; 3014dff059c6SToby Isaac bNew->field = b->field; 3015dff059c6SToby Isaac bNew->func = b->func; 3016dff059c6SToby Isaac 3017dff059c6SToby Isaac *lastnext = bNew; 3018dff059c6SToby Isaac lastnext = &(bNew->next); 3019dff059c6SToby Isaac } 3020dff059c6SToby Isaac PetscFunctionReturn(0); 3021dff059c6SToby Isaac } 3022dff059c6SToby Isaac 30239252d075SMatthew G. Knepley /*@C 30249252d075SMatthew G. Knepley PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout 30259252d075SMatthew G. Knepley 30269252d075SMatthew G. Knepley Not collective 30279252d075SMatthew G. Knepley 30289252d075SMatthew G. Knepley Input Parameter: 30299252d075SMatthew G. Knepley + prob - The PetscDS object 30309252d075SMatthew G. Knepley . numFields - Number of new fields 30319252d075SMatthew G. Knepley - fields - Old field number for each new field 30329252d075SMatthew G. Knepley 30339252d075SMatthew G. Knepley Output Parameter: 30349252d075SMatthew G. Knepley . newprob - The PetscDS copy 30359252d075SMatthew G. Knepley 30369252d075SMatthew G. Knepley Level: intermediate 30379252d075SMatthew G. Knepley 30389252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 30399252d075SMatthew G. Knepley @*/ 30409252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 30419252d075SMatthew G. Knepley { 30429252d075SMatthew G. Knepley PetscInt Nf, Nfn, fn, gn; 30439252d075SMatthew G. Knepley PetscErrorCode ierr; 30449252d075SMatthew G. Knepley 30459252d075SMatthew G. Knepley PetscFunctionBegin; 30469252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30479252d075SMatthew G. Knepley if (fields) PetscValidPointer(fields, 3); 30489252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 30499252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 30509252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr); 30519252d075SMatthew G. Knepley if (numFields > Nfn) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields %D to transfer must not be greater then the total number of fields %D", numFields, Nfn); 30529252d075SMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 30539252d075SMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 30549252d075SMatthew G. Knepley PetscPointFunc obj; 30559252d075SMatthew G. Knepley PetscPointFunc f0, f1; 30569252d075SMatthew G. Knepley PetscBdPointFunc f0Bd, f1Bd; 30579252d075SMatthew G. Knepley PetscRiemannFunc r; 30589252d075SMatthew G. Knepley 30599252d075SMatthew G. Knepley if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf); 30609252d075SMatthew G. Knepley ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr); 30619252d075SMatthew G. Knepley ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr); 30629252d075SMatthew G. Knepley ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr); 30639252d075SMatthew G. Knepley ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr); 30649252d075SMatthew G. Knepley ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr); 30659252d075SMatthew G. Knepley ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr); 30669252d075SMatthew G. Knepley ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr); 30679252d075SMatthew G. Knepley ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr); 30689252d075SMatthew G. Knepley for (gn = 0; gn < numFields; ++gn) { 30699252d075SMatthew G. Knepley const PetscInt g = fields ? fields[gn] : gn; 30709252d075SMatthew G. Knepley PetscPointJac g0, g1, g2, g3; 30719252d075SMatthew G. Knepley PetscPointJac g0p, g1p, g2p, g3p; 30729252d075SMatthew G. Knepley PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd; 30739252d075SMatthew G. Knepley 30749252d075SMatthew G. Knepley if (g >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", g, Nf); 30759252d075SMatthew G. Knepley ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr); 30769252d075SMatthew G. Knepley ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr); 30779252d075SMatthew G. Knepley ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr); 30789252d075SMatthew G. Knepley ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr); 30799252d075SMatthew G. Knepley ierr = PetscDSSetJacobianPreconditioner(prob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr); 30809252d075SMatthew G. Knepley ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr); 30819252d075SMatthew G. Knepley } 30829252d075SMatthew G. Knepley } 30839252d075SMatthew G. Knepley PetscFunctionReturn(0); 30849252d075SMatthew G. Knepley } 30859252d075SMatthew G. Knepley 3086da51fcedSMatthew G. Knepley /*@ 3087da51fcedSMatthew G. Knepley PetscDSCopyEquations - Copy all pointwise function pointers to the new problem 3088da51fcedSMatthew G. Knepley 3089da51fcedSMatthew G. Knepley Not collective 3090da51fcedSMatthew G. Knepley 3091da51fcedSMatthew G. Knepley Input Parameter: 3092da51fcedSMatthew G. Knepley . prob - The PetscDS object 3093da51fcedSMatthew G. Knepley 3094da51fcedSMatthew G. Knepley Output Parameter: 3095da51fcedSMatthew G. Knepley . newprob - The PetscDS copy 3096da51fcedSMatthew G. Knepley 3097da51fcedSMatthew G. Knepley Level: intermediate 3098da51fcedSMatthew G. Knepley 30999252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 3100da51fcedSMatthew G. Knepley @*/ 3101da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob) 3102da51fcedSMatthew G. Knepley { 31039252d075SMatthew G. Knepley PetscInt Nf, Ng; 3104da51fcedSMatthew G. Knepley PetscErrorCode ierr; 3105da51fcedSMatthew G. Knepley 3106da51fcedSMatthew G. Knepley PetscFunctionBegin; 3107da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3108da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 3109da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3110da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr); 311113903a91SSatish Balay if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng); 31129252d075SMatthew G. Knepley ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr); 31139252d075SMatthew G. Knepley PetscFunctionReturn(0); 31149252d075SMatthew G. Knepley } 31159252d075SMatthew G. Knepley /*@ 31169252d075SMatthew G. Knepley PetscDSCopyConstants - Copy all constants to the new problem 3117da51fcedSMatthew G. Knepley 31189252d075SMatthew G. Knepley Not collective 31199252d075SMatthew G. Knepley 31209252d075SMatthew G. Knepley Input Parameter: 31219252d075SMatthew G. Knepley . prob - The PetscDS object 31229252d075SMatthew G. Knepley 31239252d075SMatthew G. Knepley Output Parameter: 31249252d075SMatthew G. Knepley . newprob - The PetscDS copy 31259252d075SMatthew G. Knepley 31269252d075SMatthew G. Knepley Level: intermediate 31279252d075SMatthew G. Knepley 31289252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 31299252d075SMatthew G. Knepley @*/ 31309252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob) 31319252d075SMatthew G. Knepley { 31329252d075SMatthew G. Knepley PetscInt Nc; 31339252d075SMatthew G. Knepley const PetscScalar *constants; 31349252d075SMatthew G. Knepley PetscErrorCode ierr; 31359252d075SMatthew G. Knepley 31369252d075SMatthew G. Knepley PetscFunctionBegin; 31379252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 31389252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 31399252d075SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr); 31409252d075SMatthew G. Knepley ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr); 3141da51fcedSMatthew G. Knepley PetscFunctionReturn(0); 3142da51fcedSMatthew G. Knepley } 3143da51fcedSMatthew G. Knepley 3144b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob) 3145b1353e8eSMatthew G. Knepley { 3146df3a45bdSMatthew G. Knepley PetscInt dim, Nf, f; 3147b1353e8eSMatthew G. Knepley PetscErrorCode ierr; 3148b1353e8eSMatthew G. Knepley 3149b1353e8eSMatthew G. Knepley PetscFunctionBegin; 3150b1353e8eSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3151b1353e8eSMatthew G. Knepley PetscValidPointer(subprob, 3); 3152b1353e8eSMatthew G. Knepley if (height == 0) {*subprob = prob; PetscFunctionReturn(0);} 3153b1353e8eSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3154df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 3155df3a45bdSMatthew G. Knepley if (height > dim) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_OUTOFRANGE, "DS can only handle height in [0, %D], not %D", dim, height); 3156df3a45bdSMatthew G. Knepley if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);} 3157df3a45bdSMatthew G. Knepley if (!prob->subprobs[height-1]) { 3158b1353e8eSMatthew G. Knepley PetscInt cdim; 3159b1353e8eSMatthew G. Knepley 3160df3a45bdSMatthew G. Knepley ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr); 3161b1353e8eSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr); 3162df3a45bdSMatthew G. Knepley ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr); 3163b1353e8eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3164b1353e8eSMatthew G. Knepley PetscFE subfe; 3165b1353e8eSMatthew G. Knepley PetscObject obj; 3166b1353e8eSMatthew G. Knepley PetscClassId id; 3167b1353e8eSMatthew G. Knepley 3168b1353e8eSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 3169b1353e8eSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3170b1353e8eSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);} 3171b1353e8eSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f); 3172df3a45bdSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr); 3173b1353e8eSMatthew G. Knepley } 3174b1353e8eSMatthew G. Knepley } 3175df3a45bdSMatthew G. Knepley *subprob = prob->subprobs[height-1]; 3176b1353e8eSMatthew G. Knepley PetscFunctionReturn(0); 3177b1353e8eSMatthew G. Knepley } 3178b1353e8eSMatthew G. Knepley 3179bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob) 31802764a2aaSMatthew G. Knepley { 3181931fb3b8SToby Isaac PetscErrorCode ierr; 3182931fb3b8SToby Isaac 31832764a2aaSMatthew G. Knepley PetscFunctionBegin; 3184931fb3b8SToby Isaac ierr = PetscFree(prob->data);CHKERRQ(ierr); 31852764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31862764a2aaSMatthew G. Knepley } 31872764a2aaSMatthew G. Knepley 3188bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob) 31892764a2aaSMatthew G. Knepley { 31902764a2aaSMatthew G. Knepley PetscFunctionBegin; 31912764a2aaSMatthew G. Knepley prob->ops->setfromoptions = NULL; 31922764a2aaSMatthew G. Knepley prob->ops->setup = NULL; 31932764a2aaSMatthew G. Knepley prob->ops->view = NULL; 31942764a2aaSMatthew G. Knepley prob->ops->destroy = PetscDSDestroy_Basic; 31952764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31962764a2aaSMatthew G. Knepley } 31972764a2aaSMatthew G. Knepley 31982764a2aaSMatthew G. Knepley /*MC 31992764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 32002764a2aaSMatthew G. Knepley 32012764a2aaSMatthew G. Knepley Level: intermediate 32022764a2aaSMatthew G. Knepley 32032764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType() 32042764a2aaSMatthew G. Knepley M*/ 32052764a2aaSMatthew G. Knepley 32062764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob) 32072764a2aaSMatthew G. Knepley { 32082764a2aaSMatthew G. Knepley PetscDS_Basic *b; 32092764a2aaSMatthew G. Knepley PetscErrorCode ierr; 32102764a2aaSMatthew G. Knepley 32112764a2aaSMatthew G. Knepley PetscFunctionBegin; 3212931fb3b8SToby Isaac PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 32132764a2aaSMatthew G. Knepley ierr = PetscNewLog(prob, &b);CHKERRQ(ierr); 32142764a2aaSMatthew G. Knepley prob->data = b; 32152764a2aaSMatthew G. Knepley 32162764a2aaSMatthew G. Knepley ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr); 32172764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 32182764a2aaSMatthew G. Knepley } 3219