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) { 152*40967b3bSMatthew 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); 195*40967b3bSMatthew G. Knepley 196*40967b3bSMatthew G. Knepley for (b = prob->boundary; b; b = b->next) { 197*40967b3bSMatthew G. Knepley PetscInt c, i; 198*40967b3bSMatthew G. Knepley 199*40967b3bSMatthew G. Knepley if (b->field != f) continue; 200*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 201*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->labelname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr); 202*40967b3bSMatthew G. Knepley if (!b->numcomps) { 203*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " all components\n");CHKERRQ(ierr); 204*40967b3bSMatthew G. Knepley } else { 205*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " components: ");CHKERRQ(ierr); 206*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 207*40967b3bSMatthew G. Knepley for (c = 0; c < b->numcomps; ++c) { 208*40967b3bSMatthew G. Knepley if (c > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 209*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->comps[c]);CHKERRQ(ierr); 210*40967b3bSMatthew G. Knepley } 211*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 212*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 213*40967b3bSMatthew G. Knepley } 214*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " ids: ");CHKERRQ(ierr); 215*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 216*40967b3bSMatthew G. Knepley for (i = 0; i < b->numids; ++i) { 217*40967b3bSMatthew G. Knepley if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 218*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->ids[i]);CHKERRQ(ierr); 219*40967b3bSMatthew G. Knepley } 220*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 221*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 222*40967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 223*40967b3bSMatthew 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; 4410c2f2876SMatthew G. Knepley void **tmpctx; 442a6cbbb48SMatthew G. Knepley PetscInt Nf = prob->Nf, f, i; 4432764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4442764a2aaSMatthew G. Knepley 4452764a2aaSMatthew G. Knepley PetscFunctionBegin; 4462764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 4472764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 4482764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr); 449f744cafaSSander Arens ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr); 450f744cafaSSander 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];} 451f744cafaSSander 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;} 452f744cafaSSander Arens ierr = PetscFree3(prob->disc, prob->implicit, prob->adjacency);CHKERRQ(ierr); 4532764a2aaSMatthew G. Knepley prob->Nf = NfNew; 4542764a2aaSMatthew G. Knepley prob->disc = tmpd; 455249df284SMatthew G. Knepley prob->implicit = tmpi; 456a6cbbb48SMatthew G. Knepley prob->adjacency = tmpa; 457b7e05686SMatthew 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); 45832d2bbc9SMatthew G. Knepley ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr); 4592764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f]; 4602764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f]; 4612764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f]; 462475e0ac9SMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f]; 4630c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f]; 46432d2bbc9SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f]; 4650c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f]; 4662764a2aaSMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL; 4672764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL; 4682764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL; 469475e0ac9SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL; 470b7e05686SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL; 4710c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL; 47232d2bbc9SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL; 4730c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL; 474b7e05686SMatthew G. Knepley ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr); 47532d2bbc9SMatthew G. Knepley ierr = PetscFree(prob->update);CHKERRQ(ierr); 4762764a2aaSMatthew G. Knepley prob->obj = tmpobj; 4772764a2aaSMatthew G. Knepley prob->f = tmpf; 4782764a2aaSMatthew G. Knepley prob->g = tmpg; 479475e0ac9SMatthew G. Knepley prob->gp = tmpgp; 480b7e05686SMatthew G. Knepley prob->gt = tmpgt; 4810c2f2876SMatthew G. Knepley prob->r = tmpr; 48232d2bbc9SMatthew G. Knepley prob->update = tmpup; 4830c2f2876SMatthew G. Knepley prob->ctx = tmpctx; 484c371a6d1SMatthew G. Knepley ierr = PetscCalloc3(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew, &tmpexactSol);CHKERRQ(ierr); 4852764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f]; 4862764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f]; 487c371a6d1SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f]; 4882764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL; 4892764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL; 490c371a6d1SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL; 491c371a6d1SMatthew G. Knepley ierr = PetscFree3(prob->fBd, prob->gBd, prob->exactSol);CHKERRQ(ierr); 4922764a2aaSMatthew G. Knepley prob->fBd = tmpfbd; 4932764a2aaSMatthew G. Knepley prob->gBd = tmpgbd; 494c371a6d1SMatthew G. Knepley prob->exactSol = tmpexactSol; 4952764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4962764a2aaSMatthew G. Knepley } 4972764a2aaSMatthew G. Knepley 4982764a2aaSMatthew G. Knepley /*@ 4992764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 5002764a2aaSMatthew G. Knepley 5012764a2aaSMatthew G. Knepley Collective on PetscDS 5022764a2aaSMatthew G. Knepley 5032764a2aaSMatthew G. Knepley Input Parameter: 5042764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 5052764a2aaSMatthew G. Knepley 5062764a2aaSMatthew G. Knepley Level: developer 5072764a2aaSMatthew G. Knepley 5082764a2aaSMatthew G. Knepley .seealso PetscDSView() 5092764a2aaSMatthew G. Knepley @*/ 5102764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob) 5112764a2aaSMatthew G. Knepley { 5122764a2aaSMatthew G. Knepley PetscInt f; 51358ebd649SToby Isaac DSBoundary next; 5142764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5152764a2aaSMatthew G. Knepley 5162764a2aaSMatthew G. Knepley PetscFunctionBegin; 5172764a2aaSMatthew G. Knepley if (!*prob) PetscFunctionReturn(0); 5182764a2aaSMatthew G. Knepley PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1); 5192764a2aaSMatthew G. Knepley 5202764a2aaSMatthew G. Knepley if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);} 5212764a2aaSMatthew G. Knepley ((PetscObject) (*prob))->refct = 0; 522df3a45bdSMatthew G. Knepley if ((*prob)->subprobs) { 523df3a45bdSMatthew G. Knepley PetscInt dim, d; 524df3a45bdSMatthew G. Knepley 525df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(*prob, &dim);CHKERRQ(ierr); 526df3a45bdSMatthew G. Knepley for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*prob)->subprobs[d]);CHKERRQ(ierr);} 527df3a45bdSMatthew G. Knepley } 528df3a45bdSMatthew G. Knepley ierr = PetscFree((*prob)->subprobs);CHKERRQ(ierr); 5292764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr); 5302764a2aaSMatthew G. Knepley for (f = 0; f < (*prob)->Nf; ++f) { 5312764a2aaSMatthew G. Knepley ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr); 5322764a2aaSMatthew G. Knepley } 533f744cafaSSander Arens ierr = PetscFree3((*prob)->disc, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr); 534b7e05686SMatthew G. Knepley ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr); 53532d2bbc9SMatthew G. Knepley ierr = PetscFree((*prob)->update);CHKERRQ(ierr); 536c371a6d1SMatthew G. Knepley ierr = PetscFree3((*prob)->fBd,(*prob)->gBd,(*prob)->exactSol);CHKERRQ(ierr); 5372764a2aaSMatthew G. Knepley if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);} 53858ebd649SToby Isaac next = (*prob)->boundary; 53958ebd649SToby Isaac while (next) { 54058ebd649SToby Isaac DSBoundary b = next; 54158ebd649SToby Isaac 54258ebd649SToby Isaac next = b->next; 54358ebd649SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 54458ebd649SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 54558ebd649SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 54658ebd649SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 54758ebd649SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 54858ebd649SToby Isaac } 54997b6e6e8SMatthew G. Knepley ierr = PetscFree((*prob)->constants);CHKERRQ(ierr); 5502764a2aaSMatthew G. Knepley ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr); 5512764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5522764a2aaSMatthew G. Knepley } 5532764a2aaSMatthew G. Knepley 5542764a2aaSMatthew G. Knepley /*@ 5552764a2aaSMatthew G. Knepley PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType(). 5562764a2aaSMatthew G. Knepley 5572764a2aaSMatthew G. Knepley Collective on MPI_Comm 5582764a2aaSMatthew G. Knepley 5592764a2aaSMatthew G. Knepley Input Parameter: 5602764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object 5612764a2aaSMatthew G. Knepley 5622764a2aaSMatthew G. Knepley Output Parameter: 5632764a2aaSMatthew G. Knepley . prob - The PetscDS object 5642764a2aaSMatthew G. Knepley 5652764a2aaSMatthew G. Knepley Level: beginner 5662764a2aaSMatthew G. Knepley 5672764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC 5682764a2aaSMatthew G. Knepley @*/ 5692764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob) 5702764a2aaSMatthew G. Knepley { 5712764a2aaSMatthew G. Knepley PetscDS p; 5722764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5732764a2aaSMatthew G. Knepley 5742764a2aaSMatthew G. Knepley PetscFunctionBegin; 5752764a2aaSMatthew G. Knepley PetscValidPointer(prob, 2); 5762764a2aaSMatthew G. Knepley *prob = NULL; 5772764a2aaSMatthew G. Knepley ierr = PetscDSInitializePackage();CHKERRQ(ierr); 5782764a2aaSMatthew G. Knepley 57973107ff1SLisandro Dalcin ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr); 5802764a2aaSMatthew G. Knepley 5812764a2aaSMatthew G. Knepley p->Nf = 0; 5822764a2aaSMatthew G. Knepley p->setup = PETSC_FALSE; 58397b6e6e8SMatthew G. Knepley p->numConstants = 0; 58497b6e6e8SMatthew G. Knepley p->constants = NULL; 585a859676bSMatthew G. Knepley p->dimEmbed = -1; 58603d90f89SMatthew G. Knepley p->defaultAdj[0] = PETSC_FALSE; 58703d90f89SMatthew G. Knepley p->defaultAdj[1] = PETSC_TRUE; 58855c1f793SMatthew G. Knepley p->useJacPre = PETSC_TRUE; 5892764a2aaSMatthew G. Knepley 5902764a2aaSMatthew G. Knepley *prob = p; 5912764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5922764a2aaSMatthew G. Knepley } 5932764a2aaSMatthew G. Knepley 594bc4ae4beSMatthew G. Knepley /*@ 595bc4ae4beSMatthew G. Knepley PetscDSGetNumFields - Returns the number of fields in the DS 596bc4ae4beSMatthew G. Knepley 597bc4ae4beSMatthew G. Knepley Not collective 598bc4ae4beSMatthew G. Knepley 599bc4ae4beSMatthew G. Knepley Input Parameter: 600bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 601bc4ae4beSMatthew G. Knepley 602bc4ae4beSMatthew G. Knepley Output Parameter: 603bc4ae4beSMatthew G. Knepley . Nf - The number of fields 604bc4ae4beSMatthew G. Knepley 605bc4ae4beSMatthew G. Knepley Level: beginner 606bc4ae4beSMatthew G. Knepley 607bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate() 608bc4ae4beSMatthew G. Knepley @*/ 6092764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) 6102764a2aaSMatthew G. Knepley { 6112764a2aaSMatthew G. Knepley PetscFunctionBegin; 6122764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6132764a2aaSMatthew G. Knepley PetscValidPointer(Nf, 2); 6142764a2aaSMatthew G. Knepley *Nf = prob->Nf; 6152764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6162764a2aaSMatthew G. Knepley } 6172764a2aaSMatthew G. Knepley 618bc4ae4beSMatthew G. Knepley /*@ 619a859676bSMatthew G. Knepley PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations 620bc4ae4beSMatthew G. Knepley 621bc4ae4beSMatthew G. Knepley Not collective 622bc4ae4beSMatthew G. Knepley 623bc4ae4beSMatthew G. Knepley Input Parameter: 624bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 625bc4ae4beSMatthew G. Knepley 626bc4ae4beSMatthew G. Knepley Output Parameter: 627bc4ae4beSMatthew G. Knepley . dim - The spatial dimension 628bc4ae4beSMatthew G. Knepley 629bc4ae4beSMatthew G. Knepley Level: beginner 630bc4ae4beSMatthew G. Knepley 631a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate() 632bc4ae4beSMatthew G. Knepley @*/ 6332764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) 6342764a2aaSMatthew G. Knepley { 6352764a2aaSMatthew G. Knepley PetscErrorCode ierr; 6362764a2aaSMatthew G. Knepley 6372764a2aaSMatthew G. Knepley PetscFunctionBegin; 6382764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6392764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 6402764a2aaSMatthew G. Knepley *dim = 0; 6419de99aefSMatthew G. Knepley if (prob->Nf) { 6429de99aefSMatthew G. Knepley PetscObject obj; 6439de99aefSMatthew G. Knepley PetscClassId id; 6449de99aefSMatthew G. Knepley 6459de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 6469de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 6479de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);} 6489de99aefSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);} 6499de99aefSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 6509de99aefSMatthew G. Knepley } 6512764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6522764a2aaSMatthew G. Knepley } 6532764a2aaSMatthew G. Knepley 654bc4ae4beSMatthew G. Knepley /*@ 655a859676bSMatthew G. Knepley PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 656a859676bSMatthew G. Knepley 657a859676bSMatthew G. Knepley Not collective 658a859676bSMatthew G. Knepley 659a859676bSMatthew G. Knepley Input Parameter: 660a859676bSMatthew G. Knepley . prob - The PetscDS object 661a859676bSMatthew G. Knepley 662a859676bSMatthew G. Knepley Output Parameter: 663a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension 664a859676bSMatthew G. Knepley 665a859676bSMatthew G. Knepley Level: beginner 666a859676bSMatthew G. Knepley 667a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 668a859676bSMatthew G. Knepley @*/ 669a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed) 670a859676bSMatthew G. Knepley { 671a859676bSMatthew G. Knepley PetscFunctionBegin; 672a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 673a859676bSMatthew G. Knepley PetscValidPointer(dimEmbed, 2); 674a859676bSMatthew G. Knepley if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS"); 675a859676bSMatthew G. Knepley *dimEmbed = prob->dimEmbed; 676a859676bSMatthew G. Knepley PetscFunctionReturn(0); 677a859676bSMatthew G. Knepley } 678a859676bSMatthew G. Knepley 679a859676bSMatthew G. Knepley /*@ 680a859676bSMatthew G. Knepley PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 681a859676bSMatthew G. Knepley 682ebfe4b0dSMatthew G. Knepley Logically collective on DS 683a859676bSMatthew G. Knepley 684a859676bSMatthew G. Knepley Input Parameters: 685a859676bSMatthew G. Knepley + prob - The PetscDS object 686a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension 687a859676bSMatthew G. Knepley 688a859676bSMatthew G. Knepley Level: beginner 689a859676bSMatthew G. Knepley 690a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 691a859676bSMatthew G. Knepley @*/ 692a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed) 693a859676bSMatthew G. Knepley { 694a859676bSMatthew G. Knepley PetscFunctionBegin; 695a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 696ebfe4b0dSMatthew G. Knepley if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed); 697a859676bSMatthew G. Knepley prob->dimEmbed = dimEmbed; 698a859676bSMatthew G. Knepley PetscFunctionReturn(0); 699a859676bSMatthew G. Knepley } 700a859676bSMatthew G. Knepley 701a859676bSMatthew G. Knepley /*@ 7028edf6225SMatthew G. Knepley PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell 7038edf6225SMatthew G. Knepley 7048edf6225SMatthew G. Knepley Not collective 7058edf6225SMatthew G. Knepley 7068edf6225SMatthew G. Knepley Input Parameter: 7078edf6225SMatthew G. Knepley . prob - The PetscDS object 7088edf6225SMatthew G. Knepley 7098edf6225SMatthew G. Knepley Output Parameter: 7108edf6225SMatthew G. Knepley . isHybrid - The flag 7118edf6225SMatthew G. Knepley 7128edf6225SMatthew G. Knepley Level: developer 7138edf6225SMatthew G. Knepley 7148edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate() 7158edf6225SMatthew G. Knepley @*/ 7168edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid) 7178edf6225SMatthew G. Knepley { 7188edf6225SMatthew G. Knepley PetscFunctionBegin; 7198edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7208edf6225SMatthew G. Knepley PetscValidPointer(isHybrid, 2); 7218edf6225SMatthew G. Knepley *isHybrid = prob->isHybrid; 7228edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7238edf6225SMatthew G. Knepley } 7248edf6225SMatthew G. Knepley 7258edf6225SMatthew G. Knepley /*@ 7268edf6225SMatthew G. Knepley PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell 7278edf6225SMatthew G. Knepley 7288edf6225SMatthew G. Knepley Not collective 7298edf6225SMatthew G. Knepley 7308edf6225SMatthew G. Knepley Input Parameters: 7318edf6225SMatthew G. Knepley + prob - The PetscDS object 7328edf6225SMatthew G. Knepley - isHybrid - The flag 7338edf6225SMatthew G. Knepley 7348edf6225SMatthew G. Knepley Level: developer 7358edf6225SMatthew G. Knepley 7368edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate() 7378edf6225SMatthew G. Knepley @*/ 7388edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid) 7398edf6225SMatthew G. Knepley { 7408edf6225SMatthew G. Knepley PetscFunctionBegin; 7418edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7428edf6225SMatthew G. Knepley prob->isHybrid = isHybrid; 7438edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7448edf6225SMatthew G. Knepley } 7458edf6225SMatthew G. Knepley 7468edf6225SMatthew G. Knepley /*@ 747bc4ae4beSMatthew G. Knepley PetscDSGetTotalDimension - Returns the total size of the approximation space for this system 748bc4ae4beSMatthew G. Knepley 749bc4ae4beSMatthew G. Knepley Not collective 750bc4ae4beSMatthew G. Knepley 751bc4ae4beSMatthew G. Knepley Input Parameter: 752bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 753bc4ae4beSMatthew G. Knepley 754bc4ae4beSMatthew G. Knepley Output Parameter: 755bc4ae4beSMatthew G. Knepley . dim - The total problem dimension 756bc4ae4beSMatthew G. Knepley 757bc4ae4beSMatthew G. Knepley Level: beginner 758bc4ae4beSMatthew G. Knepley 759bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 760bc4ae4beSMatthew G. Knepley @*/ 7612764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) 7622764a2aaSMatthew G. Knepley { 7632764a2aaSMatthew G. Knepley PetscErrorCode ierr; 7642764a2aaSMatthew G. Knepley 7652764a2aaSMatthew G. Knepley PetscFunctionBegin; 7662764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7672764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 7682764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 7692764a2aaSMatthew G. Knepley *dim = prob->totDim; 7702764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 7712764a2aaSMatthew G. Knepley } 7722764a2aaSMatthew G. Knepley 773bc4ae4beSMatthew G. Knepley /*@ 774bc4ae4beSMatthew G. Knepley PetscDSGetTotalComponents - Returns the total number of components in this system 775bc4ae4beSMatthew G. Knepley 776bc4ae4beSMatthew G. Knepley Not collective 777bc4ae4beSMatthew G. Knepley 778bc4ae4beSMatthew G. Knepley Input Parameter: 779bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 780bc4ae4beSMatthew G. Knepley 781bc4ae4beSMatthew G. Knepley Output Parameter: 782bc4ae4beSMatthew G. Knepley . dim - The total number of components 783bc4ae4beSMatthew G. Knepley 784bc4ae4beSMatthew G. Knepley Level: beginner 785bc4ae4beSMatthew G. Knepley 786bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 787bc4ae4beSMatthew G. Knepley @*/ 7882764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) 7892764a2aaSMatthew G. Knepley { 7902764a2aaSMatthew G. Knepley PetscErrorCode ierr; 7912764a2aaSMatthew G. Knepley 7922764a2aaSMatthew G. Knepley PetscFunctionBegin; 7932764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7942764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 7952764a2aaSMatthew G. Knepley PetscValidPointer(Nc, 2); 7962764a2aaSMatthew G. Knepley *Nc = prob->totComp; 7972764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 7982764a2aaSMatthew G. Knepley } 7992764a2aaSMatthew G. Knepley 800bc4ae4beSMatthew G. Knepley /*@ 801bc4ae4beSMatthew G. Knepley PetscDSGetDiscretization - Returns the discretization object for the given field 802bc4ae4beSMatthew G. Knepley 803bc4ae4beSMatthew G. Knepley Not collective 804bc4ae4beSMatthew G. Knepley 805bc4ae4beSMatthew G. Knepley Input Parameters: 806bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 807bc4ae4beSMatthew G. Knepley - f - The field number 808bc4ae4beSMatthew G. Knepley 809bc4ae4beSMatthew G. Knepley Output Parameter: 810bc4ae4beSMatthew G. Knepley . disc - The discretization object 811bc4ae4beSMatthew G. Knepley 812bc4ae4beSMatthew G. Knepley Level: beginner 813bc4ae4beSMatthew G. Knepley 814f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 815bc4ae4beSMatthew G. Knepley @*/ 8162764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 8172764a2aaSMatthew G. Knepley { 8182764a2aaSMatthew G. Knepley PetscFunctionBegin; 8192764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8202764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 8212764a2aaSMatthew 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); 8222764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 8232764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8242764a2aaSMatthew G. Knepley } 8252764a2aaSMatthew G. Knepley 826bc4ae4beSMatthew G. Knepley /*@ 827bc4ae4beSMatthew G. Knepley PetscDSSetDiscretization - Sets the discretization object for the given field 828bc4ae4beSMatthew G. Knepley 829bc4ae4beSMatthew G. Knepley Not collective 830bc4ae4beSMatthew G. Knepley 831bc4ae4beSMatthew G. Knepley Input Parameters: 832bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 833bc4ae4beSMatthew G. Knepley . f - The field number 834bc4ae4beSMatthew G. Knepley - disc - The discretization object 835bc4ae4beSMatthew G. Knepley 836bc4ae4beSMatthew G. Knepley Level: beginner 837bc4ae4beSMatthew G. Knepley 838bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 839bc4ae4beSMatthew G. Knepley @*/ 8402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 8412764a2aaSMatthew G. Knepley { 8422764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8432764a2aaSMatthew G. Knepley 8442764a2aaSMatthew G. Knepley PetscFunctionBegin; 8452764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8462764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 8472764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 8482764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 849c10f2116SMatthew G. Knepley ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr); 8502764a2aaSMatthew G. Knepley prob->disc[f] = disc; 8512764a2aaSMatthew G. Knepley ierr = PetscObjectReference(disc);CHKERRQ(ierr); 852249df284SMatthew G. Knepley { 853249df284SMatthew G. Knepley PetscClassId id; 854249df284SMatthew G. Knepley 855249df284SMatthew G. Knepley ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr); 8561cf84007SMatthew G. Knepley if (id == PETSCFE_CLASSID) { 8571cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr); 8581cf84007SMatthew G. Knepley ierr = PetscDSSetAdjacency(prob, f, PETSC_FALSE, PETSC_TRUE);CHKERRQ(ierr); 8591cf84007SMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 8601cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr); 8611cf84007SMatthew G. Knepley ierr = PetscDSSetAdjacency(prob, f, PETSC_TRUE, PETSC_FALSE);CHKERRQ(ierr); 862a6cbbb48SMatthew G. Knepley } 863249df284SMatthew G. Knepley } 8642764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8652764a2aaSMatthew G. Knepley } 8662764a2aaSMatthew G. Knepley 867bc4ae4beSMatthew G. Knepley /*@ 868bc4ae4beSMatthew G. Knepley PetscDSAddDiscretization - Adds a discretization object 869bc4ae4beSMatthew G. Knepley 870bc4ae4beSMatthew G. Knepley Not collective 871bc4ae4beSMatthew G. Knepley 872bc4ae4beSMatthew G. Knepley Input Parameters: 873bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 874bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object 875bc4ae4beSMatthew G. Knepley 876bc4ae4beSMatthew G. Knepley Level: beginner 877bc4ae4beSMatthew G. Knepley 878bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 879bc4ae4beSMatthew G. Knepley @*/ 8802764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) 8812764a2aaSMatthew G. Knepley { 8822764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8832764a2aaSMatthew G. Knepley 8842764a2aaSMatthew G. Knepley PetscFunctionBegin; 8852764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr); 8862764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8872764a2aaSMatthew G. Knepley } 8882764a2aaSMatthew G. Knepley 889249df284SMatthew G. Knepley /*@ 890249df284SMatthew G. Knepley PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX 891249df284SMatthew G. Knepley 892249df284SMatthew G. Knepley Not collective 893249df284SMatthew G. Knepley 894249df284SMatthew G. Knepley Input Parameters: 895249df284SMatthew G. Knepley + prob - The PetscDS object 896249df284SMatthew G. Knepley - f - The field number 897249df284SMatthew G. Knepley 898249df284SMatthew G. Knepley Output Parameter: 899249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field 900249df284SMatthew G. Knepley 901249df284SMatthew G. Knepley Level: developer 902249df284SMatthew G. Knepley 903f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 904249df284SMatthew G. Knepley @*/ 905249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit) 906249df284SMatthew G. Knepley { 907249df284SMatthew G. Knepley PetscFunctionBegin; 908249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 909249df284SMatthew G. Knepley PetscValidPointer(implicit, 3); 910249df284SMatthew 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); 911249df284SMatthew G. Knepley *implicit = prob->implicit[f]; 912249df284SMatthew G. Knepley PetscFunctionReturn(0); 913249df284SMatthew G. Knepley } 914249df284SMatthew G. Knepley 915249df284SMatthew G. Knepley /*@ 916249df284SMatthew G. Knepley PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX 917249df284SMatthew G. Knepley 918249df284SMatthew G. Knepley Not collective 919249df284SMatthew G. Knepley 920249df284SMatthew G. Knepley Input Parameters: 921249df284SMatthew G. Knepley + prob - The PetscDS object 922249df284SMatthew G. Knepley . f - The field number 923249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field 924249df284SMatthew G. Knepley 925249df284SMatthew G. Knepley Level: developer 926249df284SMatthew G. Knepley 927f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 928249df284SMatthew G. Knepley @*/ 929249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit) 930249df284SMatthew G. Knepley { 931249df284SMatthew G. Knepley PetscFunctionBegin; 932249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 933249df284SMatthew 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); 934249df284SMatthew G. Knepley prob->implicit[f] = implicit; 935249df284SMatthew G. Knepley PetscFunctionReturn(0); 936249df284SMatthew G. Knepley } 937249df284SMatthew G. Knepley 938a6cbbb48SMatthew G. Knepley /*@ 939a6cbbb48SMatthew G. Knepley PetscDSGetAdjacency - Returns the flags for determining variable influence 940a6cbbb48SMatthew G. Knepley 941a6cbbb48SMatthew G. Knepley Not collective 942a6cbbb48SMatthew G. Knepley 943a6cbbb48SMatthew G. Knepley Input Parameters: 944a6cbbb48SMatthew G. Knepley + prob - The PetscDS object 945a6cbbb48SMatthew G. Knepley - f - The field number 946a6cbbb48SMatthew G. Knepley 947a6cbbb48SMatthew G. Knepley Output Parameter: 948a6cbbb48SMatthew G. Knepley + useCone - Flag for variable influence starting with the cone operation 949a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure 950a6cbbb48SMatthew G. Knepley 951a6cbbb48SMatthew G. Knepley Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure() 952a6cbbb48SMatthew G. Knepley 953a6cbbb48SMatthew G. Knepley Level: developer 954a6cbbb48SMatthew G. Knepley 955f744cafaSSander Arens .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 956a6cbbb48SMatthew G. Knepley @*/ 957a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure) 958a6cbbb48SMatthew G. Knepley { 959a6cbbb48SMatthew G. Knepley PetscFunctionBegin; 960a6cbbb48SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 9611cf84007SMatthew G. Knepley if (useCone) PetscValidPointer(useCone, 3); 9621cf84007SMatthew G. Knepley if (useClosure) PetscValidPointer(useClosure, 4); 96306cc46feSMatthew G. Knepley if (f < 0) { 96406cc46feSMatthew G. Knepley if (useCone) *useCone = prob->defaultAdj[0]; 96506cc46feSMatthew G. Knepley if (useClosure) *useClosure = prob->defaultAdj[1]; 96606cc46feSMatthew G. Knepley } else { 96706cc46feSMatthew 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); 9681cf84007SMatthew G. Knepley if (useCone) *useCone = prob->adjacency[f*2+0]; 9691cf84007SMatthew G. Knepley if (useClosure) *useClosure = prob->adjacency[f*2+1]; 97006cc46feSMatthew G. Knepley } 971a6cbbb48SMatthew G. Knepley PetscFunctionReturn(0); 972a6cbbb48SMatthew G. Knepley } 973a6cbbb48SMatthew G. Knepley 974a6cbbb48SMatthew G. Knepley /*@ 975a6cbbb48SMatthew G. Knepley PetscDSSetAdjacency - Set the flags for determining variable influence 976a6cbbb48SMatthew G. Knepley 977a6cbbb48SMatthew G. Knepley Not collective 978a6cbbb48SMatthew G. Knepley 979a6cbbb48SMatthew G. Knepley Input Parameters: 980a6cbbb48SMatthew G. Knepley + prob - The PetscDS object 981a6cbbb48SMatthew G. Knepley . f - The field number 982a6cbbb48SMatthew G. Knepley . useCone - Flag for variable influence starting with the cone operation 983a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure 984a6cbbb48SMatthew G. Knepley 985a6cbbb48SMatthew G. Knepley Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure() 986a6cbbb48SMatthew G. Knepley 987a6cbbb48SMatthew G. Knepley Level: developer 988a6cbbb48SMatthew G. Knepley 989f744cafaSSander Arens .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 990a6cbbb48SMatthew G. Knepley @*/ 991a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure) 992a6cbbb48SMatthew G. Knepley { 993a6cbbb48SMatthew G. Knepley PetscFunctionBegin; 994a6cbbb48SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 99506cc46feSMatthew G. Knepley if (f < 0) { 99606cc46feSMatthew G. Knepley prob->defaultAdj[0] = useCone; 99706cc46feSMatthew G. Knepley prob->defaultAdj[1] = useClosure; 99806cc46feSMatthew G. Knepley } else { 99906cc46feSMatthew 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); 1000a6cbbb48SMatthew G. Knepley prob->adjacency[f*2+0] = useCone; 1001a6cbbb48SMatthew G. Knepley prob->adjacency[f*2+1] = useClosure; 100206cc46feSMatthew G. Knepley } 1003a6cbbb48SMatthew G. Knepley PetscFunctionReturn(0); 1004a6cbbb48SMatthew G. Knepley } 1005a6cbbb48SMatthew G. Knepley 10062764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f, 100730b9ff8bSMatthew G. Knepley void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1008194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1009194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 101097b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 10112764a2aaSMatthew G. Knepley { 10122764a2aaSMatthew G. Knepley PetscFunctionBegin; 10132764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 10142764a2aaSMatthew G. Knepley PetscValidPointer(obj, 2); 10152764a2aaSMatthew 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); 10162764a2aaSMatthew G. Knepley *obj = prob->obj[f]; 10172764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10182764a2aaSMatthew G. Knepley } 10192764a2aaSMatthew G. Knepley 10202764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f, 102130b9ff8bSMatthew G. Knepley void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1022194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1023194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 102497b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 10252764a2aaSMatthew G. Knepley { 10262764a2aaSMatthew G. Knepley PetscErrorCode ierr; 10272764a2aaSMatthew G. Knepley 10282764a2aaSMatthew G. Knepley PetscFunctionBegin; 10292764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1030de716cbcSToby Isaac if (obj) PetscValidFunction(obj, 2); 10312764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 10322764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 10332764a2aaSMatthew G. Knepley prob->obj[f] = obj; 10342764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10352764a2aaSMatthew G. Knepley } 10362764a2aaSMatthew G. Knepley 1037194d53e6SMatthew G. Knepley /*@C 1038194d53e6SMatthew G. Knepley PetscDSGetResidual - Get the pointwise residual function for a given test field 1039194d53e6SMatthew G. Knepley 1040194d53e6SMatthew G. Knepley Not collective 1041194d53e6SMatthew G. Knepley 1042194d53e6SMatthew G. Knepley Input Parameters: 1043194d53e6SMatthew G. Knepley + prob - The PetscDS 1044194d53e6SMatthew G. Knepley - f - The test field number 1045194d53e6SMatthew G. Knepley 1046194d53e6SMatthew G. Knepley Output Parameters: 1047194d53e6SMatthew G. Knepley + f0 - integrand for the test function term 1048194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1049194d53e6SMatthew G. Knepley 1050194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1051194d53e6SMatthew G. Knepley 1052194d53e6SMatthew 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) 1053194d53e6SMatthew G. Knepley 1054194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1055194d53e6SMatthew G. Knepley 105630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1057194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1058194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 105930b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1060194d53e6SMatthew G. Knepley 1061194d53e6SMatthew G. Knepley + dim - the spatial dimension 1062194d53e6SMatthew G. Knepley . Nf - the number of fields 1063194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1064194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1065194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1066194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1067194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1068194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1069194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1070194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1071194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1072194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1073194d53e6SMatthew G. Knepley . t - current time 1074194d53e6SMatthew G. Knepley . x - coordinates of the current point 107597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 107697b6e6e8SMatthew G. Knepley . constants - constant parameters 1077194d53e6SMatthew G. Knepley - f0 - output values at the current point 1078194d53e6SMatthew G. Knepley 1079194d53e6SMatthew G. Knepley Level: intermediate 1080194d53e6SMatthew G. Knepley 1081194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual() 1082194d53e6SMatthew G. Knepley @*/ 10832764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f, 108430b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1085194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1086194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 108797b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 108830b9ff8bSMatthew G. Knepley void (**f1)(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 f1[])) 10922764a2aaSMatthew G. Knepley { 10932764a2aaSMatthew G. Knepley PetscFunctionBegin; 10942764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 10952764a2aaSMatthew 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); 10962764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];} 10972764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];} 10982764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10992764a2aaSMatthew G. Knepley } 11002764a2aaSMatthew G. Knepley 1101194d53e6SMatthew G. Knepley /*@C 1102194d53e6SMatthew G. Knepley PetscDSSetResidual - Set the pointwise residual function for a given test field 1103194d53e6SMatthew G. Knepley 1104194d53e6SMatthew G. Knepley Not collective 1105194d53e6SMatthew G. Knepley 1106194d53e6SMatthew G. Knepley Input Parameters: 1107194d53e6SMatthew G. Knepley + prob - The PetscDS 1108194d53e6SMatthew G. Knepley . f - The test field number 1109194d53e6SMatthew G. Knepley . f0 - integrand for the test function term 1110194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1111194d53e6SMatthew G. Knepley 1112194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1113194d53e6SMatthew G. Knepley 1114194d53e6SMatthew 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) 1115194d53e6SMatthew G. Knepley 1116194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1117194d53e6SMatthew G. Knepley 111830b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1119194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1120194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 112130b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1122194d53e6SMatthew G. Knepley 1123194d53e6SMatthew G. Knepley + dim - the spatial dimension 1124194d53e6SMatthew G. Knepley . Nf - the number of fields 1125194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1126194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1127194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1128194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1129194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1130194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1131194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1132194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1133194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1134194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1135194d53e6SMatthew G. Knepley . t - current time 1136194d53e6SMatthew G. Knepley . x - coordinates of the current point 113797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 113897b6e6e8SMatthew G. Knepley . constants - constant parameters 1139194d53e6SMatthew G. Knepley - f0 - output values at the current point 1140194d53e6SMatthew G. Knepley 1141194d53e6SMatthew G. Knepley Level: intermediate 1142194d53e6SMatthew G. Knepley 1143194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual() 1144194d53e6SMatthew G. Knepley @*/ 11452764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f, 114630b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1147194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1148194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 114997b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 115030b9ff8bSMatthew G. Knepley void (*f1)(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 f1[])) 11542764a2aaSMatthew G. Knepley { 11552764a2aaSMatthew G. Knepley PetscErrorCode ierr; 11562764a2aaSMatthew G. Knepley 11572764a2aaSMatthew G. Knepley PetscFunctionBegin; 11582764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1159f866a1d0SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1160f866a1d0SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 11612764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 11622764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 11632764a2aaSMatthew G. Knepley prob->f[f*2+0] = f0; 11642764a2aaSMatthew G. Knepley prob->f[f*2+1] = f1; 11652764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11662764a2aaSMatthew G. Knepley } 11672764a2aaSMatthew G. Knepley 11683e75805dSMatthew G. Knepley /*@C 11693e75805dSMatthew G. Knepley PetscDSHasJacobian - Signals that Jacobian functions have been set 11703e75805dSMatthew G. Knepley 11713e75805dSMatthew G. Knepley Not collective 11723e75805dSMatthew G. Knepley 11733e75805dSMatthew G. Knepley Input Parameter: 11743e75805dSMatthew G. Knepley . prob - The PetscDS 11753e75805dSMatthew G. Knepley 11763e75805dSMatthew G. Knepley Output Parameter: 11773e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set 11783e75805dSMatthew G. Knepley 11793e75805dSMatthew G. Knepley Level: intermediate 11803e75805dSMatthew G. Knepley 11813e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 11823e75805dSMatthew G. Knepley @*/ 11833e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac) 11843e75805dSMatthew G. Knepley { 11853e75805dSMatthew G. Knepley PetscInt f, g, h; 11863e75805dSMatthew G. Knepley 11873e75805dSMatthew G. Knepley PetscFunctionBegin; 11883e75805dSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 11893e75805dSMatthew G. Knepley *hasJac = PETSC_FALSE; 11903e75805dSMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 11913e75805dSMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 11923e75805dSMatthew G. Knepley for (h = 0; h < 4; ++h) { 11933e75805dSMatthew G. Knepley if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE; 11943e75805dSMatthew G. Knepley } 11953e75805dSMatthew G. Knepley } 11963e75805dSMatthew G. Knepley } 11973e75805dSMatthew G. Knepley PetscFunctionReturn(0); 11983e75805dSMatthew G. Knepley } 11993e75805dSMatthew G. Knepley 1200194d53e6SMatthew G. Knepley /*@C 1201194d53e6SMatthew G. Knepley PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field 1202194d53e6SMatthew G. Knepley 1203194d53e6SMatthew G. Knepley Not collective 1204194d53e6SMatthew G. Knepley 1205194d53e6SMatthew G. Knepley Input Parameters: 1206194d53e6SMatthew G. Knepley + prob - The PetscDS 1207194d53e6SMatthew G. Knepley . f - The test field number 1208194d53e6SMatthew G. Knepley - g - The field number 1209194d53e6SMatthew G. Knepley 1210194d53e6SMatthew G. Knepley Output Parameters: 1211194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1212194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1213194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1214194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1215194d53e6SMatthew G. Knepley 1216194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1217194d53e6SMatthew G. Knepley 1218194d53e6SMatthew 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 1219194d53e6SMatthew G. Knepley 1220194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1221194d53e6SMatthew G. Knepley 122230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1223194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1224194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 122530b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1226194d53e6SMatthew G. Knepley 1227194d53e6SMatthew G. Knepley + dim - the spatial dimension 1228194d53e6SMatthew G. Knepley . Nf - the number of fields 1229194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1230194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1231194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1232194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1233194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1234194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1235194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1236194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1237194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1238194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1239194d53e6SMatthew G. Knepley . t - current time 12402aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1241194d53e6SMatthew G. Knepley . x - coordinates of the current point 124297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 124397b6e6e8SMatthew G. Knepley . constants - constant parameters 1244194d53e6SMatthew G. Knepley - g0 - output values at the current point 1245194d53e6SMatthew G. Knepley 1246194d53e6SMatthew G. Knepley Level: intermediate 1247194d53e6SMatthew G. Knepley 1248194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1249194d53e6SMatthew G. Knepley @*/ 12502764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g, 125130b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1252194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1253194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 125497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 125530b9ff8bSMatthew G. Knepley void (**g1)(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 g1[]), 125930b9ff8bSMatthew G. Knepley void (**g2)(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 g2[]), 126330b9ff8bSMatthew G. Knepley void (**g3)(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 g3[])) 12672764a2aaSMatthew G. Knepley { 12682764a2aaSMatthew G. Knepley PetscFunctionBegin; 12692764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 12702764a2aaSMatthew 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); 12712764a2aaSMatthew 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); 12722764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];} 12732764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];} 12742764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];} 12752764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];} 12762764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 12772764a2aaSMatthew G. Knepley } 12782764a2aaSMatthew G. Knepley 1279194d53e6SMatthew G. Knepley /*@C 1280194d53e6SMatthew G. Knepley PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields 1281194d53e6SMatthew G. Knepley 1282194d53e6SMatthew G. Knepley Not collective 1283194d53e6SMatthew G. Knepley 1284194d53e6SMatthew G. Knepley Input Parameters: 1285194d53e6SMatthew G. Knepley + prob - The PetscDS 1286194d53e6SMatthew G. Knepley . f - The test field number 1287194d53e6SMatthew G. Knepley . g - The field number 1288194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1289194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1290194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1291194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1292194d53e6SMatthew G. Knepley 1293194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1294194d53e6SMatthew G. Knepley 1295194d53e6SMatthew 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 1296194d53e6SMatthew G. Knepley 1297194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1298194d53e6SMatthew G. Knepley 129930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1300194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1301194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 130230b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1303194d53e6SMatthew G. Knepley 1304194d53e6SMatthew G. Knepley + dim - the spatial dimension 1305194d53e6SMatthew G. Knepley . Nf - the number of fields 1306194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1307194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1308194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1309194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1310194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1311194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1312194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1313194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1314194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1315194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1316194d53e6SMatthew G. Knepley . t - current time 13172aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1318194d53e6SMatthew G. Knepley . x - coordinates of the current point 131997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 132097b6e6e8SMatthew G. Knepley . constants - constant parameters 1321194d53e6SMatthew G. Knepley - g0 - output values at the current point 1322194d53e6SMatthew G. Knepley 1323194d53e6SMatthew G. Knepley Level: intermediate 1324194d53e6SMatthew G. Knepley 1325194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1326194d53e6SMatthew G. Knepley @*/ 13272764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g, 132830b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1329194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1330194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 133197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 133230b9ff8bSMatthew G. Knepley void (*g1)(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 g1[]), 133630b9ff8bSMatthew G. Knepley void (*g2)(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 g2[]), 134030b9ff8bSMatthew G. Knepley void (*g3)(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 g3[])) 13442764a2aaSMatthew G. Knepley { 13452764a2aaSMatthew G. Knepley PetscErrorCode ierr; 13462764a2aaSMatthew G. Knepley 13472764a2aaSMatthew G. Knepley PetscFunctionBegin; 13482764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13492764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 13502764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 13512764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 13522764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 13532764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 13542764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 13552764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 13562764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+0] = g0; 13572764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+1] = g1; 13582764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+2] = g2; 13592764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+3] = g3; 13602764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 13612764a2aaSMatthew G. Knepley } 13622764a2aaSMatthew G. Knepley 1363475e0ac9SMatthew G. Knepley /*@C 136455c1f793SMatthew G. Knepley PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner 136555c1f793SMatthew G. Knepley 136655c1f793SMatthew G. Knepley Not collective 136755c1f793SMatthew G. Knepley 136855c1f793SMatthew G. Knepley Input Parameters: 136955c1f793SMatthew G. Knepley + prob - The PetscDS 137055c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner 137155c1f793SMatthew G. Knepley 137255c1f793SMatthew G. Knepley Level: intermediate 137355c1f793SMatthew G. Knepley 137455c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 137555c1f793SMatthew G. Knepley @*/ 137655c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre) 137755c1f793SMatthew G. Knepley { 137855c1f793SMatthew G. Knepley PetscFunctionBegin; 137955c1f793SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 138055c1f793SMatthew G. Knepley prob->useJacPre = useJacPre; 138155c1f793SMatthew G. Knepley PetscFunctionReturn(0); 138255c1f793SMatthew G. Knepley } 138355c1f793SMatthew G. Knepley 138455c1f793SMatthew G. Knepley /*@C 1385475e0ac9SMatthew G. Knepley PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set 1386475e0ac9SMatthew G. Knepley 1387475e0ac9SMatthew G. Knepley Not collective 1388475e0ac9SMatthew G. Knepley 1389475e0ac9SMatthew G. Knepley Input Parameter: 1390475e0ac9SMatthew G. Knepley . prob - The PetscDS 1391475e0ac9SMatthew G. Knepley 1392475e0ac9SMatthew G. Knepley Output Parameter: 1393475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set 1394475e0ac9SMatthew G. Knepley 1395475e0ac9SMatthew G. Knepley Level: intermediate 1396475e0ac9SMatthew G. Knepley 1397475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1398475e0ac9SMatthew G. Knepley @*/ 1399475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre) 1400475e0ac9SMatthew G. Knepley { 1401475e0ac9SMatthew G. Knepley PetscInt f, g, h; 1402475e0ac9SMatthew G. Knepley 1403475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1404475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1405475e0ac9SMatthew G. Knepley *hasJacPre = PETSC_FALSE; 140655c1f793SMatthew G. Knepley if (!prob->useJacPre) PetscFunctionReturn(0); 1407475e0ac9SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1408475e0ac9SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1409475e0ac9SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1410475e0ac9SMatthew G. Knepley if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE; 1411475e0ac9SMatthew G. Knepley } 1412475e0ac9SMatthew G. Knepley } 1413475e0ac9SMatthew G. Knepley } 1414475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1415475e0ac9SMatthew G. Knepley } 1416475e0ac9SMatthew G. Knepley 1417475e0ac9SMatthew G. Knepley /*@C 1418475e0ac9SMatthew 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. 1419475e0ac9SMatthew G. Knepley 1420475e0ac9SMatthew G. Knepley Not collective 1421475e0ac9SMatthew G. Knepley 1422475e0ac9SMatthew G. Knepley Input Parameters: 1423475e0ac9SMatthew G. Knepley + prob - The PetscDS 1424475e0ac9SMatthew G. Knepley . f - The test field number 1425475e0ac9SMatthew G. Knepley - g - The field number 1426475e0ac9SMatthew G. Knepley 1427475e0ac9SMatthew G. Knepley Output Parameters: 1428475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term 1429475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1430475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1431475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1432475e0ac9SMatthew G. Knepley 1433475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1434475e0ac9SMatthew G. Knepley 1435475e0ac9SMatthew 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 1436475e0ac9SMatthew G. Knepley 1437475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1438475e0ac9SMatthew G. Knepley 1439475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1440475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1441475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1442475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1443475e0ac9SMatthew G. Knepley 1444475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1445475e0ac9SMatthew G. Knepley . Nf - the number of fields 1446475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1447475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1448475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1449475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1450475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1451475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1452475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1453475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1454475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1455475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1456475e0ac9SMatthew G. Knepley . t - current time 1457475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1458475e0ac9SMatthew G. Knepley . x - coordinates of the current point 145997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 146097b6e6e8SMatthew G. Knepley . constants - constant parameters 1461475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1462475e0ac9SMatthew G. Knepley 1463475e0ac9SMatthew G. Knepley Level: intermediate 1464475e0ac9SMatthew G. Knepley 1465475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1466475e0ac9SMatthew G. Knepley @*/ 1467475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1468475e0ac9SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1469475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1470475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 147197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1472475e0ac9SMatthew G. Knepley void (**g1)(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 g1[]), 1476475e0ac9SMatthew G. Knepley void (**g2)(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 g2[]), 1480475e0ac9SMatthew G. Knepley void (**g3)(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 g3[])) 1484475e0ac9SMatthew G. Knepley { 1485475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1486475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1487475e0ac9SMatthew 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); 1488475e0ac9SMatthew 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); 1489475e0ac9SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];} 1490475e0ac9SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];} 1491475e0ac9SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];} 1492475e0ac9SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];} 1493475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1494475e0ac9SMatthew G. Knepley } 1495475e0ac9SMatthew G. Knepley 1496475e0ac9SMatthew G. Knepley /*@C 1497475e0ac9SMatthew 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. 1498475e0ac9SMatthew G. Knepley 1499475e0ac9SMatthew G. Knepley Not collective 1500475e0ac9SMatthew G. Knepley 1501475e0ac9SMatthew G. Knepley Input Parameters: 1502475e0ac9SMatthew G. Knepley + prob - The PetscDS 1503475e0ac9SMatthew G. Knepley . f - The test field number 1504475e0ac9SMatthew G. Knepley . g - The field number 1505475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term 1506475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1507475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1508475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1509475e0ac9SMatthew G. Knepley 1510475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1511475e0ac9SMatthew G. Knepley 1512475e0ac9SMatthew 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 1513475e0ac9SMatthew G. Knepley 1514475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1515475e0ac9SMatthew G. Knepley 1516475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1517475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1518475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1519475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1520475e0ac9SMatthew G. Knepley 1521475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1522475e0ac9SMatthew G. Knepley . Nf - the number of fields 1523475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1524475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1525475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1526475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1527475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1528475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1529475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1530475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1531475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1532475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1533475e0ac9SMatthew G. Knepley . t - current time 1534475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1535475e0ac9SMatthew G. Knepley . x - coordinates of the current point 153697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 153797b6e6e8SMatthew G. Knepley . constants - constant parameters 1538475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1539475e0ac9SMatthew G. Knepley 1540475e0ac9SMatthew G. Knepley Level: intermediate 1541475e0ac9SMatthew G. Knepley 1542475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian() 1543475e0ac9SMatthew G. Knepley @*/ 1544475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1545475e0ac9SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1546475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1547475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 154897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1549475e0ac9SMatthew G. Knepley void (*g1)(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 g1[]), 1553475e0ac9SMatthew G. Knepley void (*g2)(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 g2[]), 1557475e0ac9SMatthew G. Knepley void (*g3)(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 g3[])) 1561475e0ac9SMatthew G. Knepley { 1562475e0ac9SMatthew G. Knepley PetscErrorCode ierr; 1563475e0ac9SMatthew G. Knepley 1564475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1565475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1566475e0ac9SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1567475e0ac9SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1568475e0ac9SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1569475e0ac9SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1570475e0ac9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1571475e0ac9SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1572475e0ac9SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1573475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+0] = g0; 1574475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+1] = g1; 1575475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+2] = g2; 1576475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+3] = g3; 1577475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1578475e0ac9SMatthew G. Knepley } 1579475e0ac9SMatthew G. Knepley 1580b7e05686SMatthew G. Knepley /*@C 1581b7e05686SMatthew G. Knepley PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set 1582b7e05686SMatthew G. Knepley 1583b7e05686SMatthew G. Knepley Not collective 1584b7e05686SMatthew G. Knepley 1585b7e05686SMatthew G. Knepley Input Parameter: 1586b7e05686SMatthew G. Knepley . prob - The PetscDS 1587b7e05686SMatthew G. Knepley 1588b7e05686SMatthew G. Knepley Output Parameter: 1589b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set 1590b7e05686SMatthew G. Knepley 1591b7e05686SMatthew G. Knepley Level: intermediate 1592b7e05686SMatthew G. Knepley 1593b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian() 1594b7e05686SMatthew G. Knepley @*/ 1595b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac) 1596b7e05686SMatthew G. Knepley { 1597b7e05686SMatthew G. Knepley PetscInt f, g, h; 1598b7e05686SMatthew G. Knepley 1599b7e05686SMatthew G. Knepley PetscFunctionBegin; 1600b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1601b7e05686SMatthew G. Knepley *hasDynJac = PETSC_FALSE; 1602b7e05686SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1603b7e05686SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1604b7e05686SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1605b7e05686SMatthew G. Knepley if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE; 1606b7e05686SMatthew G. Knepley } 1607b7e05686SMatthew G. Knepley } 1608b7e05686SMatthew G. Knepley } 1609b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1610b7e05686SMatthew G. Knepley } 1611b7e05686SMatthew G. Knepley 1612b7e05686SMatthew G. Knepley /*@C 1613b7e05686SMatthew G. Knepley PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field 1614b7e05686SMatthew G. Knepley 1615b7e05686SMatthew G. Knepley Not collective 1616b7e05686SMatthew G. Knepley 1617b7e05686SMatthew G. Knepley Input Parameters: 1618b7e05686SMatthew G. Knepley + prob - The PetscDS 1619b7e05686SMatthew G. Knepley . f - The test field number 1620b7e05686SMatthew G. Knepley - g - The field number 1621b7e05686SMatthew G. Knepley 1622b7e05686SMatthew G. Knepley Output Parameters: 1623b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term 1624b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1625b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1626b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1627b7e05686SMatthew G. Knepley 1628b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1629b7e05686SMatthew G. Knepley 1630b7e05686SMatthew 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 1631b7e05686SMatthew G. Knepley 1632b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1633b7e05686SMatthew G. Knepley 1634b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1635b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1636b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1637b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1638b7e05686SMatthew G. Knepley 1639b7e05686SMatthew G. Knepley + dim - the spatial dimension 1640b7e05686SMatthew G. Knepley . Nf - the number of fields 1641b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1642b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1643b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1644b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1645b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1646b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1647b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1648b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1649b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1650b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1651b7e05686SMatthew G. Knepley . t - current time 1652b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1653b7e05686SMatthew G. Knepley . x - coordinates of the current point 165497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 165597b6e6e8SMatthew G. Knepley . constants - constant parameters 1656b7e05686SMatthew G. Knepley - g0 - output values at the current point 1657b7e05686SMatthew G. Knepley 1658b7e05686SMatthew G. Knepley Level: intermediate 1659b7e05686SMatthew G. Knepley 1660b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1661b7e05686SMatthew G. Knepley @*/ 1662b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1663b7e05686SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1664b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1665b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 166697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1667b7e05686SMatthew G. Knepley void (**g1)(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 g1[]), 1671b7e05686SMatthew G. Knepley void (**g2)(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 g2[]), 1675b7e05686SMatthew G. Knepley void (**g3)(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 g3[])) 1679b7e05686SMatthew G. Knepley { 1680b7e05686SMatthew G. Knepley PetscFunctionBegin; 1681b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1682b7e05686SMatthew 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); 1683b7e05686SMatthew 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); 1684b7e05686SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];} 1685b7e05686SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];} 1686b7e05686SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];} 1687b7e05686SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];} 1688b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1689b7e05686SMatthew G. Knepley } 1690b7e05686SMatthew G. Knepley 1691b7e05686SMatthew G. Knepley /*@C 1692b7e05686SMatthew G. Knepley PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields 1693b7e05686SMatthew G. Knepley 1694b7e05686SMatthew G. Knepley Not collective 1695b7e05686SMatthew G. Knepley 1696b7e05686SMatthew G. Knepley Input Parameters: 1697b7e05686SMatthew G. Knepley + prob - The PetscDS 1698b7e05686SMatthew G. Knepley . f - The test field number 1699b7e05686SMatthew G. Knepley . g - The field number 1700b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term 1701b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1702b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1703b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1704b7e05686SMatthew G. Knepley 1705b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1706b7e05686SMatthew G. Knepley 1707b7e05686SMatthew 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 1708b7e05686SMatthew G. Knepley 1709b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1710b7e05686SMatthew G. Knepley 1711b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1712b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1713b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1714b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1715b7e05686SMatthew G. Knepley 1716b7e05686SMatthew G. Knepley + dim - the spatial dimension 1717b7e05686SMatthew G. Knepley . Nf - the number of fields 1718b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1719b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1720b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1721b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1722b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1723b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1724b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1725b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1726b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1727b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1728b7e05686SMatthew G. Knepley . t - current time 1729b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1730b7e05686SMatthew G. Knepley . x - coordinates of the current point 173197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 173297b6e6e8SMatthew G. Knepley . constants - constant parameters 1733b7e05686SMatthew G. Knepley - g0 - output values at the current point 1734b7e05686SMatthew G. Knepley 1735b7e05686SMatthew G. Knepley Level: intermediate 1736b7e05686SMatthew G. Knepley 1737b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1738b7e05686SMatthew G. Knepley @*/ 1739b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1740b7e05686SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1741b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1742b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 174397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1744b7e05686SMatthew G. Knepley void (*g1)(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 g1[]), 1748b7e05686SMatthew G. Knepley void (*g2)(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 g2[]), 1752b7e05686SMatthew G. Knepley void (*g3)(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 g3[])) 1756b7e05686SMatthew G. Knepley { 1757b7e05686SMatthew G. Knepley PetscErrorCode ierr; 1758b7e05686SMatthew G. Knepley 1759b7e05686SMatthew G. Knepley PetscFunctionBegin; 1760b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1761b7e05686SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1762b7e05686SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1763b7e05686SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1764b7e05686SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1765b7e05686SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1766b7e05686SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1767b7e05686SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1768b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+0] = g0; 1769b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+1] = g1; 1770b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+2] = g2; 1771b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+3] = g3; 1772b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1773b7e05686SMatthew G. Knepley } 1774b7e05686SMatthew G. Knepley 17750c2f2876SMatthew G. Knepley /*@C 17760c2f2876SMatthew G. Knepley PetscDSGetRiemannSolver - Returns the Riemann solver for the given field 17770c2f2876SMatthew G. Knepley 17780c2f2876SMatthew G. Knepley Not collective 17790c2f2876SMatthew G. Knepley 17800c2f2876SMatthew G. Knepley Input Arguments: 17810c2f2876SMatthew G. Knepley + prob - The PetscDS object 17820c2f2876SMatthew G. Knepley - f - The field number 17830c2f2876SMatthew G. Knepley 17840c2f2876SMatthew G. Knepley Output Argument: 17850c2f2876SMatthew G. Knepley . r - Riemann solver 17860c2f2876SMatthew G. Knepley 17870c2f2876SMatthew G. Knepley Calling sequence for r: 17880c2f2876SMatthew G. Knepley 17895db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 17900c2f2876SMatthew G. Knepley 17915db36cf9SMatthew G. Knepley + dim - The spatial dimension 17925db36cf9SMatthew G. Knepley . Nf - The number of fields 17935db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 17940c2f2876SMatthew G. Knepley . n - The normal vector to the interface 17950c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 17960c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 17970c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 179897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 179997b6e6e8SMatthew G. Knepley . constants - constant parameters 18000c2f2876SMatthew G. Knepley - ctx - optional user context 18010c2f2876SMatthew G. Knepley 18020c2f2876SMatthew G. Knepley Level: intermediate 18030c2f2876SMatthew G. Knepley 18040c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver() 18050c2f2876SMatthew G. Knepley @*/ 18060c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f, 180797b6e6e8SMatthew 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)) 18080c2f2876SMatthew G. Knepley { 18090c2f2876SMatthew G. Knepley PetscFunctionBegin; 18100c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 18110c2f2876SMatthew 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); 18120c2f2876SMatthew G. Knepley PetscValidPointer(r, 3); 18130c2f2876SMatthew G. Knepley *r = prob->r[f]; 18140c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18150c2f2876SMatthew G. Knepley } 18160c2f2876SMatthew G. Knepley 18170c2f2876SMatthew G. Knepley /*@C 18180c2f2876SMatthew G. Knepley PetscDSSetRiemannSolver - Sets the Riemann solver for the given field 18190c2f2876SMatthew G. Knepley 18200c2f2876SMatthew G. Knepley Not collective 18210c2f2876SMatthew G. Knepley 18220c2f2876SMatthew G. Knepley Input Arguments: 18230c2f2876SMatthew G. Knepley + prob - The PetscDS object 18240c2f2876SMatthew G. Knepley . f - The field number 18250c2f2876SMatthew G. Knepley - r - Riemann solver 18260c2f2876SMatthew G. Knepley 18270c2f2876SMatthew G. Knepley Calling sequence for r: 18280c2f2876SMatthew G. Knepley 18295db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 18300c2f2876SMatthew G. Knepley 18315db36cf9SMatthew G. Knepley + dim - The spatial dimension 18325db36cf9SMatthew G. Knepley . Nf - The number of fields 18335db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 18340c2f2876SMatthew G. Knepley . n - The normal vector to the interface 18350c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 18360c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 18370c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 183897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 183997b6e6e8SMatthew G. Knepley . constants - constant parameters 18400c2f2876SMatthew G. Knepley - ctx - optional user context 18410c2f2876SMatthew G. Knepley 18420c2f2876SMatthew G. Knepley Level: intermediate 18430c2f2876SMatthew G. Knepley 18440c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver() 18450c2f2876SMatthew G. Knepley @*/ 18460c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f, 184797b6e6e8SMatthew 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)) 18480c2f2876SMatthew G. Knepley { 18490c2f2876SMatthew G. Knepley PetscErrorCode ierr; 18500c2f2876SMatthew G. Knepley 18510c2f2876SMatthew G. Knepley PetscFunctionBegin; 18520c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1853de716cbcSToby Isaac if (r) PetscValidFunction(r, 3); 18540c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 18550c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 18560c2f2876SMatthew G. Knepley prob->r[f] = r; 18570c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18580c2f2876SMatthew G. Knepley } 18590c2f2876SMatthew G. Knepley 186032d2bbc9SMatthew G. Knepley /*@C 186132d2bbc9SMatthew G. Knepley PetscDSGetUpdate - Get the pointwise update function for a given field 186232d2bbc9SMatthew G. Knepley 186332d2bbc9SMatthew G. Knepley Not collective 186432d2bbc9SMatthew G. Knepley 186532d2bbc9SMatthew G. Knepley Input Parameters: 186632d2bbc9SMatthew G. Knepley + prob - The PetscDS 186732d2bbc9SMatthew G. Knepley - f - The field number 186832d2bbc9SMatthew G. Knepley 186932d2bbc9SMatthew G. Knepley Output Parameters: 187032d2bbc9SMatthew G. Knepley + update - update function 187132d2bbc9SMatthew G. Knepley 187232d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 187332d2bbc9SMatthew G. Knepley 187432d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 187532d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 187632d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 187732d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 187832d2bbc9SMatthew G. Knepley 187932d2bbc9SMatthew G. Knepley + dim - the spatial dimension 188032d2bbc9SMatthew G. Knepley . Nf - the number of fields 188132d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 188232d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 188332d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 188432d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 188532d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 188632d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 188732d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 188832d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 188932d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 189032d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 189132d2bbc9SMatthew G. Knepley . t - current time 189232d2bbc9SMatthew G. Knepley . x - coordinates of the current point 189332d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point 189432d2bbc9SMatthew G. Knepley 189532d2bbc9SMatthew G. Knepley Level: intermediate 189632d2bbc9SMatthew G. Knepley 189732d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual() 189832d2bbc9SMatthew G. Knepley @*/ 189932d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f, 190032d2bbc9SMatthew G. Knepley void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 190132d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 190232d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 19033fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 190432d2bbc9SMatthew G. Knepley { 190532d2bbc9SMatthew G. Knepley PetscFunctionBegin; 190632d2bbc9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 190732d2bbc9SMatthew 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); 190832d2bbc9SMatthew G. Knepley if (update) {PetscValidPointer(update, 3); *update = prob->update[f];} 190932d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 191032d2bbc9SMatthew G. Knepley } 191132d2bbc9SMatthew G. Knepley 191232d2bbc9SMatthew G. Knepley /*@C 19133fa77dffSMatthew G. Knepley PetscDSSetUpdate - Set the pointwise update function for a given field 191432d2bbc9SMatthew G. Knepley 191532d2bbc9SMatthew G. Knepley Not collective 191632d2bbc9SMatthew G. Knepley 191732d2bbc9SMatthew G. Knepley Input Parameters: 191832d2bbc9SMatthew G. Knepley + prob - The PetscDS 191932d2bbc9SMatthew G. Knepley . f - The field number 192032d2bbc9SMatthew G. Knepley - update - update function 192132d2bbc9SMatthew G. Knepley 192232d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 192332d2bbc9SMatthew G. Knepley 192432d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 192532d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 192632d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 192732d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 192832d2bbc9SMatthew G. Knepley 192932d2bbc9SMatthew G. Knepley + dim - the spatial dimension 193032d2bbc9SMatthew G. Knepley . Nf - the number of fields 193132d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 193232d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 193332d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 193432d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 193532d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 193632d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 193732d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 193832d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 193932d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 194032d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 194132d2bbc9SMatthew G. Knepley . t - current time 194232d2bbc9SMatthew G. Knepley . x - coordinates of the current point 194332d2bbc9SMatthew G. Knepley - uNew - new field values at the current point 194432d2bbc9SMatthew G. Knepley 194532d2bbc9SMatthew G. Knepley Level: intermediate 194632d2bbc9SMatthew G. Knepley 194732d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual() 194832d2bbc9SMatthew G. Knepley @*/ 194932d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f, 195032d2bbc9SMatthew G. Knepley void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 195132d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 195232d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 19533fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 195432d2bbc9SMatthew G. Knepley { 195532d2bbc9SMatthew G. Knepley PetscErrorCode ierr; 195632d2bbc9SMatthew G. Knepley 195732d2bbc9SMatthew G. Knepley PetscFunctionBegin; 195832d2bbc9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 195932d2bbc9SMatthew G. Knepley if (update) PetscValidFunction(update, 3); 196032d2bbc9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 196132d2bbc9SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 196232d2bbc9SMatthew G. Knepley prob->update[f] = update; 196332d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 196432d2bbc9SMatthew G. Knepley } 196532d2bbc9SMatthew G. Knepley 19660c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx) 19670c2f2876SMatthew G. Knepley { 19680c2f2876SMatthew G. Knepley PetscFunctionBegin; 19690c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19700c2f2876SMatthew 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); 19710c2f2876SMatthew G. Knepley PetscValidPointer(ctx, 3); 19720c2f2876SMatthew G. Knepley *ctx = prob->ctx[f]; 19730c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19740c2f2876SMatthew G. Knepley } 19750c2f2876SMatthew G. Knepley 19760c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx) 19770c2f2876SMatthew G. Knepley { 19780c2f2876SMatthew G. Knepley PetscErrorCode ierr; 19790c2f2876SMatthew G. Knepley 19800c2f2876SMatthew G. Knepley PetscFunctionBegin; 19810c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19820c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 19830c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 19840c2f2876SMatthew G. Knepley prob->ctx[f] = ctx; 19850c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19860c2f2876SMatthew G. Knepley } 19870c2f2876SMatthew G. Knepley 1988194d53e6SMatthew G. Knepley /*@C 1989194d53e6SMatthew G. Knepley PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field 1990194d53e6SMatthew G. Knepley 1991194d53e6SMatthew G. Knepley Not collective 1992194d53e6SMatthew G. Knepley 1993194d53e6SMatthew G. Knepley Input Parameters: 1994194d53e6SMatthew G. Knepley + prob - The PetscDS 1995194d53e6SMatthew G. Knepley - f - The test field number 1996194d53e6SMatthew G. Knepley 1997194d53e6SMatthew G. Knepley Output Parameters: 1998194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term 1999194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2000194d53e6SMatthew G. Knepley 2001194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2002194d53e6SMatthew G. Knepley 2003194d53e6SMatthew 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 2004194d53e6SMatthew G. Knepley 2005194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2006194d53e6SMatthew G. Knepley 200730b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2008194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2009194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 201030b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2011194d53e6SMatthew G. Knepley 2012194d53e6SMatthew G. Knepley + dim - the spatial dimension 2013194d53e6SMatthew G. Knepley . Nf - the number of fields 2014194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2015194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2016194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2017194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2018194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2019194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2020194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2021194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2022194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2023194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2024194d53e6SMatthew G. Knepley . t - current time 2025194d53e6SMatthew G. Knepley . x - coordinates of the current point 2026194d53e6SMatthew G. Knepley . n - unit normal at the current point 202797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 202897b6e6e8SMatthew G. Knepley . constants - constant parameters 2029194d53e6SMatthew G. Knepley - f0 - output values at the current point 2030194d53e6SMatthew G. Knepley 2031194d53e6SMatthew G. Knepley Level: intermediate 2032194d53e6SMatthew G. Knepley 2033194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual() 2034194d53e6SMatthew G. Knepley @*/ 20352764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f, 203630b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2037194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2038194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 203997b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 204030b9ff8bSMatthew G. Knepley void (**f1)(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 f1[])) 20442764a2aaSMatthew G. Knepley { 20452764a2aaSMatthew G. Knepley PetscFunctionBegin; 20462764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 20472764a2aaSMatthew 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); 20482764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];} 20492764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];} 20502764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 20512764a2aaSMatthew G. Knepley } 20522764a2aaSMatthew G. Knepley 2053194d53e6SMatthew G. Knepley /*@C 2054194d53e6SMatthew G. Knepley PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field 2055194d53e6SMatthew G. Knepley 2056194d53e6SMatthew G. Knepley Not collective 2057194d53e6SMatthew G. Knepley 2058194d53e6SMatthew G. Knepley Input Parameters: 2059194d53e6SMatthew G. Knepley + prob - The PetscDS 2060194d53e6SMatthew G. Knepley . f - The test field number 2061194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term 2062194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2063194d53e6SMatthew G. Knepley 2064194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2065194d53e6SMatthew G. Knepley 2066194d53e6SMatthew 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 2067194d53e6SMatthew G. Knepley 2068194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2069194d53e6SMatthew G. Knepley 207030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2071194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2072194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 207330b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2074194d53e6SMatthew G. Knepley 2075194d53e6SMatthew G. Knepley + dim - the spatial dimension 2076194d53e6SMatthew G. Knepley . Nf - the number of fields 2077194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2078194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2079194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2080194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2081194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2082194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2083194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2084194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2085194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2086194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2087194d53e6SMatthew G. Knepley . t - current time 2088194d53e6SMatthew G. Knepley . x - coordinates of the current point 2089194d53e6SMatthew G. Knepley . n - unit normal at the current point 209097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 209197b6e6e8SMatthew G. Knepley . constants - constant parameters 2092194d53e6SMatthew G. Knepley - f0 - output values at the current point 2093194d53e6SMatthew G. Knepley 2094194d53e6SMatthew G. Knepley Level: intermediate 2095194d53e6SMatthew G. Knepley 2096194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual() 2097194d53e6SMatthew G. Knepley @*/ 20982764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f, 209930b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2100194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2101194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 210297b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 210330b9ff8bSMatthew G. Knepley void (*f1)(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 f1[])) 21072764a2aaSMatthew G. Knepley { 21082764a2aaSMatthew G. Knepley PetscErrorCode ierr; 21092764a2aaSMatthew G. Knepley 21102764a2aaSMatthew G. Knepley PetscFunctionBegin; 21112764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 21122764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 21132764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 21142764a2aaSMatthew G. Knepley if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;} 21152764a2aaSMatthew G. Knepley if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;} 21162764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21172764a2aaSMatthew G. Knepley } 21182764a2aaSMatthew G. Knepley 2119194d53e6SMatthew G. Knepley /*@C 2120194d53e6SMatthew G. Knepley PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field 2121194d53e6SMatthew G. Knepley 2122194d53e6SMatthew G. Knepley Not collective 2123194d53e6SMatthew G. Knepley 2124194d53e6SMatthew G. Knepley Input Parameters: 2125194d53e6SMatthew G. Knepley + prob - The PetscDS 2126194d53e6SMatthew G. Knepley . f - The test field number 2127194d53e6SMatthew G. Knepley - g - The field number 2128194d53e6SMatthew G. Knepley 2129194d53e6SMatthew G. Knepley Output Parameters: 2130194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 2131194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2132194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2133194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2134194d53e6SMatthew G. Knepley 2135194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2136194d53e6SMatthew G. Knepley 2137194d53e6SMatthew 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 2138194d53e6SMatthew G. Knepley 2139194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2140194d53e6SMatthew G. Knepley 214130b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2142194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2143194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 214430b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2145194d53e6SMatthew G. Knepley 2146194d53e6SMatthew G. Knepley + dim - the spatial dimension 2147194d53e6SMatthew G. Knepley . Nf - the number of fields 2148194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2149194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2150194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2151194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2152194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2153194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2154194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2155194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2156194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2157194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2158194d53e6SMatthew G. Knepley . t - current time 21592aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2160194d53e6SMatthew G. Knepley . x - coordinates of the current point 2161194d53e6SMatthew G. Knepley . n - normal at the current point 216297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 216397b6e6e8SMatthew G. Knepley . constants - constant parameters 2164194d53e6SMatthew G. Knepley - g0 - output values at the current point 2165194d53e6SMatthew G. Knepley 2166194d53e6SMatthew G. Knepley Level: intermediate 2167194d53e6SMatthew G. Knepley 2168194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian() 2169194d53e6SMatthew G. Knepley @*/ 21702764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 217130b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2172194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2173194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 217497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 217530b9ff8bSMatthew G. Knepley void (**g1)(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 g1[]), 217930b9ff8bSMatthew G. Knepley void (**g2)(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 g2[]), 218330b9ff8bSMatthew G. Knepley void (**g3)(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 g3[])) 21872764a2aaSMatthew G. Knepley { 21882764a2aaSMatthew G. Knepley PetscFunctionBegin; 21892764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 21902764a2aaSMatthew 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); 21912764a2aaSMatthew 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); 21922764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];} 21932764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];} 21942764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];} 21952764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];} 21962764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21972764a2aaSMatthew G. Knepley } 21982764a2aaSMatthew G. Knepley 2199194d53e6SMatthew G. Knepley /*@C 2200194d53e6SMatthew G. Knepley PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field 2201194d53e6SMatthew G. Knepley 2202194d53e6SMatthew G. Knepley Not collective 2203194d53e6SMatthew G. Knepley 2204194d53e6SMatthew G. Knepley Input Parameters: 2205194d53e6SMatthew G. Knepley + prob - The PetscDS 2206194d53e6SMatthew G. Knepley . f - The test field number 2207194d53e6SMatthew G. Knepley . g - The field number 2208194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 2209194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2210194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2211194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2212194d53e6SMatthew G. Knepley 2213194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2214194d53e6SMatthew G. Knepley 2215194d53e6SMatthew 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 2216194d53e6SMatthew G. Knepley 2217194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2218194d53e6SMatthew G. Knepley 221930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2220194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2221194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 222230b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2223194d53e6SMatthew G. Knepley 2224194d53e6SMatthew G. Knepley + dim - the spatial dimension 2225194d53e6SMatthew G. Knepley . Nf - the number of fields 2226194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2227194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2228194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2229194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2230194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2231194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2232194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2233194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2234194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2235194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2236194d53e6SMatthew G. Knepley . t - current time 22372aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2238194d53e6SMatthew G. Knepley . x - coordinates of the current point 2239194d53e6SMatthew G. Knepley . n - normal at the current point 224097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 224197b6e6e8SMatthew G. Knepley . constants - constant parameters 2242194d53e6SMatthew G. Knepley - g0 - output values at the current point 2243194d53e6SMatthew G. Knepley 2244194d53e6SMatthew G. Knepley Level: intermediate 2245194d53e6SMatthew G. Knepley 2246194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian() 2247194d53e6SMatthew G. Knepley @*/ 22482764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 224930b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2250194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2251194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 225297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 225330b9ff8bSMatthew G. Knepley void (*g1)(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 g1[]), 225730b9ff8bSMatthew G. Knepley void (*g2)(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 g2[]), 226130b9ff8bSMatthew G. Knepley void (*g3)(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 g3[])) 22652764a2aaSMatthew G. Knepley { 22662764a2aaSMatthew G. Knepley PetscErrorCode ierr; 22672764a2aaSMatthew G. Knepley 22682764a2aaSMatthew G. Knepley PetscFunctionBegin; 22692764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 22702764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 22712764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 22722764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 22732764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 22742764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 22752764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 22762764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 22772764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+0] = g0; 22782764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+1] = g1; 22792764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+2] = g2; 22802764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+3] = g3; 22812764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22822764a2aaSMatthew G. Knepley } 22832764a2aaSMatthew G. Knepley 22840d3e9b51SMatthew G. Knepley /*@C 2285c371a6d1SMatthew G. Knepley PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field 2286c371a6d1SMatthew G. Knepley 2287c371a6d1SMatthew G. Knepley Not collective 2288c371a6d1SMatthew G. Knepley 2289c371a6d1SMatthew G. Knepley Input Parameters: 2290c371a6d1SMatthew G. Knepley + prob - The PetscDS 2291c371a6d1SMatthew G. Knepley - f - The test field number 2292c371a6d1SMatthew G. Knepley 2293c371a6d1SMatthew G. Knepley Output Parameter: 2294c371a6d1SMatthew G. Knepley . exactSol - exact solution for the test field 2295c371a6d1SMatthew G. Knepley 2296c371a6d1SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2297c371a6d1SMatthew G. Knepley 2298c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2299c371a6d1SMatthew G. Knepley 2300c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2301c371a6d1SMatthew G. Knepley . t - current time 2302c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2303c371a6d1SMatthew G. Knepley . Nc - the number of field components 2304c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2305c371a6d1SMatthew G. Knepley - ctx - a user context 2306c371a6d1SMatthew G. Knepley 2307c371a6d1SMatthew G. Knepley Level: intermediate 2308c371a6d1SMatthew G. Knepley 2309c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution() 2310c371a6d1SMatthew G. Knepley @*/ 2311c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)) 2312c371a6d1SMatthew G. Knepley { 2313c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2314c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2315c371a6d1SMatthew 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); 2316c371a6d1SMatthew G. Knepley if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];} 2317c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2318c371a6d1SMatthew G. Knepley } 2319c371a6d1SMatthew G. Knepley 2320c371a6d1SMatthew G. Knepley /*@C 2321c371a6d1SMatthew G. Knepley PetscDSSetExactSolution - Get the pointwise exact solution function for a given test field 2322c371a6d1SMatthew G. Knepley 2323c371a6d1SMatthew G. Knepley Not collective 2324c371a6d1SMatthew G. Knepley 2325c371a6d1SMatthew G. Knepley Input Parameters: 2326c371a6d1SMatthew G. Knepley + prob - The PetscDS 2327c371a6d1SMatthew G. Knepley . f - The test field number 2328c371a6d1SMatthew G. Knepley - sol - solution function for the test fields 2329c371a6d1SMatthew G. Knepley 2330c371a6d1SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2331c371a6d1SMatthew G. Knepley 2332c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2333c371a6d1SMatthew G. Knepley 2334c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2335c371a6d1SMatthew G. Knepley . t - current time 2336c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2337c371a6d1SMatthew G. Knepley . Nc - the number of field components 2338c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2339c371a6d1SMatthew G. Knepley - ctx - a user context 2340c371a6d1SMatthew G. Knepley 2341c371a6d1SMatthew G. Knepley Level: intermediate 2342c371a6d1SMatthew G. Knepley 2343c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution() 2344c371a6d1SMatthew G. Knepley @*/ 2345c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)) 2346c371a6d1SMatthew G. Knepley { 2347c371a6d1SMatthew G. Knepley PetscErrorCode ierr; 2348c371a6d1SMatthew G. Knepley 2349c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2350c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2351c371a6d1SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 2352c371a6d1SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 2353c371a6d1SMatthew G. Knepley if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;} 2354c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2355c371a6d1SMatthew G. Knepley } 2356c371a6d1SMatthew G. Knepley 23575638fd0eSMatthew G. Knepley /*@C 235897b6e6e8SMatthew G. Knepley PetscDSGetConstants - Returns the array of constants passed to point functions 235997b6e6e8SMatthew G. Knepley 236097b6e6e8SMatthew G. Knepley Not collective 236197b6e6e8SMatthew G. Knepley 236297b6e6e8SMatthew G. Knepley Input Parameter: 236397b6e6e8SMatthew G. Knepley . prob - The PetscDS object 236497b6e6e8SMatthew G. Knepley 236597b6e6e8SMatthew G. Knepley Output Parameters: 236697b6e6e8SMatthew G. Knepley + numConstants - The number of constants 236797b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 236897b6e6e8SMatthew G. Knepley 236997b6e6e8SMatthew G. Knepley Level: intermediate 237097b6e6e8SMatthew G. Knepley 237197b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate() 237297b6e6e8SMatthew G. Knepley @*/ 237397b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[]) 237497b6e6e8SMatthew G. Knepley { 237597b6e6e8SMatthew G. Knepley PetscFunctionBegin; 237697b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 237797b6e6e8SMatthew G. Knepley if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;} 237897b6e6e8SMatthew G. Knepley if (constants) {PetscValidPointer(constants, 3); *constants = prob->constants;} 237997b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 238097b6e6e8SMatthew G. Knepley } 238197b6e6e8SMatthew G. Knepley 23820d3e9b51SMatthew G. Knepley /*@C 238397b6e6e8SMatthew G. Knepley PetscDSSetConstants - Set the array of constants passed to point functions 238497b6e6e8SMatthew G. Knepley 238597b6e6e8SMatthew G. Knepley Not collective 238697b6e6e8SMatthew G. Knepley 238797b6e6e8SMatthew G. Knepley Input Parameters: 238897b6e6e8SMatthew G. Knepley + prob - The PetscDS object 238997b6e6e8SMatthew G. Knepley . numConstants - The number of constants 239097b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 239197b6e6e8SMatthew G. Knepley 239297b6e6e8SMatthew G. Knepley Level: intermediate 239397b6e6e8SMatthew G. Knepley 239497b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate() 239597b6e6e8SMatthew G. Knepley @*/ 239697b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[]) 239797b6e6e8SMatthew G. Knepley { 239897b6e6e8SMatthew G. Knepley PetscErrorCode ierr; 239997b6e6e8SMatthew G. Knepley 240097b6e6e8SMatthew G. Knepley PetscFunctionBegin; 240197b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 240297b6e6e8SMatthew G. Knepley if (numConstants != prob->numConstants) { 240397b6e6e8SMatthew G. Knepley ierr = PetscFree(prob->constants);CHKERRQ(ierr); 240497b6e6e8SMatthew G. Knepley prob->numConstants = numConstants; 240597b6e6e8SMatthew G. Knepley if (prob->numConstants) { 240697b6e6e8SMatthew G. Knepley ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr); 240720be0f5bSMatthew G. Knepley } else { 240820be0f5bSMatthew G. Knepley prob->constants = NULL; 240920be0f5bSMatthew G. Knepley } 241020be0f5bSMatthew G. Knepley } 241120be0f5bSMatthew G. Knepley if (prob->numConstants) { 241220be0f5bSMatthew G. Knepley PetscValidPointer(constants, 3); 241397b6e6e8SMatthew G. Knepley ierr = PetscMemcpy(prob->constants, constants, prob->numConstants * sizeof(PetscScalar));CHKERRQ(ierr); 241497b6e6e8SMatthew G. Knepley } 241597b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 241697b6e6e8SMatthew G. Knepley } 241797b6e6e8SMatthew G. Knepley 24184cd1e086SMatthew G. Knepley /*@ 24194cd1e086SMatthew G. Knepley PetscDSGetFieldIndex - Returns the index of the given field 24204cd1e086SMatthew G. Knepley 24214cd1e086SMatthew G. Knepley Not collective 24224cd1e086SMatthew G. Knepley 24234cd1e086SMatthew G. Knepley Input Parameters: 24244cd1e086SMatthew G. Knepley + prob - The PetscDS object 24254cd1e086SMatthew G. Knepley - disc - The discretization object 24264cd1e086SMatthew G. Knepley 24274cd1e086SMatthew G. Knepley Output Parameter: 24284cd1e086SMatthew G. Knepley . f - The field number 24294cd1e086SMatthew G. Knepley 24304cd1e086SMatthew G. Knepley Level: beginner 24314cd1e086SMatthew G. Knepley 2432f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 24334cd1e086SMatthew G. Knepley @*/ 24344cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f) 24354cd1e086SMatthew G. Knepley { 24364cd1e086SMatthew G. Knepley PetscInt g; 24374cd1e086SMatthew G. Knepley 24384cd1e086SMatthew G. Knepley PetscFunctionBegin; 24394cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 24404cd1e086SMatthew G. Knepley PetscValidPointer(f, 3); 24414cd1e086SMatthew G. Knepley *f = -1; 24424cd1e086SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;} 24434cd1e086SMatthew G. Knepley if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS."); 24444cd1e086SMatthew G. Knepley *f = g; 24454cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 24464cd1e086SMatthew G. Knepley } 24474cd1e086SMatthew G. Knepley 24484cd1e086SMatthew G. Knepley /*@ 24494cd1e086SMatthew G. Knepley PetscDSGetFieldSize - Returns the size of the given field in the full space basis 24504cd1e086SMatthew G. Knepley 24514cd1e086SMatthew G. Knepley Not collective 24524cd1e086SMatthew G. Knepley 24534cd1e086SMatthew G. Knepley Input Parameters: 24544cd1e086SMatthew G. Knepley + prob - The PetscDS object 24554cd1e086SMatthew G. Knepley - f - The field number 24564cd1e086SMatthew G. Knepley 24574cd1e086SMatthew G. Knepley Output Parameter: 24584cd1e086SMatthew G. Knepley . size - The size 24594cd1e086SMatthew G. Knepley 24604cd1e086SMatthew G. Knepley Level: beginner 24614cd1e086SMatthew G. Knepley 2462f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate() 24634cd1e086SMatthew G. Knepley @*/ 24644cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size) 24654cd1e086SMatthew G. Knepley { 24662166fd64SMatthew G. Knepley PetscErrorCode ierr; 24672166fd64SMatthew G. Knepley 24684cd1e086SMatthew G. Knepley PetscFunctionBegin; 24694cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 24704cd1e086SMatthew G. Knepley PetscValidPointer(size, 3); 24714cd1e086SMatthew 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); 24722166fd64SMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2473d4742ddaSMatthew G. Knepley *size = prob->Nb[f]; 24744cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 24754cd1e086SMatthew G. Knepley } 24764cd1e086SMatthew G. Knepley 2477bc4ae4beSMatthew G. Knepley /*@ 2478bc4ae4beSMatthew G. Knepley PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis 2479bc4ae4beSMatthew G. Knepley 2480bc4ae4beSMatthew G. Knepley Not collective 2481bc4ae4beSMatthew G. Knepley 2482bc4ae4beSMatthew G. Knepley Input Parameters: 2483bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 2484bc4ae4beSMatthew G. Knepley - f - The field number 2485bc4ae4beSMatthew G. Knepley 2486bc4ae4beSMatthew G. Knepley Output Parameter: 2487bc4ae4beSMatthew G. Knepley . off - The offset 2488bc4ae4beSMatthew G. Knepley 2489bc4ae4beSMatthew G. Knepley Level: beginner 2490bc4ae4beSMatthew G. Knepley 2491f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate() 2492bc4ae4beSMatthew G. Knepley @*/ 24932764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 24942764a2aaSMatthew G. Knepley { 24954cd1e086SMatthew G. Knepley PetscInt size, g; 24962764a2aaSMatthew G. Knepley PetscErrorCode ierr; 24972764a2aaSMatthew G. Knepley 24982764a2aaSMatthew G. Knepley PetscFunctionBegin; 24992764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 25002764a2aaSMatthew G. Knepley PetscValidPointer(off, 3); 25012764a2aaSMatthew 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); 25022764a2aaSMatthew G. Knepley *off = 0; 25032764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 25044cd1e086SMatthew G. Knepley ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr); 25054cd1e086SMatthew G. Knepley *off += size; 25062764a2aaSMatthew G. Knepley } 25072764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 25082764a2aaSMatthew G. Knepley } 25092764a2aaSMatthew G. Knepley 2510bc4ae4beSMatthew G. Knepley /*@ 251147e57110SSander Arens PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point 2512bc4ae4beSMatthew G. Knepley 2513bc4ae4beSMatthew G. Knepley Not collective 2514bc4ae4beSMatthew G. Knepley 251547e57110SSander Arens Input Parameter: 251647e57110SSander Arens . prob - The PetscDS object 2517bc4ae4beSMatthew G. Knepley 2518bc4ae4beSMatthew G. Knepley Output Parameter: 251947e57110SSander Arens . dimensions - The number of dimensions 2520bc4ae4beSMatthew G. Knepley 2521bc4ae4beSMatthew G. Knepley Level: beginner 2522bc4ae4beSMatthew G. Knepley 252347e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 2524bc4ae4beSMatthew G. Knepley @*/ 252547e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[]) 25262764a2aaSMatthew G. Knepley { 25272764a2aaSMatthew G. Knepley PetscErrorCode ierr; 25282764a2aaSMatthew G. Knepley 25292764a2aaSMatthew G. Knepley PetscFunctionBegin; 25302764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 253147e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 253247e57110SSander Arens PetscValidPointer(dimensions, 2); 253347e57110SSander Arens *dimensions = prob->Nb; 253447e57110SSander Arens PetscFunctionReturn(0); 25356ce16762SMatthew G. Knepley } 253647e57110SSander Arens 253747e57110SSander Arens /*@ 253847e57110SSander Arens PetscDSGetComponents - Returns the number of components for each field on an evaluation point 253947e57110SSander Arens 254047e57110SSander Arens Not collective 254147e57110SSander Arens 254247e57110SSander Arens Input Parameter: 254347e57110SSander Arens . prob - The PetscDS object 254447e57110SSander Arens 254547e57110SSander Arens Output Parameter: 254647e57110SSander Arens . components - The number of components 254747e57110SSander Arens 254847e57110SSander Arens Level: beginner 254947e57110SSander Arens 255047e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 255147e57110SSander Arens @*/ 255247e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[]) 255347e57110SSander Arens { 255447e57110SSander Arens PetscErrorCode ierr; 255547e57110SSander Arens 255647e57110SSander Arens PetscFunctionBegin; 255747e57110SSander Arens PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 255847e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 255947e57110SSander Arens PetscValidPointer(components, 2); 256047e57110SSander Arens *components = prob->Nc; 25616ce16762SMatthew G. Knepley PetscFunctionReturn(0); 25626ce16762SMatthew G. Knepley } 25636ce16762SMatthew G. Knepley 25646ce16762SMatthew G. Knepley /*@ 25656ce16762SMatthew G. Knepley PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point 25666ce16762SMatthew G. Knepley 25676ce16762SMatthew G. Knepley Not collective 25686ce16762SMatthew G. Knepley 25696ce16762SMatthew G. Knepley Input Parameters: 25706ce16762SMatthew G. Knepley + prob - The PetscDS object 25716ce16762SMatthew G. Knepley - f - The field number 25726ce16762SMatthew G. Knepley 25736ce16762SMatthew G. Knepley Output Parameter: 25746ce16762SMatthew G. Knepley . off - The offset 25756ce16762SMatthew G. Knepley 25766ce16762SMatthew G. Knepley Level: beginner 25776ce16762SMatthew G. Knepley 2578f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 25796ce16762SMatthew G. Knepley @*/ 25806ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off) 25816ce16762SMatthew G. Knepley { 25826ce16762SMatthew G. Knepley PetscFunctionBegin; 25836ce16762SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 25846ce16762SMatthew G. Knepley PetscValidPointer(off, 3); 25856ce16762SMatthew 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); 258647e57110SSander Arens *off = prob->off[f]; 25872764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 25882764a2aaSMatthew G. Knepley } 25892764a2aaSMatthew G. Knepley 2590194d53e6SMatthew G. Knepley /*@ 2591194d53e6SMatthew G. Knepley PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point 2592194d53e6SMatthew G. Knepley 2593194d53e6SMatthew G. Knepley Not collective 2594194d53e6SMatthew G. Knepley 2595194d53e6SMatthew G. Knepley Input Parameter: 2596194d53e6SMatthew G. Knepley . prob - The PetscDS object 2597194d53e6SMatthew G. Knepley 2598194d53e6SMatthew G. Knepley Output Parameter: 2599194d53e6SMatthew G. Knepley . offsets - The offsets 2600194d53e6SMatthew G. Knepley 2601194d53e6SMatthew G. Knepley Level: beginner 2602194d53e6SMatthew G. Knepley 2603f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2604194d53e6SMatthew G. Knepley @*/ 2605194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[]) 2606194d53e6SMatthew G. Knepley { 2607194d53e6SMatthew G. Knepley PetscFunctionBegin; 2608194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2609194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2610194d53e6SMatthew G. Knepley *offsets = prob->off; 2611194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2612194d53e6SMatthew G. Knepley } 2613194d53e6SMatthew G. Knepley 2614194d53e6SMatthew G. Knepley /*@ 2615194d53e6SMatthew G. Knepley PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point 2616194d53e6SMatthew G. Knepley 2617194d53e6SMatthew G. Knepley Not collective 2618194d53e6SMatthew G. Knepley 2619194d53e6SMatthew G. Knepley Input Parameter: 2620194d53e6SMatthew G. Knepley . prob - The PetscDS object 2621194d53e6SMatthew G. Knepley 2622194d53e6SMatthew G. Knepley Output Parameter: 2623194d53e6SMatthew G. Knepley . offsets - The offsets 2624194d53e6SMatthew G. Knepley 2625194d53e6SMatthew G. Knepley Level: beginner 2626194d53e6SMatthew G. Knepley 2627f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2628194d53e6SMatthew G. Knepley @*/ 2629194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[]) 2630194d53e6SMatthew G. Knepley { 2631194d53e6SMatthew G. Knepley PetscFunctionBegin; 2632194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2633194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2634194d53e6SMatthew G. Knepley *offsets = prob->offDer; 2635194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2636194d53e6SMatthew G. Knepley } 2637194d53e6SMatthew G. Knepley 263868c9edb9SMatthew G. Knepley /*@C 263968c9edb9SMatthew G. Knepley PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization 264068c9edb9SMatthew G. Knepley 264168c9edb9SMatthew G. Knepley Not collective 264268c9edb9SMatthew G. Knepley 264368c9edb9SMatthew G. Knepley Input Parameter: 264468c9edb9SMatthew G. Knepley . prob - The PetscDS object 264568c9edb9SMatthew G. Knepley 264668c9edb9SMatthew G. Knepley Output Parameters: 264768c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points 264868c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points 264968c9edb9SMatthew G. Knepley 265068c9edb9SMatthew G. Knepley Level: intermediate 265168c9edb9SMatthew G. Knepley 2652f744cafaSSander Arens .seealso: PetscDSCreate() 265368c9edb9SMatthew G. Knepley @*/ 26542764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer) 26552764a2aaSMatthew G. Knepley { 26562764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26572764a2aaSMatthew G. Knepley 26582764a2aaSMatthew G. Knepley PetscFunctionBegin; 26592764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26602764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 26612764a2aaSMatthew G. Knepley if (basis) {PetscValidPointer(basis, 2); *basis = prob->basis;} 26622764a2aaSMatthew G. Knepley if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;} 26632764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26642764a2aaSMatthew G. Knepley } 26652764a2aaSMatthew G. Knepley 266668c9edb9SMatthew G. Knepley /*@C 26674d0b9603SSander Arens PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces 266868c9edb9SMatthew G. Knepley 266968c9edb9SMatthew G. Knepley Not collective 267068c9edb9SMatthew G. Knepley 267168c9edb9SMatthew G. Knepley Input Parameter: 267268c9edb9SMatthew G. Knepley . prob - The PetscDS object 267368c9edb9SMatthew G. Knepley 267468c9edb9SMatthew G. Knepley Output Parameters: 26754d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points 26764d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points 267768c9edb9SMatthew G. Knepley 267868c9edb9SMatthew G. Knepley Level: intermediate 267968c9edb9SMatthew G. Knepley 268068c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate() 268168c9edb9SMatthew G. Knepley @*/ 26824d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer) 26832764a2aaSMatthew G. Knepley { 26842764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26852764a2aaSMatthew G. Knepley 26862764a2aaSMatthew G. Knepley PetscFunctionBegin; 26872764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26882764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 26894d0b9603SSander Arens if (basis) {PetscValidPointer(basis, 2); *basis = prob->basisFace;} 26904d0b9603SSander Arens if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;} 26912764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26922764a2aaSMatthew G. Knepley } 26932764a2aaSMatthew G. Knepley 26942764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) 26952764a2aaSMatthew G. Knepley { 26962764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26972764a2aaSMatthew G. Knepley 26982764a2aaSMatthew G. Knepley PetscFunctionBegin; 26992764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 27002764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 27012764a2aaSMatthew G. Knepley if (u) {PetscValidPointer(u, 2); *u = prob->u;} 27022764a2aaSMatthew G. Knepley if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;} 27032764a2aaSMatthew G. Knepley if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;} 27042764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27052764a2aaSMatthew G. Knepley } 27062764a2aaSMatthew G. Knepley 27072764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) 27082764a2aaSMatthew G. Knepley { 27092764a2aaSMatthew G. Knepley PetscErrorCode ierr; 27102764a2aaSMatthew G. Knepley 27112764a2aaSMatthew G. Knepley PetscFunctionBegin; 27122764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 27132764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 27142764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;} 27152764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;} 27162764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;} 27172764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;} 27182764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;} 27192764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;} 27202764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27212764a2aaSMatthew G. Knepley } 27222764a2aaSMatthew G. Knepley 27232764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer) 27242764a2aaSMatthew G. Knepley { 27252764a2aaSMatthew G. Knepley PetscErrorCode ierr; 27262764a2aaSMatthew G. Knepley 27272764a2aaSMatthew G. Knepley PetscFunctionBegin; 27282764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 27292764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 27302764a2aaSMatthew G. Knepley if (x) {PetscValidPointer(x, 2); *x = prob->x;} 27312764a2aaSMatthew G. Knepley if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;} 27322764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27332764a2aaSMatthew G. Knepley } 27342764a2aaSMatthew G. Knepley 273558ebd649SToby Isaac /*@C 273658ebd649SToby Isaac PetscDSAddBoundary - Add a boundary condition to the model 273758ebd649SToby Isaac 273858ebd649SToby Isaac Input Parameters: 273958ebd649SToby Isaac + ds - The PetscDS object 27402d47a189SJulian Andrej . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 274158ebd649SToby Isaac . name - The BC name 274258ebd649SToby Isaac . labelname - The label defining constrained points 274358ebd649SToby Isaac . field - The field to constrain 2744e8ecbf3fSStefano Zampini . numcomps - The number of constrained field components (0 will constrain all fields) 274558ebd649SToby Isaac . comps - An array of constrained component numbers 274658ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 274758ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 274858ebd649SToby Isaac . ids - An array of ids for constrained points 274958ebd649SToby Isaac - ctx - An optional user context for bcFunc 275058ebd649SToby Isaac 275158ebd649SToby Isaac Options Database Keys: 275258ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 275358ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 275458ebd649SToby Isaac 275558ebd649SToby Isaac Level: developer 275658ebd649SToby Isaac 275758ebd649SToby Isaac .seealso: PetscDSGetBoundary() 275858ebd649SToby Isaac @*/ 2759a30ec4eaSSatish 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) 276058ebd649SToby Isaac { 276158ebd649SToby Isaac DSBoundary b; 276258ebd649SToby Isaac PetscErrorCode ierr; 276358ebd649SToby Isaac 276458ebd649SToby Isaac PetscFunctionBegin; 276558ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 276658ebd649SToby Isaac ierr = PetscNew(&b);CHKERRQ(ierr); 276758ebd649SToby Isaac ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 276858ebd649SToby Isaac ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 276958ebd649SToby Isaac ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 277058ebd649SToby Isaac if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);} 277158ebd649SToby Isaac ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 277258ebd649SToby Isaac if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);} 2773f971fd6bSMatthew G. Knepley b->type = type; 277458ebd649SToby Isaac b->field = field; 277558ebd649SToby Isaac b->numcomps = numcomps; 277658ebd649SToby Isaac b->func = bcFunc; 277758ebd649SToby Isaac b->numids = numids; 277858ebd649SToby Isaac b->ctx = ctx; 277958ebd649SToby Isaac b->next = ds->boundary; 278058ebd649SToby Isaac ds->boundary = b; 278158ebd649SToby Isaac PetscFunctionReturn(0); 278258ebd649SToby Isaac } 278358ebd649SToby Isaac 2784b67eacb3SMatthew G. Knepley /*@C 2785b67eacb3SMatthew G. Knepley PetscDSUpdateBoundary - Change a boundary condition for the model 2786b67eacb3SMatthew G. Knepley 2787b67eacb3SMatthew G. Knepley Input Parameters: 2788b67eacb3SMatthew G. Knepley + ds - The PetscDS object 2789b67eacb3SMatthew G. Knepley . bd - The boundary condition number 2790b67eacb3SMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 2791b67eacb3SMatthew G. Knepley . name - The BC name 2792b67eacb3SMatthew G. Knepley . labelname - The label defining constrained points 2793b67eacb3SMatthew G. Knepley . field - The field to constrain 2794b67eacb3SMatthew G. Knepley . numcomps - The number of constrained field components 2795b67eacb3SMatthew G. Knepley . comps - An array of constrained component numbers 2796b67eacb3SMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 2797b67eacb3SMatthew G. Knepley . numids - The number of DMLabel ids for constrained points 2798b67eacb3SMatthew G. Knepley . ids - An array of ids for constrained points 2799b67eacb3SMatthew G. Knepley - ctx - An optional user context for bcFunc 2800b67eacb3SMatthew G. Knepley 28019a6efb6aSMatthew 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(). 28029a6efb6aSMatthew G. Knepley 2803b67eacb3SMatthew G. Knepley Level: developer 2804b67eacb3SMatthew G. Knepley 28059a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary() 2806b67eacb3SMatthew G. Knepley @*/ 2807b67eacb3SMatthew 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) 2808b67eacb3SMatthew G. Knepley { 2809b67eacb3SMatthew G. Knepley DSBoundary b = ds->boundary; 2810b67eacb3SMatthew G. Knepley PetscInt n = 0; 2811b67eacb3SMatthew G. Knepley PetscErrorCode ierr; 2812b67eacb3SMatthew G. Knepley 2813b67eacb3SMatthew G. Knepley PetscFunctionBegin; 2814b67eacb3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 2815b67eacb3SMatthew G. Knepley while (b) { 2816b67eacb3SMatthew G. Knepley if (n == bd) break; 2817b67eacb3SMatthew G. Knepley b = b->next; 2818b67eacb3SMatthew G. Knepley ++n; 2819b67eacb3SMatthew G. Knepley } 2820b67eacb3SMatthew G. Knepley if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 2821b67eacb3SMatthew G. Knepley if (name) { 2822b67eacb3SMatthew G. Knepley ierr = PetscFree(b->name);CHKERRQ(ierr); 2823b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 2824b67eacb3SMatthew G. Knepley } 2825b67eacb3SMatthew G. Knepley if (labelname) { 2826b67eacb3SMatthew G. Knepley ierr = PetscFree(b->labelname);CHKERRQ(ierr); 2827b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 2828b67eacb3SMatthew G. Knepley } 2829b67eacb3SMatthew G. Knepley if (numcomps >= 0 && numcomps != b->numcomps) { 2830b67eacb3SMatthew G. Knepley b->numcomps = numcomps; 2831b67eacb3SMatthew G. Knepley ierr = PetscFree(b->comps);CHKERRQ(ierr); 2832b67eacb3SMatthew G. Knepley ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 2833b67eacb3SMatthew G. Knepley if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);} 2834b67eacb3SMatthew G. Knepley } 2835b67eacb3SMatthew G. Knepley if (numids >= 0 && numids != b->numids) { 2836b67eacb3SMatthew G. Knepley b->numids = numids; 2837b67eacb3SMatthew G. Knepley ierr = PetscFree(b->ids);CHKERRQ(ierr); 2838b67eacb3SMatthew G. Knepley ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 2839b67eacb3SMatthew G. Knepley if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);} 2840b67eacb3SMatthew G. Knepley } 2841b67eacb3SMatthew G. Knepley b->type = type; 2842b67eacb3SMatthew G. Knepley if (field >= 0) {b->field = field;} 2843b67eacb3SMatthew G. Knepley if (bcFunc) {b->func = bcFunc;} 2844b67eacb3SMatthew G. Knepley if (ctx) {b->ctx = ctx;} 2845b67eacb3SMatthew G. Knepley PetscFunctionReturn(0); 2846b67eacb3SMatthew G. Knepley } 2847b67eacb3SMatthew G. Knepley 284858ebd649SToby Isaac /*@ 284958ebd649SToby Isaac PetscDSGetNumBoundary - Get the number of registered BC 285058ebd649SToby Isaac 285158ebd649SToby Isaac Input Parameters: 285258ebd649SToby Isaac . ds - The PetscDS object 285358ebd649SToby Isaac 285458ebd649SToby Isaac Output Parameters: 285558ebd649SToby Isaac . numBd - The number of BC 285658ebd649SToby Isaac 285758ebd649SToby Isaac Level: intermediate 285858ebd649SToby Isaac 285958ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary() 286058ebd649SToby Isaac @*/ 286158ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd) 286258ebd649SToby Isaac { 286358ebd649SToby Isaac DSBoundary b = ds->boundary; 286458ebd649SToby Isaac 286558ebd649SToby Isaac PetscFunctionBegin; 286658ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 286758ebd649SToby Isaac PetscValidPointer(numBd, 2); 286858ebd649SToby Isaac *numBd = 0; 286958ebd649SToby Isaac while (b) {++(*numBd); b = b->next;} 287058ebd649SToby Isaac PetscFunctionReturn(0); 287158ebd649SToby Isaac } 287258ebd649SToby Isaac 287358ebd649SToby Isaac /*@C 28749a6efb6aSMatthew G. Knepley PetscDSGetBoundary - Gets a boundary condition to the model 287558ebd649SToby Isaac 287658ebd649SToby Isaac Input Parameters: 287758ebd649SToby Isaac + ds - The PetscDS object 287858ebd649SToby Isaac - bd - The BC number 287958ebd649SToby Isaac 288058ebd649SToby Isaac Output Parameters: 28812d47a189SJulian Andrej + type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 288258ebd649SToby Isaac . name - The BC name 288358ebd649SToby Isaac . labelname - The label defining constrained points 288458ebd649SToby Isaac . field - The field to constrain 288558ebd649SToby Isaac . numcomps - The number of constrained field components 288658ebd649SToby Isaac . comps - An array of constrained component numbers 288758ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 288858ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 288958ebd649SToby Isaac . ids - An array of ids for constrained points 289058ebd649SToby Isaac - ctx - An optional user context for bcFunc 289158ebd649SToby Isaac 289258ebd649SToby Isaac Options Database Keys: 289358ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 289458ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 289558ebd649SToby Isaac 289658ebd649SToby Isaac Level: developer 289758ebd649SToby Isaac 289858ebd649SToby Isaac .seealso: PetscDSAddBoundary() 289958ebd649SToby Isaac @*/ 2900a30ec4eaSSatish 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) 290158ebd649SToby Isaac { 290258ebd649SToby Isaac DSBoundary b = ds->boundary; 290358ebd649SToby Isaac PetscInt n = 0; 290458ebd649SToby Isaac 290558ebd649SToby Isaac PetscFunctionBegin; 290658ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 290758ebd649SToby Isaac while (b) { 290858ebd649SToby Isaac if (n == bd) break; 290958ebd649SToby Isaac b = b->next; 291058ebd649SToby Isaac ++n; 291158ebd649SToby Isaac } 291258ebd649SToby Isaac if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 2913f971fd6bSMatthew G. Knepley if (type) { 2914f971fd6bSMatthew G. Knepley PetscValidPointer(type, 3); 2915f971fd6bSMatthew G. Knepley *type = b->type; 291658ebd649SToby Isaac } 291758ebd649SToby Isaac if (name) { 291858ebd649SToby Isaac PetscValidPointer(name, 4); 291958ebd649SToby Isaac *name = b->name; 292058ebd649SToby Isaac } 292158ebd649SToby Isaac if (labelname) { 292258ebd649SToby Isaac PetscValidPointer(labelname, 5); 292358ebd649SToby Isaac *labelname = b->labelname; 292458ebd649SToby Isaac } 292558ebd649SToby Isaac if (field) { 292658ebd649SToby Isaac PetscValidPointer(field, 6); 292758ebd649SToby Isaac *field = b->field; 292858ebd649SToby Isaac } 292958ebd649SToby Isaac if (numcomps) { 293058ebd649SToby Isaac PetscValidPointer(numcomps, 7); 293158ebd649SToby Isaac *numcomps = b->numcomps; 293258ebd649SToby Isaac } 293358ebd649SToby Isaac if (comps) { 293458ebd649SToby Isaac PetscValidPointer(comps, 8); 293558ebd649SToby Isaac *comps = b->comps; 293658ebd649SToby Isaac } 293758ebd649SToby Isaac if (func) { 293858ebd649SToby Isaac PetscValidPointer(func, 9); 293958ebd649SToby Isaac *func = b->func; 294058ebd649SToby Isaac } 294158ebd649SToby Isaac if (numids) { 294258ebd649SToby Isaac PetscValidPointer(numids, 10); 294358ebd649SToby Isaac *numids = b->numids; 294458ebd649SToby Isaac } 294558ebd649SToby Isaac if (ids) { 294658ebd649SToby Isaac PetscValidPointer(ids, 11); 294758ebd649SToby Isaac *ids = b->ids; 294858ebd649SToby Isaac } 294958ebd649SToby Isaac if (ctx) { 295058ebd649SToby Isaac PetscValidPointer(ctx, 12); 295158ebd649SToby Isaac *ctx = b->ctx; 295258ebd649SToby Isaac } 295358ebd649SToby Isaac PetscFunctionReturn(0); 295458ebd649SToby Isaac } 295558ebd649SToby Isaac 29569252d075SMatthew G. Knepley /*@ 29579252d075SMatthew G. Knepley PetscDSCopyBoundary - Copy all boundary condition objects to the new problem 29589252d075SMatthew G. Knepley 29599252d075SMatthew G. Knepley Not collective 29609252d075SMatthew G. Knepley 29619252d075SMatthew G. Knepley Input Parameter: 29629252d075SMatthew G. Knepley . prob - The PetscDS object 29639252d075SMatthew G. Knepley 29649252d075SMatthew G. Knepley Output Parameter: 29659252d075SMatthew G. Knepley . newprob - The PetscDS copy 29669252d075SMatthew G. Knepley 29679252d075SMatthew G. Knepley Level: intermediate 29689252d075SMatthew G. Knepley 29699252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 29709252d075SMatthew G. Knepley @*/ 2971dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB) 2972dff059c6SToby Isaac { 2973dff059c6SToby Isaac DSBoundary b, next, *lastnext; 2974dff059c6SToby Isaac PetscErrorCode ierr; 2975dff059c6SToby Isaac 2976dff059c6SToby Isaac PetscFunctionBegin; 2977dff059c6SToby Isaac PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1); 2978dff059c6SToby Isaac PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2); 2979dff059c6SToby Isaac if (probA == probB) PetscFunctionReturn(0); 2980dff059c6SToby Isaac next = probB->boundary; 2981dff059c6SToby Isaac while (next) { 2982dff059c6SToby Isaac DSBoundary b = next; 2983dff059c6SToby Isaac 2984dff059c6SToby Isaac next = b->next; 2985dff059c6SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 2986dff059c6SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 2987dff059c6SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 2988dff059c6SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 2989dff059c6SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 2990dff059c6SToby Isaac } 2991dff059c6SToby Isaac lastnext = &(probB->boundary); 2992dff059c6SToby Isaac for (b = probA->boundary; b; b = b->next) { 2993dff059c6SToby Isaac DSBoundary bNew; 2994dff059c6SToby Isaac 2995459726d8SSatish Balay ierr = PetscNew(&bNew);CHKERRQ(ierr); 2996dff059c6SToby Isaac bNew->numcomps = b->numcomps; 2997dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr); 2998dff059c6SToby Isaac ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr); 2999dff059c6SToby Isaac bNew->numids = b->numids; 3000dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr); 3001dff059c6SToby Isaac ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr); 3002dff059c6SToby Isaac ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr); 3003dff059c6SToby Isaac ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr); 3004dff059c6SToby Isaac bNew->ctx = b->ctx; 3005f971fd6bSMatthew G. Knepley bNew->type = b->type; 3006dff059c6SToby Isaac bNew->field = b->field; 3007dff059c6SToby Isaac bNew->func = b->func; 3008dff059c6SToby Isaac 3009dff059c6SToby Isaac *lastnext = bNew; 3010dff059c6SToby Isaac lastnext = &(bNew->next); 3011dff059c6SToby Isaac } 3012dff059c6SToby Isaac PetscFunctionReturn(0); 3013dff059c6SToby Isaac } 3014dff059c6SToby Isaac 30159252d075SMatthew G. Knepley /*@C 30169252d075SMatthew G. Knepley PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout 30179252d075SMatthew G. Knepley 30189252d075SMatthew G. Knepley Not collective 30199252d075SMatthew G. Knepley 30209252d075SMatthew G. Knepley Input Parameter: 30219252d075SMatthew G. Knepley + prob - The PetscDS object 30229252d075SMatthew G. Knepley . numFields - Number of new fields 30239252d075SMatthew G. Knepley - fields - Old field number for each new field 30249252d075SMatthew G. Knepley 30259252d075SMatthew G. Knepley Output Parameter: 30269252d075SMatthew G. Knepley . newprob - The PetscDS copy 30279252d075SMatthew G. Knepley 30289252d075SMatthew G. Knepley Level: intermediate 30299252d075SMatthew G. Knepley 30309252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 30319252d075SMatthew G. Knepley @*/ 30329252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 30339252d075SMatthew G. Knepley { 30349252d075SMatthew G. Knepley PetscInt Nf, Nfn, fn, gn; 30359252d075SMatthew G. Knepley PetscErrorCode ierr; 30369252d075SMatthew G. Knepley 30379252d075SMatthew G. Knepley PetscFunctionBegin; 30389252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30399252d075SMatthew G. Knepley if (fields) PetscValidPointer(fields, 3); 30409252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 30419252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 30429252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr); 30439252d075SMatthew 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); 30449252d075SMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 30459252d075SMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 30469252d075SMatthew G. Knepley PetscPointFunc obj; 30479252d075SMatthew G. Knepley PetscPointFunc f0, f1; 30489252d075SMatthew G. Knepley PetscBdPointFunc f0Bd, f1Bd; 30499252d075SMatthew G. Knepley PetscRiemannFunc r; 30509252d075SMatthew G. Knepley 30519252d075SMatthew G. Knepley if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf); 30529252d075SMatthew G. Knepley ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr); 30539252d075SMatthew G. Knepley ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr); 30549252d075SMatthew G. Knepley ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr); 30559252d075SMatthew G. Knepley ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr); 30569252d075SMatthew G. Knepley ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr); 30579252d075SMatthew G. Knepley ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr); 30589252d075SMatthew G. Knepley ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr); 30599252d075SMatthew G. Knepley ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr); 30609252d075SMatthew G. Knepley for (gn = 0; gn < numFields; ++gn) { 30619252d075SMatthew G. Knepley const PetscInt g = fields ? fields[gn] : gn; 30629252d075SMatthew G. Knepley PetscPointJac g0, g1, g2, g3; 30639252d075SMatthew G. Knepley PetscPointJac g0p, g1p, g2p, g3p; 30649252d075SMatthew G. Knepley PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd; 30659252d075SMatthew G. Knepley 30669252d075SMatthew G. Knepley if (g >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", g, Nf); 30679252d075SMatthew G. Knepley ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr); 30689252d075SMatthew G. Knepley ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr); 30699252d075SMatthew G. Knepley ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr); 30709252d075SMatthew G. Knepley ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr); 30719252d075SMatthew G. Knepley ierr = PetscDSSetJacobianPreconditioner(prob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr); 30729252d075SMatthew G. Knepley ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr); 30739252d075SMatthew G. Knepley } 30749252d075SMatthew G. Knepley } 30759252d075SMatthew G. Knepley PetscFunctionReturn(0); 30769252d075SMatthew G. Knepley } 30779252d075SMatthew G. Knepley 3078da51fcedSMatthew G. Knepley /*@ 3079da51fcedSMatthew G. Knepley PetscDSCopyEquations - Copy all pointwise function pointers to the new problem 3080da51fcedSMatthew G. Knepley 3081da51fcedSMatthew G. Knepley Not collective 3082da51fcedSMatthew G. Knepley 3083da51fcedSMatthew G. Knepley Input Parameter: 3084da51fcedSMatthew G. Knepley . prob - The PetscDS object 3085da51fcedSMatthew G. Knepley 3086da51fcedSMatthew G. Knepley Output Parameter: 3087da51fcedSMatthew G. Knepley . newprob - The PetscDS copy 3088da51fcedSMatthew G. Knepley 3089da51fcedSMatthew G. Knepley Level: intermediate 3090da51fcedSMatthew G. Knepley 30919252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 3092da51fcedSMatthew G. Knepley @*/ 3093da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob) 3094da51fcedSMatthew G. Knepley { 30959252d075SMatthew G. Knepley PetscInt Nf, Ng; 3096da51fcedSMatthew G. Knepley PetscErrorCode ierr; 3097da51fcedSMatthew G. Knepley 3098da51fcedSMatthew G. Knepley PetscFunctionBegin; 3099da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3100da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 3101da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3102da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr); 310313903a91SSatish Balay if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng); 31049252d075SMatthew G. Knepley ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr); 31059252d075SMatthew G. Knepley PetscFunctionReturn(0); 31069252d075SMatthew G. Knepley } 31079252d075SMatthew G. Knepley /*@ 31089252d075SMatthew G. Knepley PetscDSCopyConstants - Copy all constants to the new problem 3109da51fcedSMatthew G. Knepley 31109252d075SMatthew G. Knepley Not collective 31119252d075SMatthew G. Knepley 31129252d075SMatthew G. Knepley Input Parameter: 31139252d075SMatthew G. Knepley . prob - The PetscDS object 31149252d075SMatthew G. Knepley 31159252d075SMatthew G. Knepley Output Parameter: 31169252d075SMatthew G. Knepley . newprob - The PetscDS copy 31179252d075SMatthew G. Knepley 31189252d075SMatthew G. Knepley Level: intermediate 31199252d075SMatthew G. Knepley 31209252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 31219252d075SMatthew G. Knepley @*/ 31229252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob) 31239252d075SMatthew G. Knepley { 31249252d075SMatthew G. Knepley PetscInt Nc; 31259252d075SMatthew G. Knepley const PetscScalar *constants; 31269252d075SMatthew G. Knepley PetscErrorCode ierr; 31279252d075SMatthew G. Knepley 31289252d075SMatthew G. Knepley PetscFunctionBegin; 31299252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 31309252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 31319252d075SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr); 31329252d075SMatthew G. Knepley ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr); 3133da51fcedSMatthew G. Knepley PetscFunctionReturn(0); 3134da51fcedSMatthew G. Knepley } 3135da51fcedSMatthew G. Knepley 3136b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob) 3137b1353e8eSMatthew G. Knepley { 3138df3a45bdSMatthew G. Knepley PetscInt dim, Nf, f; 3139b1353e8eSMatthew G. Knepley PetscErrorCode ierr; 3140b1353e8eSMatthew G. Knepley 3141b1353e8eSMatthew G. Knepley PetscFunctionBegin; 3142b1353e8eSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3143b1353e8eSMatthew G. Knepley PetscValidPointer(subprob, 3); 3144b1353e8eSMatthew G. Knepley if (height == 0) {*subprob = prob; PetscFunctionReturn(0);} 3145b1353e8eSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3146df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 3147df3a45bdSMatthew 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); 3148df3a45bdSMatthew G. Knepley if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);} 3149df3a45bdSMatthew G. Knepley if (!prob->subprobs[height-1]) { 3150b1353e8eSMatthew G. Knepley PetscInt cdim; 3151b1353e8eSMatthew G. Knepley 3152df3a45bdSMatthew G. Knepley ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr); 3153b1353e8eSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr); 3154df3a45bdSMatthew G. Knepley ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr); 3155b1353e8eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3156b1353e8eSMatthew G. Knepley PetscFE subfe; 3157b1353e8eSMatthew G. Knepley PetscObject obj; 3158b1353e8eSMatthew G. Knepley PetscClassId id; 3159b1353e8eSMatthew G. Knepley 3160b1353e8eSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 3161b1353e8eSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3162b1353e8eSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);} 3163b1353e8eSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f); 3164df3a45bdSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr); 3165b1353e8eSMatthew G. Knepley } 3166b1353e8eSMatthew G. Knepley } 3167df3a45bdSMatthew G. Knepley *subprob = prob->subprobs[height-1]; 3168b1353e8eSMatthew G. Knepley PetscFunctionReturn(0); 3169b1353e8eSMatthew G. Knepley } 3170b1353e8eSMatthew G. Knepley 3171bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob) 31722764a2aaSMatthew G. Knepley { 3173931fb3b8SToby Isaac PetscErrorCode ierr; 3174931fb3b8SToby Isaac 31752764a2aaSMatthew G. Knepley PetscFunctionBegin; 3176931fb3b8SToby Isaac ierr = PetscFree(prob->data);CHKERRQ(ierr); 31772764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31782764a2aaSMatthew G. Knepley } 31792764a2aaSMatthew G. Knepley 3180bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob) 31812764a2aaSMatthew G. Knepley { 31822764a2aaSMatthew G. Knepley PetscFunctionBegin; 31832764a2aaSMatthew G. Knepley prob->ops->setfromoptions = NULL; 31842764a2aaSMatthew G. Knepley prob->ops->setup = NULL; 31852764a2aaSMatthew G. Knepley prob->ops->view = NULL; 31862764a2aaSMatthew G. Knepley prob->ops->destroy = PetscDSDestroy_Basic; 31872764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31882764a2aaSMatthew G. Knepley } 31892764a2aaSMatthew G. Knepley 31902764a2aaSMatthew G. Knepley /*MC 31912764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 31922764a2aaSMatthew G. Knepley 31932764a2aaSMatthew G. Knepley Level: intermediate 31942764a2aaSMatthew G. Knepley 31952764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType() 31962764a2aaSMatthew G. Knepley M*/ 31972764a2aaSMatthew G. Knepley 31982764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob) 31992764a2aaSMatthew G. Knepley { 32002764a2aaSMatthew G. Knepley PetscDS_Basic *b; 32012764a2aaSMatthew G. Knepley PetscErrorCode ierr; 32022764a2aaSMatthew G. Knepley 32032764a2aaSMatthew G. Knepley PetscFunctionBegin; 3204931fb3b8SToby Isaac PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 32052764a2aaSMatthew G. Knepley ierr = PetscNewLog(prob, &b);CHKERRQ(ierr); 32062764a2aaSMatthew G. Knepley prob->data = b; 32072764a2aaSMatthew G. Knepley 32082764a2aaSMatthew G. Knepley ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr); 32092764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 32102764a2aaSMatthew G. Knepley } 3211