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 .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy() 532764a2aaSMatthew G. Knepley 542764a2aaSMatthew G. Knepley @*/ 552764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS)) 562764a2aaSMatthew G. Knepley { 572764a2aaSMatthew G. Knepley PetscErrorCode ierr; 582764a2aaSMatthew G. Knepley 592764a2aaSMatthew G. Knepley PetscFunctionBegin; 602764a2aaSMatthew G. Knepley ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr); 612764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 622764a2aaSMatthew G. Knepley } 632764a2aaSMatthew G. Knepley 642764a2aaSMatthew G. Knepley /*@C 652764a2aaSMatthew G. Knepley PetscDSSetType - Builds a particular PetscDS 662764a2aaSMatthew G. Knepley 67d083f849SBarry Smith Collective on prob 682764a2aaSMatthew G. Knepley 692764a2aaSMatthew G. Knepley Input Parameters: 702764a2aaSMatthew G. Knepley + prob - The PetscDS object 712764a2aaSMatthew G. Knepley - name - The kind of system 722764a2aaSMatthew G. Knepley 732764a2aaSMatthew G. Knepley Options Database Key: 742764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types 752764a2aaSMatthew G. Knepley 762764a2aaSMatthew G. Knepley Level: intermediate 772764a2aaSMatthew G. Knepley 78f5f57ec0SBarry Smith Not available from Fortran 79f5f57ec0SBarry Smith 802764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate() 812764a2aaSMatthew G. Knepley @*/ 822764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name) 832764a2aaSMatthew G. Knepley { 842764a2aaSMatthew G. Knepley PetscErrorCode (*r)(PetscDS); 852764a2aaSMatthew G. Knepley PetscBool match; 862764a2aaSMatthew G. Knepley PetscErrorCode ierr; 872764a2aaSMatthew G. Knepley 882764a2aaSMatthew G. Knepley PetscFunctionBegin; 892764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 902764a2aaSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr); 912764a2aaSMatthew G. Knepley if (match) PetscFunctionReturn(0); 922764a2aaSMatthew G. Knepley 930f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 942764a2aaSMatthew G. Knepley ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr); 952764a2aaSMatthew G. Knepley if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name); 962764a2aaSMatthew G. Knepley 972764a2aaSMatthew G. Knepley if (prob->ops->destroy) { 982764a2aaSMatthew G. Knepley ierr = (*prob->ops->destroy)(prob);CHKERRQ(ierr); 992764a2aaSMatthew G. Knepley prob->ops->destroy = NULL; 1002764a2aaSMatthew G. Knepley } 1012764a2aaSMatthew G. Knepley ierr = (*r)(prob);CHKERRQ(ierr); 1022764a2aaSMatthew G. Knepley ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr); 1032764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 1042764a2aaSMatthew G. Knepley } 1052764a2aaSMatthew G. Knepley 1062764a2aaSMatthew G. Knepley /*@C 1072764a2aaSMatthew G. Knepley PetscDSGetType - Gets the PetscDS type name (as a string) from the object. 1082764a2aaSMatthew G. Knepley 1092764a2aaSMatthew G. Knepley Not Collective 1102764a2aaSMatthew G. Knepley 1112764a2aaSMatthew G. Knepley Input Parameter: 1122764a2aaSMatthew G. Knepley . prob - The PetscDS 1132764a2aaSMatthew G. Knepley 1142764a2aaSMatthew G. Knepley Output Parameter: 1152764a2aaSMatthew G. Knepley . name - The PetscDS type name 1162764a2aaSMatthew G. Knepley 1172764a2aaSMatthew G. Knepley Level: intermediate 1182764a2aaSMatthew G. Knepley 119f5f57ec0SBarry Smith Not available from Fortran 120f5f57ec0SBarry Smith 1212764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate() 1222764a2aaSMatthew G. Knepley @*/ 1232764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name) 1242764a2aaSMatthew G. Knepley { 1252764a2aaSMatthew G. Knepley PetscErrorCode ierr; 1262764a2aaSMatthew G. Knepley 1272764a2aaSMatthew G. Knepley PetscFunctionBegin; 1282764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 129c959eef4SJed Brown PetscValidPointer(name, 2); 1300f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 1312764a2aaSMatthew G. Knepley *name = ((PetscObject) prob)->type_name; 1322764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 1332764a2aaSMatthew G. Knepley } 1342764a2aaSMatthew G. Knepley 1357d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer) 1367d8a60eaSMatthew G. Knepley { 1377d8a60eaSMatthew G. Knepley PetscViewerFormat format; 13897b6e6e8SMatthew G. Knepley const PetscScalar *constants; 13997b6e6e8SMatthew G. Knepley PetscInt numConstants, f; 1407d8a60eaSMatthew G. Knepley PetscErrorCode ierr; 1417d8a60eaSMatthew G. Knepley 1427d8a60eaSMatthew G. Knepley PetscFunctionBegin; 1437d8a60eaSMatthew G. Knepley ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 1447d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr); 1457d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 1464727e194SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " cell total dim %D total comp %D\n", prob->totDim, prob->totComp);CHKERRQ(ierr); 1474727e194SMatthew G. Knepley if (prob->isHybrid) {ierr = PetscViewerASCIIPrintf(viewer, " hybrid cell\n");CHKERRQ(ierr);} 1487d8a60eaSMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 14940967b3bSMatthew G. Knepley DSBoundary b; 1507d8a60eaSMatthew G. Knepley PetscObject obj; 1517d8a60eaSMatthew G. Knepley PetscClassId id; 152f35450b9SMatthew G. Knepley PetscQuadrature q; 1537d8a60eaSMatthew G. Knepley const char *name; 154f35450b9SMatthew G. Knepley PetscInt Nc, Nq, Nqc; 1557d8a60eaSMatthew G. Knepley 1567d8a60eaSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 1577d8a60eaSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 1587d8a60eaSMatthew G. Knepley ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr); 1597d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr); 1604727e194SMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 1617d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 1627d8a60eaSMatthew G. Knepley ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr); 163f35450b9SMatthew G. Knepley ierr = PetscFEGetQuadrature((PetscFE) obj, &q);CHKERRQ(ierr); 1647d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr); 1657d8a60eaSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 1667d8a60eaSMatthew G. Knepley ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr); 167f35450b9SMatthew G. Knepley ierr = PetscFVGetQuadrature((PetscFV) obj, &q);CHKERRQ(ierr); 1687d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr); 1697d8a60eaSMatthew G. Knepley } 17097b6e6e8SMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f); 17197b6e6e8SMatthew G. Knepley if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%D components", Nc);CHKERRQ(ierr);} 17297b6e6e8SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, "%D component ", Nc);CHKERRQ(ierr);} 173249df284SMatthew G. Knepley if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);} 174249df284SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);} 1753e60c2a6SMatthew G. Knepley if (q) { 176f35450b9SMatthew G. Knepley ierr = PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL);CHKERRQ(ierr); 177f35450b9SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " (Nq %D Nqc %D)", Nq, Nqc);CHKERRQ(ierr); 1783e60c2a6SMatthew G. Knepley } 1797d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 1804727e194SMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 1815d160056SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 1827d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);} 1837d8a60eaSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);} 1845d160056SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 18540967b3bSMatthew G. Knepley 18640967b3bSMatthew G. Knepley for (b = prob->boundary; b; b = b->next) { 18740967b3bSMatthew G. Knepley PetscInt c, i; 18840967b3bSMatthew G. Knepley 18940967b3bSMatthew G. Knepley if (b->field != f) continue; 19040967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 19140967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->labelname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr); 19240967b3bSMatthew G. Knepley if (!b->numcomps) { 19340967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " all components\n");CHKERRQ(ierr); 19440967b3bSMatthew G. Knepley } else { 19540967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " components: ");CHKERRQ(ierr); 19640967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 19740967b3bSMatthew G. Knepley for (c = 0; c < b->numcomps; ++c) { 19840967b3bSMatthew G. Knepley if (c > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 19940967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->comps[c]);CHKERRQ(ierr); 20040967b3bSMatthew G. Knepley } 20140967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 20240967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 20340967b3bSMatthew G. Knepley } 20440967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " ids: ");CHKERRQ(ierr); 20540967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 20640967b3bSMatthew G. Knepley for (i = 0; i < b->numids; ++i) { 20740967b3bSMatthew G. Knepley if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 20840967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->ids[i]);CHKERRQ(ierr); 20940967b3bSMatthew G. Knepley } 21040967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 21140967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 21240967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 21340967b3bSMatthew G. Knepley } 2147d8a60eaSMatthew G. Knepley } 21597b6e6e8SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr); 21697b6e6e8SMatthew G. Knepley if (numConstants) { 21797b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr); 21897b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 21957fc01e9SMatthew G. Knepley for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);} 22097b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 22197b6e6e8SMatthew G. Knepley } 2227d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 2237d8a60eaSMatthew G. Knepley PetscFunctionReturn(0); 2247d8a60eaSMatthew G. Knepley } 2257d8a60eaSMatthew G. Knepley 2262764a2aaSMatthew G. Knepley /*@C 227fe2efc57SMark PetscDSViewFromOptions - View from Options 228fe2efc57SMark 229fe2efc57SMark Collective on PetscDS 230fe2efc57SMark 231fe2efc57SMark Input Parameters: 232fe2efc57SMark + A - the PetscDS object 233736c3998SJose E. Roman . obj - Optional object 234736c3998SJose E. Roman - name - command line option 235fe2efc57SMark 236fe2efc57SMark Level: intermediate 237fe2efc57SMark .seealso: PetscDS, PetscDSView, PetscObjectViewFromOptions(), PetscDSCreate() 238fe2efc57SMark @*/ 239fe2efc57SMark PetscErrorCode PetscDSViewFromOptions(PetscDS A,PetscObject obj,const char name[]) 240fe2efc57SMark { 241fe2efc57SMark PetscErrorCode ierr; 242fe2efc57SMark 243fe2efc57SMark PetscFunctionBegin; 244fe2efc57SMark PetscValidHeaderSpecific(A,PETSCDS_CLASSID,1); 245fe2efc57SMark ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr); 246fe2efc57SMark PetscFunctionReturn(0); 247fe2efc57SMark } 248fe2efc57SMark 249fe2efc57SMark /*@C 2502764a2aaSMatthew G. Knepley PetscDSView - Views a PetscDS 2512764a2aaSMatthew G. Knepley 252d083f849SBarry Smith Collective on prob 2532764a2aaSMatthew G. Knepley 2542764a2aaSMatthew G. Knepley Input Parameter: 2552764a2aaSMatthew G. Knepley + prob - the PetscDS object to view 2562764a2aaSMatthew G. Knepley - v - the viewer 2572764a2aaSMatthew G. Knepley 2582764a2aaSMatthew G. Knepley Level: developer 2592764a2aaSMatthew G. Knepley 2602764a2aaSMatthew G. Knepley .seealso PetscDSDestroy() 2612764a2aaSMatthew G. Knepley @*/ 2622764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v) 2632764a2aaSMatthew G. Knepley { 2647d8a60eaSMatthew G. Knepley PetscBool iascii; 2652764a2aaSMatthew G. Knepley PetscErrorCode ierr; 2662764a2aaSMatthew G. Knepley 2672764a2aaSMatthew G. Knepley PetscFunctionBegin; 2682764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2692764a2aaSMatthew G. Knepley if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);} 2707d8a60eaSMatthew G. Knepley else {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);} 2717d8a60eaSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 2727d8a60eaSMatthew G. Knepley if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);} 2732764a2aaSMatthew G. Knepley if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);} 2742764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 2752764a2aaSMatthew G. Knepley } 2762764a2aaSMatthew G. Knepley 2772764a2aaSMatthew G. Knepley /*@ 2782764a2aaSMatthew G. Knepley PetscDSSetFromOptions - sets parameters in a PetscDS from the options database 2792764a2aaSMatthew G. Knepley 280d083f849SBarry Smith Collective on prob 2812764a2aaSMatthew G. Knepley 2822764a2aaSMatthew G. Knepley Input Parameter: 2832764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for 2842764a2aaSMatthew G. Knepley 2852764a2aaSMatthew G. Knepley Options Database: 28655c1f793SMatthew G. Knepley + -petscds_type <type> : Set the DS type 28755c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS 28855c1f793SMatthew G. Knepley . -petscds_jac_pre : Turn formation of a separate Jacobian preconditioner on and off 28955c1f793SMatthew G. Knepley . -bc_<name> <ids> : Specify a list of label ids for a boundary condition 29055c1f793SMatthew G. Knepley - -bc_<name>_comp <comps> : Specify a list of field components to constrain for a boundary condition 2912764a2aaSMatthew G. Knepley 2922764a2aaSMatthew G. Knepley Level: developer 2932764a2aaSMatthew G. Knepley 2942764a2aaSMatthew G. Knepley .seealso PetscDSView() 2952764a2aaSMatthew G. Knepley @*/ 2962764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob) 2972764a2aaSMatthew G. Knepley { 298f1fd5e65SToby Isaac DSBoundary b; 2992764a2aaSMatthew G. Knepley const char *defaultType; 3002764a2aaSMatthew G. Knepley char name[256]; 3012764a2aaSMatthew G. Knepley PetscBool flg; 3022764a2aaSMatthew G. Knepley PetscErrorCode ierr; 3032764a2aaSMatthew G. Knepley 3042764a2aaSMatthew G. Knepley PetscFunctionBegin; 3052764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3062764a2aaSMatthew G. Knepley if (!((PetscObject) prob)->type_name) { 3072764a2aaSMatthew G. Knepley defaultType = PETSCDSBASIC; 3082764a2aaSMatthew G. Knepley } else { 3092764a2aaSMatthew G. Knepley defaultType = ((PetscObject) prob)->type_name; 3102764a2aaSMatthew G. Knepley } 3110f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 3122764a2aaSMatthew G. Knepley 3132764a2aaSMatthew G. Knepley ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr); 314f1fd5e65SToby Isaac for (b = prob->boundary; b; b = b->next) { 315f1fd5e65SToby Isaac char optname[1024]; 316f1fd5e65SToby Isaac PetscInt ids[1024], len = 1024; 317f1fd5e65SToby Isaac PetscBool flg; 318f1fd5e65SToby Isaac 319f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr); 320f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 321f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr); 322f1fd5e65SToby Isaac if (flg) { 323f1fd5e65SToby Isaac b->numids = len; 324f1fd5e65SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 325f1fd5e65SToby Isaac ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr); 326580bdb30SBarry Smith ierr = PetscArraycpy(b->ids, ids, len);CHKERRQ(ierr); 327f1fd5e65SToby Isaac } 328e7b0402cSSander Arens len = 1024; 329f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr); 330f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 331f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr); 332f1fd5e65SToby Isaac if (flg) { 333f1fd5e65SToby Isaac b->numcomps = len; 334f1fd5e65SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 335f1fd5e65SToby Isaac ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr); 336580bdb30SBarry Smith ierr = PetscArraycpy(b->comps, ids, len);CHKERRQ(ierr); 337f1fd5e65SToby Isaac } 338f1fd5e65SToby Isaac } 3392764a2aaSMatthew G. Knepley ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr); 3402764a2aaSMatthew G. Knepley if (flg) { 3412764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, name);CHKERRQ(ierr); 3422764a2aaSMatthew G. Knepley } else if (!((PetscObject) prob)->type_name) { 3432764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr); 3442764a2aaSMatthew G. Knepley } 34555c1f793SMatthew G. Knepley ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr); 3462764a2aaSMatthew G. Knepley if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);} 3472764a2aaSMatthew G. Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 3480633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr); 3492764a2aaSMatthew G. Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 3505d160056SMatthew G. Knepley if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);} 3512764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 3522764a2aaSMatthew G. Knepley } 3532764a2aaSMatthew G. Knepley 3542764a2aaSMatthew G. Knepley /*@C 3552764a2aaSMatthew G. Knepley PetscDSSetUp - Construct data structures for the PetscDS 3562764a2aaSMatthew G. Knepley 357d083f849SBarry Smith Collective on prob 3582764a2aaSMatthew G. Knepley 3592764a2aaSMatthew G. Knepley Input Parameter: 3602764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup 3612764a2aaSMatthew G. Knepley 3622764a2aaSMatthew G. Knepley Level: developer 3632764a2aaSMatthew G. Knepley 3642764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy() 3652764a2aaSMatthew G. Knepley @*/ 3662764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob) 3672764a2aaSMatthew G. Knepley { 3682764a2aaSMatthew G. Knepley const PetscInt Nf = prob->Nf; 3694bee2e38SMatthew G. Knepley PetscInt dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f; 3702764a2aaSMatthew G. Knepley PetscErrorCode ierr; 3712764a2aaSMatthew G. Knepley 3722764a2aaSMatthew G. Knepley PetscFunctionBegin; 3732764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3742764a2aaSMatthew G. Knepley if (prob->setup) PetscFunctionReturn(0); 3752764a2aaSMatthew G. Knepley /* Calculate sizes */ 3762764a2aaSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 377d1506c7cSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr); 378f744cafaSSander Arens prob->totDim = prob->totComp = 0; 37947e57110SSander Arens ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr); 380f744cafaSSander Arens ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr); 381ef0bb6c7SMatthew G. Knepley ierr = PetscMalloc2(Nf,&prob->T,Nf,&prob->Tf);CHKERRQ(ierr); 3822764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3839de99aefSMatthew G. Knepley PetscObject obj; 3849de99aefSMatthew G. Knepley PetscClassId id; 385665f567fSMatthew G. Knepley PetscQuadrature q = NULL; 3869de99aefSMatthew G. Knepley PetscInt Nq = 0, Nb, Nc; 3872764a2aaSMatthew G. Knepley 3889de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 389665f567fSMatthew G. Knepley if (!obj) { 390665f567fSMatthew G. Knepley /* Empty mesh */ 391665f567fSMatthew G. Knepley Nb = Nc = 0; 392665f567fSMatthew G. Knepley prob->T[f] = prob->Tf[f] = NULL; 393665f567fSMatthew G. Knepley } else { 3949de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3959de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 3969de99aefSMatthew G. Knepley PetscFE fe = (PetscFE) obj; 3979de99aefSMatthew G. Knepley 3982764a2aaSMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr); 3992764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 4002764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 401ef0bb6c7SMatthew G. Knepley ierr = PetscFEGetCellTabulation(fe, &prob->T[f]);CHKERRQ(ierr); 402ef0bb6c7SMatthew G. Knepley ierr = PetscFEGetFaceTabulation(fe, &prob->Tf[f]);CHKERRQ(ierr); 4039de99aefSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 4049de99aefSMatthew G. Knepley PetscFV fv = (PetscFV) obj; 4059de99aefSMatthew G. Knepley 4069de99aefSMatthew G. Knepley ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr); 4079de99aefSMatthew G. Knepley ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr); 4089c3cf19fSMatthew G. Knepley Nb = Nc; 409ef0bb6c7SMatthew G. Knepley ierr = PetscFVGetCellTabulation(fv, &prob->T[f]);CHKERRQ(ierr); 4104d0b9603SSander Arens /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */ 411abac5ca0SMatthew G. Knepley } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f); 412665f567fSMatthew G. Knepley } 41347e57110SSander Arens prob->Nc[f] = Nc; 41447e57110SSander Arens prob->Nb[f] = Nb; 415194d53e6SMatthew G. Knepley prob->off[f+1] = Nc + prob->off[f]; 416194d53e6SMatthew G. Knepley prob->offDer[f+1] = Nc*dim + prob->offDer[f]; 417a6b92713SMatthew G. Knepley if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);} 4182764a2aaSMatthew G. Knepley NqMax = PetscMax(NqMax, Nq); 4194bee2e38SMatthew G. Knepley NbMax = PetscMax(NbMax, Nb); 4202764a2aaSMatthew G. Knepley NcMax = PetscMax(NcMax, Nc); 4219c3cf19fSMatthew G. Knepley prob->totDim += Nb; 4222764a2aaSMatthew G. Knepley prob->totComp += Nc; 42394a5e212SMatthew G. Knepley /* There are two faces for all fields but the cohesive field on a hybrid cell */ 42494a5e212SMatthew G. Knepley if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb; 4252764a2aaSMatthew G. Knepley } 4262764a2aaSMatthew G. Knepley /* Allocate works space */ 42794a5e212SMatthew G. Knepley if (prob->isHybrid) NsMax = 2; 4284bee2e38SMatthew G. Knepley ierr = PetscMalloc3(NsMax*prob->totComp,&prob->u,NsMax*prob->totComp,&prob->u_t,NsMax*prob->totComp*dimEmbed,&prob->u_x);CHKERRQ(ierr); 4294bee2e38SMatthew G. Knepley ierr = PetscMalloc5(dimEmbed,&prob->x,NbMax*NcMax,&prob->basisReal,NbMax*NcMax*dimEmbed,&prob->basisDerReal,NbMax*NcMax,&prob->testReal,NbMax*NcMax*dimEmbed,&prob->testDerReal);CHKERRQ(ierr); 43027f02ce8SMatthew G. Knepley ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dimEmbed,&prob->f1, 43127f02ce8SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g1, 43227f02ce8SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed*dimEmbed,&prob->g3);CHKERRQ(ierr); 4332764a2aaSMatthew G. Knepley if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);} 4342764a2aaSMatthew G. Knepley prob->setup = PETSC_TRUE; 4352764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4362764a2aaSMatthew G. Knepley } 4372764a2aaSMatthew G. Knepley 4382764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob) 4392764a2aaSMatthew G. Knepley { 4402764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4412764a2aaSMatthew G. Knepley 4422764a2aaSMatthew G. Knepley PetscFunctionBegin; 44347e57110SSander Arens ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr); 444f744cafaSSander Arens ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr); 445ef0bb6c7SMatthew G. Knepley ierr = PetscFree2(prob->T,prob->Tf);CHKERRQ(ierr); 4464bee2e38SMatthew G. Knepley ierr = PetscFree3(prob->u,prob->u_t,prob->u_x);CHKERRQ(ierr); 4474bee2e38SMatthew G. Knepley ierr = PetscFree5(prob->x,prob->basisReal, prob->basisDerReal,prob->testReal,prob->testDerReal);CHKERRQ(ierr); 4482764a2aaSMatthew G. Knepley ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr); 4492764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4502764a2aaSMatthew G. Knepley } 4512764a2aaSMatthew G. Knepley 4522764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew) 4532764a2aaSMatthew G. Knepley { 454f744cafaSSander Arens PetscObject *tmpd; 45534aa8a36SMatthew G. Knepley PetscBool *tmpi; 45632d2bbc9SMatthew G. Knepley PetscPointFunc *tmpobj, *tmpf, *tmpup; 457b7e05686SMatthew G. Knepley PetscPointJac *tmpg, *tmpgp, *tmpgt; 4582aa1fc23SMatthew G. Knepley PetscBdPointFunc *tmpfbd; 45927f02ce8SMatthew G. Knepley PetscBdPointJac *tmpgbd, *tmpgpbd; 460194d53e6SMatthew G. Knepley PetscRiemannFunc *tmpr; 461c371a6d1SMatthew G. Knepley PetscSimplePointFunc *tmpexactSol; 46295cbbfd3SMatthew G. Knepley void **tmpexactCtx; 4630c2f2876SMatthew G. Knepley void **tmpctx; 46434aa8a36SMatthew G. Knepley PetscInt Nf = prob->Nf, f; 4652764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4662764a2aaSMatthew G. Knepley 4672764a2aaSMatthew G. Knepley PetscFunctionBegin; 4682764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 4692764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 4702764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr); 47134aa8a36SMatthew G. Knepley ierr = PetscMalloc2(NfNew, &tmpd, NfNew, &tmpi);CHKERRQ(ierr); 47234aa8a36SMatthew G. Knepley for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f];} 47334aa8a36SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE;} 47434aa8a36SMatthew G. Knepley ierr = PetscFree2(prob->disc, prob->implicit);CHKERRQ(ierr); 4752764a2aaSMatthew G. Knepley prob->Nf = NfNew; 4762764a2aaSMatthew G. Knepley prob->disc = tmpd; 477249df284SMatthew G. Knepley prob->implicit = tmpi; 478b7e05686SMatthew 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); 47932d2bbc9SMatthew G. Knepley ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr); 4802764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f]; 4812764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f]; 4822764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f]; 483475e0ac9SMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f]; 4840c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f]; 48532d2bbc9SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f]; 4860c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f]; 4872764a2aaSMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL; 4882764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL; 4892764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL; 490475e0ac9SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL; 491b7e05686SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL; 4920c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL; 49332d2bbc9SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL; 4940c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL; 495b7e05686SMatthew G. Knepley ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr); 49632d2bbc9SMatthew G. Knepley ierr = PetscFree(prob->update);CHKERRQ(ierr); 4972764a2aaSMatthew G. Knepley prob->obj = tmpobj; 4982764a2aaSMatthew G. Knepley prob->f = tmpf; 4992764a2aaSMatthew G. Knepley prob->g = tmpg; 500475e0ac9SMatthew G. Knepley prob->gp = tmpgp; 501b7e05686SMatthew G. Knepley prob->gt = tmpgt; 5020c2f2876SMatthew G. Knepley prob->r = tmpr; 50332d2bbc9SMatthew G. Knepley prob->update = tmpup; 5040c2f2876SMatthew G. Knepley prob->ctx = tmpctx; 50527f02ce8SMatthew G. Knepley ierr = PetscCalloc5(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew*NfNew*4, &tmpgpbd, NfNew, &tmpexactSol, NfNew, &tmpexactCtx);CHKERRQ(ierr); 5062764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f]; 5072764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f]; 50827f02ce8SMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgpbd[f] = prob->gpBd[f]; 509c371a6d1SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f]; 51095cbbfd3SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f]; 5112764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL; 5122764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL; 51327f02ce8SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgpbd[f] = NULL; 514c371a6d1SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL; 51595cbbfd3SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL; 51627f02ce8SMatthew G. Knepley ierr = PetscFree5(prob->fBd, prob->gBd, prob->gpBd, prob->exactSol, prob->exactCtx);CHKERRQ(ierr); 5172764a2aaSMatthew G. Knepley prob->fBd = tmpfbd; 5182764a2aaSMatthew G. Knepley prob->gBd = tmpgbd; 51927f02ce8SMatthew G. Knepley prob->gpBd = tmpgpbd; 520c371a6d1SMatthew G. Knepley prob->exactSol = tmpexactSol; 52195cbbfd3SMatthew G. Knepley prob->exactCtx = tmpexactCtx; 5222764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5232764a2aaSMatthew G. Knepley } 5242764a2aaSMatthew G. Knepley 5252764a2aaSMatthew G. Knepley /*@ 5262764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 5272764a2aaSMatthew G. Knepley 528d083f849SBarry Smith Collective on prob 5292764a2aaSMatthew G. Knepley 5302764a2aaSMatthew G. Knepley Input Parameter: 5312764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 5322764a2aaSMatthew G. Knepley 5332764a2aaSMatthew G. Knepley Level: developer 5342764a2aaSMatthew G. Knepley 5352764a2aaSMatthew G. Knepley .seealso PetscDSView() 5362764a2aaSMatthew G. Knepley @*/ 5372764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob) 5382764a2aaSMatthew G. Knepley { 5392764a2aaSMatthew G. Knepley PetscInt f; 54058ebd649SToby Isaac DSBoundary next; 5412764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5422764a2aaSMatthew G. Knepley 5432764a2aaSMatthew G. Knepley PetscFunctionBegin; 5442764a2aaSMatthew G. Knepley if (!*prob) PetscFunctionReturn(0); 5452764a2aaSMatthew G. Knepley PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1); 5462764a2aaSMatthew G. Knepley 5472764a2aaSMatthew G. Knepley if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);} 5482764a2aaSMatthew G. Knepley ((PetscObject) (*prob))->refct = 0; 549df3a45bdSMatthew G. Knepley if ((*prob)->subprobs) { 550df3a45bdSMatthew G. Knepley PetscInt dim, d; 551df3a45bdSMatthew G. Knepley 552df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(*prob, &dim);CHKERRQ(ierr); 553df3a45bdSMatthew G. Knepley for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*prob)->subprobs[d]);CHKERRQ(ierr);} 554df3a45bdSMatthew G. Knepley } 555df3a45bdSMatthew G. Knepley ierr = PetscFree((*prob)->subprobs);CHKERRQ(ierr); 5562764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr); 5572764a2aaSMatthew G. Knepley for (f = 0; f < (*prob)->Nf; ++f) { 5582764a2aaSMatthew G. Knepley ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr); 5592764a2aaSMatthew G. Knepley } 56034aa8a36SMatthew G. Knepley ierr = PetscFree2((*prob)->disc, (*prob)->implicit);CHKERRQ(ierr); 561b7e05686SMatthew G. Knepley ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr); 56232d2bbc9SMatthew G. Knepley ierr = PetscFree((*prob)->update);CHKERRQ(ierr); 56327f02ce8SMatthew G. Knepley ierr = PetscFree5((*prob)->fBd,(*prob)->gBd,(*prob)->gpBd,(*prob)->exactSol,(*prob)->exactCtx);CHKERRQ(ierr); 5642764a2aaSMatthew G. Knepley if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);} 56558ebd649SToby Isaac next = (*prob)->boundary; 56658ebd649SToby Isaac while (next) { 56758ebd649SToby Isaac DSBoundary b = next; 56858ebd649SToby Isaac 56958ebd649SToby Isaac next = b->next; 57058ebd649SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 57158ebd649SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 57258ebd649SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 57358ebd649SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 57458ebd649SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 57558ebd649SToby Isaac } 57697b6e6e8SMatthew G. Knepley ierr = PetscFree((*prob)->constants);CHKERRQ(ierr); 5772764a2aaSMatthew G. Knepley ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr); 5782764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5792764a2aaSMatthew G. Knepley } 5802764a2aaSMatthew G. Knepley 5812764a2aaSMatthew G. Knepley /*@ 5822764a2aaSMatthew G. Knepley PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType(). 5832764a2aaSMatthew G. Knepley 584d083f849SBarry Smith Collective 5852764a2aaSMatthew G. Knepley 5862764a2aaSMatthew G. Knepley Input Parameter: 5872764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object 5882764a2aaSMatthew G. Knepley 5892764a2aaSMatthew G. Knepley Output Parameter: 5902764a2aaSMatthew G. Knepley . prob - The PetscDS object 5912764a2aaSMatthew G. Knepley 5922764a2aaSMatthew G. Knepley Level: beginner 5932764a2aaSMatthew G. Knepley 5942764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC 5952764a2aaSMatthew G. Knepley @*/ 5962764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob) 5972764a2aaSMatthew G. Knepley { 5982764a2aaSMatthew G. Knepley PetscDS p; 5992764a2aaSMatthew G. Knepley PetscErrorCode ierr; 6002764a2aaSMatthew G. Knepley 6012764a2aaSMatthew G. Knepley PetscFunctionBegin; 6022764a2aaSMatthew G. Knepley PetscValidPointer(prob, 2); 6032764a2aaSMatthew G. Knepley *prob = NULL; 6042764a2aaSMatthew G. Knepley ierr = PetscDSInitializePackage();CHKERRQ(ierr); 6052764a2aaSMatthew G. Knepley 60673107ff1SLisandro Dalcin ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr); 6072764a2aaSMatthew G. Knepley 6082764a2aaSMatthew G. Knepley p->Nf = 0; 6092764a2aaSMatthew G. Knepley p->setup = PETSC_FALSE; 61097b6e6e8SMatthew G. Knepley p->numConstants = 0; 61197b6e6e8SMatthew G. Knepley p->constants = NULL; 612a859676bSMatthew G. Knepley p->dimEmbed = -1; 61355c1f793SMatthew G. Knepley p->useJacPre = PETSC_TRUE; 6142764a2aaSMatthew G. Knepley 6152764a2aaSMatthew G. Knepley *prob = p; 6162764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6172764a2aaSMatthew G. Knepley } 6182764a2aaSMatthew G. Knepley 619bc4ae4beSMatthew G. Knepley /*@ 620bc4ae4beSMatthew G. Knepley PetscDSGetNumFields - Returns the number of fields in the DS 621bc4ae4beSMatthew G. Knepley 622bc4ae4beSMatthew G. Knepley Not collective 623bc4ae4beSMatthew G. Knepley 624bc4ae4beSMatthew G. Knepley Input Parameter: 625bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 626bc4ae4beSMatthew G. Knepley 627bc4ae4beSMatthew G. Knepley Output Parameter: 628bc4ae4beSMatthew G. Knepley . Nf - The number of fields 629bc4ae4beSMatthew G. Knepley 630bc4ae4beSMatthew G. Knepley Level: beginner 631bc4ae4beSMatthew G. Knepley 632bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate() 633bc4ae4beSMatthew G. Knepley @*/ 6342764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) 6352764a2aaSMatthew G. Knepley { 6362764a2aaSMatthew G. Knepley PetscFunctionBegin; 6372764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6382764a2aaSMatthew G. Knepley PetscValidPointer(Nf, 2); 6392764a2aaSMatthew G. Knepley *Nf = prob->Nf; 6402764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6412764a2aaSMatthew G. Knepley } 6422764a2aaSMatthew G. Knepley 643bc4ae4beSMatthew G. Knepley /*@ 644a859676bSMatthew G. Knepley PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations 645bc4ae4beSMatthew G. Knepley 646bc4ae4beSMatthew G. Knepley Not collective 647bc4ae4beSMatthew G. Knepley 648bc4ae4beSMatthew G. Knepley Input Parameter: 649bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 650bc4ae4beSMatthew G. Knepley 651bc4ae4beSMatthew G. Knepley Output Parameter: 652bc4ae4beSMatthew G. Knepley . dim - The spatial dimension 653bc4ae4beSMatthew G. Knepley 654bc4ae4beSMatthew G. Knepley Level: beginner 655bc4ae4beSMatthew G. Knepley 656a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate() 657bc4ae4beSMatthew G. Knepley @*/ 6582764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) 6592764a2aaSMatthew G. Knepley { 6602764a2aaSMatthew G. Knepley PetscErrorCode ierr; 6612764a2aaSMatthew G. Knepley 6622764a2aaSMatthew G. Knepley PetscFunctionBegin; 6632764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6642764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 6652764a2aaSMatthew G. Knepley *dim = 0; 6669de99aefSMatthew G. Knepley if (prob->Nf) { 6679de99aefSMatthew G. Knepley PetscObject obj; 6689de99aefSMatthew G. Knepley PetscClassId id; 6699de99aefSMatthew G. Knepley 6709de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 671665f567fSMatthew G. Knepley if (obj) { 6729de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 6739de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);} 6749de99aefSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);} 6759de99aefSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 6769de99aefSMatthew G. Knepley } 677665f567fSMatthew G. Knepley } 6782764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6792764a2aaSMatthew G. Knepley } 6802764a2aaSMatthew G. Knepley 681bc4ae4beSMatthew G. Knepley /*@ 682a859676bSMatthew G. Knepley PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 683a859676bSMatthew G. Knepley 684a859676bSMatthew G. Knepley Not collective 685a859676bSMatthew G. Knepley 686a859676bSMatthew G. Knepley Input Parameter: 687a859676bSMatthew G. Knepley . prob - The PetscDS object 688a859676bSMatthew G. Knepley 689a859676bSMatthew G. Knepley Output Parameter: 690a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension 691a859676bSMatthew G. Knepley 692a859676bSMatthew G. Knepley Level: beginner 693a859676bSMatthew G. Knepley 694a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 695a859676bSMatthew G. Knepley @*/ 696a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed) 697a859676bSMatthew G. Knepley { 698a859676bSMatthew G. Knepley PetscFunctionBegin; 699a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 700a859676bSMatthew G. Knepley PetscValidPointer(dimEmbed, 2); 701a859676bSMatthew G. Knepley if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS"); 702a859676bSMatthew G. Knepley *dimEmbed = prob->dimEmbed; 703a859676bSMatthew G. Knepley PetscFunctionReturn(0); 704a859676bSMatthew G. Knepley } 705a859676bSMatthew G. Knepley 706a859676bSMatthew G. Knepley /*@ 707a859676bSMatthew G. Knepley PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 708a859676bSMatthew G. Knepley 709d083f849SBarry Smith Logically collective on prob 710a859676bSMatthew G. Knepley 711a859676bSMatthew G. Knepley Input Parameters: 712a859676bSMatthew G. Knepley + prob - The PetscDS object 713a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension 714a859676bSMatthew G. Knepley 715a859676bSMatthew G. Knepley Level: beginner 716a859676bSMatthew G. Knepley 717a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 718a859676bSMatthew G. Knepley @*/ 719a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed) 720a859676bSMatthew G. Knepley { 721a859676bSMatthew G. Knepley PetscFunctionBegin; 722a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 723ebfe4b0dSMatthew G. Knepley if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed); 724a859676bSMatthew G. Knepley prob->dimEmbed = dimEmbed; 725a859676bSMatthew G. Knepley PetscFunctionReturn(0); 726a859676bSMatthew G. Knepley } 727a859676bSMatthew G. Knepley 728a859676bSMatthew G. Knepley /*@ 7298edf6225SMatthew G. Knepley PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell 7308edf6225SMatthew G. Knepley 7318edf6225SMatthew G. Knepley Not collective 7328edf6225SMatthew G. Knepley 7338edf6225SMatthew G. Knepley Input Parameter: 7348edf6225SMatthew G. Knepley . prob - The PetscDS object 7358edf6225SMatthew G. Knepley 7368edf6225SMatthew G. Knepley Output Parameter: 7378edf6225SMatthew G. Knepley . isHybrid - The flag 7388edf6225SMatthew G. Knepley 7398edf6225SMatthew G. Knepley Level: developer 7408edf6225SMatthew G. Knepley 7418edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate() 7428edf6225SMatthew G. Knepley @*/ 7438edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid) 7448edf6225SMatthew G. Knepley { 7458edf6225SMatthew G. Knepley PetscFunctionBegin; 7468edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7478edf6225SMatthew G. Knepley PetscValidPointer(isHybrid, 2); 7488edf6225SMatthew G. Knepley *isHybrid = prob->isHybrid; 7498edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7508edf6225SMatthew G. Knepley } 7518edf6225SMatthew G. Knepley 7528edf6225SMatthew G. Knepley /*@ 7538edf6225SMatthew G. Knepley PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell 7548edf6225SMatthew G. Knepley 7558edf6225SMatthew G. Knepley Not collective 7568edf6225SMatthew G. Knepley 7578edf6225SMatthew G. Knepley Input Parameters: 7588edf6225SMatthew G. Knepley + prob - The PetscDS object 7598edf6225SMatthew G. Knepley - isHybrid - The flag 7608edf6225SMatthew G. Knepley 7618edf6225SMatthew G. Knepley Level: developer 7628edf6225SMatthew G. Knepley 7638edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate() 7648edf6225SMatthew G. Knepley @*/ 7658edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid) 7668edf6225SMatthew G. Knepley { 7678edf6225SMatthew G. Knepley PetscFunctionBegin; 7688edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7698edf6225SMatthew G. Knepley prob->isHybrid = isHybrid; 7708edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7718edf6225SMatthew G. Knepley } 7728edf6225SMatthew G. Knepley 7738edf6225SMatthew G. Knepley /*@ 774bc4ae4beSMatthew G. Knepley PetscDSGetTotalDimension - Returns the total size of the approximation space for 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 problem dimension 783bc4ae4beSMatthew G. Knepley 784bc4ae4beSMatthew G. Knepley Level: beginner 785bc4ae4beSMatthew G. Knepley 786bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 787bc4ae4beSMatthew G. Knepley @*/ 7882764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) 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(dim, 2); 7962764a2aaSMatthew G. Knepley *dim = prob->totDim; 7972764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 7982764a2aaSMatthew G. Knepley } 7992764a2aaSMatthew G. Knepley 800bc4ae4beSMatthew G. Knepley /*@ 801bc4ae4beSMatthew G. Knepley PetscDSGetTotalComponents - Returns the total number of components in this system 802bc4ae4beSMatthew G. Knepley 803bc4ae4beSMatthew G. Knepley Not collective 804bc4ae4beSMatthew G. Knepley 805bc4ae4beSMatthew G. Knepley Input Parameter: 806bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 807bc4ae4beSMatthew G. Knepley 808bc4ae4beSMatthew G. Knepley Output Parameter: 809bc4ae4beSMatthew G. Knepley . dim - The total number of components 810bc4ae4beSMatthew G. Knepley 811bc4ae4beSMatthew G. Knepley Level: beginner 812bc4ae4beSMatthew G. Knepley 813bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 814bc4ae4beSMatthew G. Knepley @*/ 8152764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) 8162764a2aaSMatthew G. Knepley { 8172764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8182764a2aaSMatthew G. Knepley 8192764a2aaSMatthew G. Knepley PetscFunctionBegin; 8202764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8212764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 8222764a2aaSMatthew G. Knepley PetscValidPointer(Nc, 2); 8232764a2aaSMatthew G. Knepley *Nc = prob->totComp; 8242764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8252764a2aaSMatthew G. Knepley } 8262764a2aaSMatthew G. Knepley 827bc4ae4beSMatthew G. Knepley /*@ 828bc4ae4beSMatthew G. Knepley PetscDSGetDiscretization - Returns the discretization object for the given field 829bc4ae4beSMatthew G. Knepley 830bc4ae4beSMatthew G. Knepley Not collective 831bc4ae4beSMatthew G. Knepley 832bc4ae4beSMatthew G. Knepley Input Parameters: 833bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 834bc4ae4beSMatthew G. Knepley - f - The field number 835bc4ae4beSMatthew G. Knepley 836bc4ae4beSMatthew G. Knepley Output Parameter: 837bc4ae4beSMatthew G. Knepley . disc - The discretization object 838bc4ae4beSMatthew G. Knepley 839bc4ae4beSMatthew G. Knepley Level: beginner 840bc4ae4beSMatthew G. Knepley 841f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 842bc4ae4beSMatthew G. Knepley @*/ 8432764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 8442764a2aaSMatthew G. Knepley { 8452764a2aaSMatthew G. Knepley PetscFunctionBegin; 8462764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8472764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 8482764a2aaSMatthew 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); 8492764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 8502764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8512764a2aaSMatthew G. Knepley } 8522764a2aaSMatthew G. Knepley 853bc4ae4beSMatthew G. Knepley /*@ 854bc4ae4beSMatthew G. Knepley PetscDSSetDiscretization - Sets the discretization object for the given field 855bc4ae4beSMatthew G. Knepley 856bc4ae4beSMatthew G. Knepley Not collective 857bc4ae4beSMatthew G. Knepley 858bc4ae4beSMatthew G. Knepley Input Parameters: 859bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 860bc4ae4beSMatthew G. Knepley . f - The field number 861bc4ae4beSMatthew G. Knepley - disc - The discretization object 862bc4ae4beSMatthew G. Knepley 863bc4ae4beSMatthew G. Knepley Level: beginner 864bc4ae4beSMatthew G. Knepley 865bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 866bc4ae4beSMatthew G. Knepley @*/ 8672764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 8682764a2aaSMatthew G. Knepley { 8692764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8702764a2aaSMatthew G. Knepley 8712764a2aaSMatthew G. Knepley PetscFunctionBegin; 8722764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 873665f567fSMatthew G. Knepley if (disc) PetscValidPointer(disc, 3); 8742764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 8752764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 876c10f2116SMatthew G. Knepley ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr); 8772764a2aaSMatthew G. Knepley prob->disc[f] = disc; 8782764a2aaSMatthew G. Knepley ierr = PetscObjectReference(disc);CHKERRQ(ierr); 879665f567fSMatthew G. Knepley if (disc) { 880249df284SMatthew G. Knepley PetscClassId id; 881249df284SMatthew G. Knepley 882249df284SMatthew G. Knepley ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr); 8831cf84007SMatthew G. Knepley if (id == PETSCFE_CLASSID) { 8841cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr); 8851cf84007SMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 8861cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr); 887a6cbbb48SMatthew G. Knepley } 888249df284SMatthew G. Knepley } 8892764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8902764a2aaSMatthew G. Knepley } 8912764a2aaSMatthew G. Knepley 892bc4ae4beSMatthew G. Knepley /*@ 893bc4ae4beSMatthew G. Knepley PetscDSAddDiscretization - Adds a discretization object 894bc4ae4beSMatthew G. Knepley 895bc4ae4beSMatthew G. Knepley Not collective 896bc4ae4beSMatthew G. Knepley 897bc4ae4beSMatthew G. Knepley Input Parameters: 898bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 899bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object 900bc4ae4beSMatthew G. Knepley 901bc4ae4beSMatthew G. Knepley Level: beginner 902bc4ae4beSMatthew G. Knepley 903bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 904bc4ae4beSMatthew G. Knepley @*/ 9052764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) 9062764a2aaSMatthew G. Knepley { 9072764a2aaSMatthew G. Knepley PetscErrorCode ierr; 9082764a2aaSMatthew G. Knepley 9092764a2aaSMatthew G. Knepley PetscFunctionBegin; 9102764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr); 9112764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9122764a2aaSMatthew G. Knepley } 9132764a2aaSMatthew G. Knepley 914249df284SMatthew G. Knepley /*@ 915*083401c6SMatthew G. Knepley PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS 916*083401c6SMatthew G. Knepley 917*083401c6SMatthew G. Knepley Not collective 918*083401c6SMatthew G. Knepley 919*083401c6SMatthew G. Knepley Input Parameter: 920*083401c6SMatthew G. Knepley . prob - The PetscDS object 921*083401c6SMatthew G. Knepley 922*083401c6SMatthew G. Knepley Output Parameter: 923*083401c6SMatthew G. Knepley . q - The quadrature object 924*083401c6SMatthew G. Knepley 925*083401c6SMatthew G. Knepley Level: intermediate 926*083401c6SMatthew G. Knepley 927*083401c6SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 928*083401c6SMatthew G. Knepley @*/ 929*083401c6SMatthew G. Knepley PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q) 930*083401c6SMatthew G. Knepley { 931*083401c6SMatthew G. Knepley PetscObject obj; 932*083401c6SMatthew G. Knepley PetscClassId id; 933*083401c6SMatthew G. Knepley PetscErrorCode ierr; 934*083401c6SMatthew G. Knepley 935*083401c6SMatthew G. Knepley PetscFunctionBegin; 936*083401c6SMatthew G. Knepley *q = NULL; 937*083401c6SMatthew G. Knepley if (!prob->Nf) PetscFunctionReturn(0); 938*083401c6SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 939*083401c6SMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 940*083401c6SMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetQuadrature((PetscFE) obj, q);CHKERRQ(ierr);} 941*083401c6SMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetQuadrature((PetscFV) obj, q);CHKERRQ(ierr);} 942*083401c6SMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 943*083401c6SMatthew G. Knepley PetscFunctionReturn(0); 944*083401c6SMatthew G. Knepley } 945*083401c6SMatthew G. Knepley 946*083401c6SMatthew G. Knepley /*@ 947249df284SMatthew G. Knepley PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX 948249df284SMatthew G. Knepley 949249df284SMatthew G. Knepley Not collective 950249df284SMatthew G. Knepley 951249df284SMatthew G. Knepley Input Parameters: 952249df284SMatthew G. Knepley + prob - The PetscDS object 953249df284SMatthew G. Knepley - f - The field number 954249df284SMatthew G. Knepley 955249df284SMatthew G. Knepley Output Parameter: 956249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field 957249df284SMatthew G. Knepley 958249df284SMatthew G. Knepley Level: developer 959249df284SMatthew G. Knepley 960f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 961249df284SMatthew G. Knepley @*/ 962249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit) 963249df284SMatthew G. Knepley { 964249df284SMatthew G. Knepley PetscFunctionBegin; 965249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 966249df284SMatthew G. Knepley PetscValidPointer(implicit, 3); 967249df284SMatthew 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); 968249df284SMatthew G. Knepley *implicit = prob->implicit[f]; 969249df284SMatthew G. Knepley PetscFunctionReturn(0); 970249df284SMatthew G. Knepley } 971249df284SMatthew G. Knepley 972249df284SMatthew G. Knepley /*@ 973249df284SMatthew G. Knepley PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX 974249df284SMatthew G. Knepley 975249df284SMatthew G. Knepley Not collective 976249df284SMatthew G. Knepley 977249df284SMatthew G. Knepley Input Parameters: 978249df284SMatthew G. Knepley + prob - The PetscDS object 979249df284SMatthew G. Knepley . f - The field number 980249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field 981249df284SMatthew G. Knepley 982249df284SMatthew G. Knepley Level: developer 983249df284SMatthew G. Knepley 984f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 985249df284SMatthew G. Knepley @*/ 986249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit) 987249df284SMatthew G. Knepley { 988249df284SMatthew G. Knepley PetscFunctionBegin; 989249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 990249df284SMatthew 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); 991249df284SMatthew G. Knepley prob->implicit[f] = implicit; 992249df284SMatthew G. Knepley PetscFunctionReturn(0); 993249df284SMatthew G. Knepley } 994249df284SMatthew G. Knepley 9952764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f, 99630b9ff8bSMatthew G. Knepley void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 997194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 998194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 99997b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 10002764a2aaSMatthew G. Knepley { 10012764a2aaSMatthew G. Knepley PetscFunctionBegin; 10022764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 10032764a2aaSMatthew G. Knepley PetscValidPointer(obj, 2); 10042764a2aaSMatthew 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); 10052764a2aaSMatthew G. Knepley *obj = prob->obj[f]; 10062764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10072764a2aaSMatthew G. Knepley } 10082764a2aaSMatthew G. Knepley 10092764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f, 101030b9ff8bSMatthew G. Knepley void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1011194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1012194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 101397b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 10142764a2aaSMatthew G. Knepley { 10152764a2aaSMatthew G. Knepley PetscErrorCode ierr; 10162764a2aaSMatthew G. Knepley 10172764a2aaSMatthew G. Knepley PetscFunctionBegin; 10182764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1019de716cbcSToby Isaac if (obj) PetscValidFunction(obj, 2); 10202764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 10212764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 10222764a2aaSMatthew G. Knepley prob->obj[f] = obj; 10232764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10242764a2aaSMatthew G. Knepley } 10252764a2aaSMatthew G. Knepley 1026194d53e6SMatthew G. Knepley /*@C 1027194d53e6SMatthew G. Knepley PetscDSGetResidual - Get the pointwise residual function for a given test field 1028194d53e6SMatthew G. Knepley 1029194d53e6SMatthew G. Knepley Not collective 1030194d53e6SMatthew G. Knepley 1031194d53e6SMatthew G. Knepley Input Parameters: 1032194d53e6SMatthew G. Knepley + prob - The PetscDS 1033194d53e6SMatthew G. Knepley - f - The test field number 1034194d53e6SMatthew G. Knepley 1035194d53e6SMatthew G. Knepley Output Parameters: 1036194d53e6SMatthew G. Knepley + f0 - integrand for the test function term 1037194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1038194d53e6SMatthew G. Knepley 1039194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1040194d53e6SMatthew G. Knepley 1041194d53e6SMatthew 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) 1042194d53e6SMatthew G. Knepley 1043194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1044194d53e6SMatthew G. Knepley 104530b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1046194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1047194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 104830b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1049194d53e6SMatthew G. Knepley 1050194d53e6SMatthew G. Knepley + dim - the spatial dimension 1051194d53e6SMatthew G. Knepley . Nf - the number of fields 1052194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1053194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1054194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1055194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1056194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1057194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1058194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1059194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1060194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1061194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1062194d53e6SMatthew G. Knepley . t - current time 1063194d53e6SMatthew G. Knepley . x - coordinates of the current point 106497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 106597b6e6e8SMatthew G. Knepley . constants - constant parameters 1066194d53e6SMatthew G. Knepley - f0 - output values at the current point 1067194d53e6SMatthew G. Knepley 1068194d53e6SMatthew G. Knepley Level: intermediate 1069194d53e6SMatthew G. Knepley 1070194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual() 1071194d53e6SMatthew G. Knepley @*/ 10722764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f, 107330b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1074194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1075194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 107697b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 107730b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1078194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1079194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 108097b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 10812764a2aaSMatthew G. Knepley { 10822764a2aaSMatthew G. Knepley PetscFunctionBegin; 10832764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 10842764a2aaSMatthew 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); 10852764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];} 10862764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];} 10872764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10882764a2aaSMatthew G. Knepley } 10892764a2aaSMatthew G. Knepley 1090194d53e6SMatthew G. Knepley /*@C 1091194d53e6SMatthew G. Knepley PetscDSSetResidual - Set the pointwise residual function for a given test field 1092194d53e6SMatthew G. Knepley 1093194d53e6SMatthew G. Knepley Not collective 1094194d53e6SMatthew G. Knepley 1095194d53e6SMatthew G. Knepley Input Parameters: 1096194d53e6SMatthew G. Knepley + prob - The PetscDS 1097194d53e6SMatthew G. Knepley . f - The test field number 1098194d53e6SMatthew G. Knepley . f0 - integrand for the test function term 1099194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1100194d53e6SMatthew G. Knepley 1101194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1102194d53e6SMatthew G. Knepley 1103194d53e6SMatthew 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) 1104194d53e6SMatthew G. Knepley 1105194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1106194d53e6SMatthew G. Knepley 110730b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1108194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1109194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 111030b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1111194d53e6SMatthew G. Knepley 1112194d53e6SMatthew G. Knepley + dim - the spatial dimension 1113194d53e6SMatthew G. Knepley . Nf - the number of fields 1114194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1115194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1116194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1117194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1118194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1119194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1120194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1121194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1122194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1123194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1124194d53e6SMatthew G. Knepley . t - current time 1125194d53e6SMatthew G. Knepley . x - coordinates of the current point 112697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 112797b6e6e8SMatthew G. Knepley . constants - constant parameters 1128194d53e6SMatthew G. Knepley - f0 - output values at the current point 1129194d53e6SMatthew G. Knepley 1130194d53e6SMatthew G. Knepley Level: intermediate 1131194d53e6SMatthew G. Knepley 1132194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual() 1133194d53e6SMatthew G. Knepley @*/ 11342764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f, 113530b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1136194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1137194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 113897b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 113930b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1140194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1141194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 114297b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 11432764a2aaSMatthew G. Knepley { 11442764a2aaSMatthew G. Knepley PetscErrorCode ierr; 11452764a2aaSMatthew G. Knepley 11462764a2aaSMatthew G. Knepley PetscFunctionBegin; 11472764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1148f866a1d0SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1149f866a1d0SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 11502764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 11512764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 11522764a2aaSMatthew G. Knepley prob->f[f*2+0] = f0; 11532764a2aaSMatthew G. Knepley prob->f[f*2+1] = f1; 11542764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11552764a2aaSMatthew G. Knepley } 11562764a2aaSMatthew G. Knepley 11573e75805dSMatthew G. Knepley /*@C 11583e75805dSMatthew G. Knepley PetscDSHasJacobian - Signals that Jacobian functions have been set 11593e75805dSMatthew G. Knepley 11603e75805dSMatthew G. Knepley Not collective 11613e75805dSMatthew G. Knepley 11623e75805dSMatthew G. Knepley Input Parameter: 11633e75805dSMatthew G. Knepley . prob - The PetscDS 11643e75805dSMatthew G. Knepley 11653e75805dSMatthew G. Knepley Output Parameter: 11663e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set 11673e75805dSMatthew G. Knepley 11683e75805dSMatthew G. Knepley Level: intermediate 11693e75805dSMatthew G. Knepley 11703e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 11713e75805dSMatthew G. Knepley @*/ 11723e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac) 11733e75805dSMatthew G. Knepley { 11743e75805dSMatthew G. Knepley PetscInt f, g, h; 11753e75805dSMatthew G. Knepley 11763e75805dSMatthew G. Knepley PetscFunctionBegin; 11773e75805dSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 11783e75805dSMatthew G. Knepley *hasJac = PETSC_FALSE; 11793e75805dSMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 11803e75805dSMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 11813e75805dSMatthew G. Knepley for (h = 0; h < 4; ++h) { 11823e75805dSMatthew G. Knepley if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE; 11833e75805dSMatthew G. Knepley } 11843e75805dSMatthew G. Knepley } 11853e75805dSMatthew G. Knepley } 11863e75805dSMatthew G. Knepley PetscFunctionReturn(0); 11873e75805dSMatthew G. Knepley } 11883e75805dSMatthew G. Knepley 1189194d53e6SMatthew G. Knepley /*@C 1190194d53e6SMatthew G. Knepley PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field 1191194d53e6SMatthew G. Knepley 1192194d53e6SMatthew G. Knepley Not collective 1193194d53e6SMatthew G. Knepley 1194194d53e6SMatthew G. Knepley Input Parameters: 1195194d53e6SMatthew G. Knepley + prob - The PetscDS 1196194d53e6SMatthew G. Knepley . f - The test field number 1197194d53e6SMatthew G. Knepley - g - The field number 1198194d53e6SMatthew G. Knepley 1199194d53e6SMatthew G. Knepley Output Parameters: 1200194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1201194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1202194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1203194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1204194d53e6SMatthew G. Knepley 1205194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1206194d53e6SMatthew G. Knepley 1207194d53e6SMatthew 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 1208194d53e6SMatthew G. Knepley 1209194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1210194d53e6SMatthew G. Knepley 121130b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1212194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1213194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 121430b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1215194d53e6SMatthew G. Knepley 1216194d53e6SMatthew G. Knepley + dim - the spatial dimension 1217194d53e6SMatthew G. Knepley . Nf - the number of fields 1218194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1219194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1220194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1221194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1222194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1223194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1224194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1225194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1226194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1227194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1228194d53e6SMatthew G. Knepley . t - current time 12292aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1230194d53e6SMatthew G. Knepley . x - coordinates of the current point 123197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 123297b6e6e8SMatthew G. Knepley . constants - constant parameters 1233194d53e6SMatthew G. Knepley - g0 - output values at the current point 1234194d53e6SMatthew G. Knepley 1235194d53e6SMatthew G. Knepley Level: intermediate 1236194d53e6SMatthew G. Knepley 1237194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1238194d53e6SMatthew G. Knepley @*/ 12392764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g, 124030b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1241194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1242194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 124397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 124430b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1245194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1246194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 124797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 124830b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1249194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1250194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 125197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 125230b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1253194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1254194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 125597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 12562764a2aaSMatthew G. Knepley { 12572764a2aaSMatthew G. Knepley PetscFunctionBegin; 12582764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 12592764a2aaSMatthew 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); 12602764a2aaSMatthew 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); 12612764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];} 12622764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];} 12632764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];} 12642764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];} 12652764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 12662764a2aaSMatthew G. Knepley } 12672764a2aaSMatthew G. Knepley 1268194d53e6SMatthew G. Knepley /*@C 1269194d53e6SMatthew G. Knepley PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields 1270194d53e6SMatthew G. Knepley 1271194d53e6SMatthew G. Knepley Not collective 1272194d53e6SMatthew G. Knepley 1273194d53e6SMatthew G. Knepley Input Parameters: 1274194d53e6SMatthew G. Knepley + prob - The PetscDS 1275194d53e6SMatthew G. Knepley . f - The test field number 1276194d53e6SMatthew G. Knepley . g - The field number 1277194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1278194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1279194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1280194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1281194d53e6SMatthew G. Knepley 1282194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1283194d53e6SMatthew G. Knepley 1284194d53e6SMatthew 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 1285194d53e6SMatthew G. Knepley 1286194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1287194d53e6SMatthew G. Knepley 128830b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1289194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1290194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 129130b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1292194d53e6SMatthew G. Knepley 1293194d53e6SMatthew G. Knepley + dim - the spatial dimension 1294194d53e6SMatthew G. Knepley . Nf - the number of fields 1295194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1296194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1297194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1298194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1299194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1300194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1301194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1302194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1303194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1304194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1305194d53e6SMatthew G. Knepley . t - current time 13062aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1307194d53e6SMatthew G. Knepley . x - coordinates of the current point 130897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 130997b6e6e8SMatthew G. Knepley . constants - constant parameters 1310194d53e6SMatthew G. Knepley - g0 - output values at the current point 1311194d53e6SMatthew G. Knepley 1312194d53e6SMatthew G. Knepley Level: intermediate 1313194d53e6SMatthew G. Knepley 1314194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1315194d53e6SMatthew G. Knepley @*/ 13162764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g, 131730b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1318194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1319194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 132097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 132130b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1322194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1323194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 132497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 132530b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1326194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1327194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 132897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 132930b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1330194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1331194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 133297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 13332764a2aaSMatthew G. Knepley { 13342764a2aaSMatthew G. Knepley PetscErrorCode ierr; 13352764a2aaSMatthew G. Knepley 13362764a2aaSMatthew G. Knepley PetscFunctionBegin; 13372764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 13382764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 13392764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 13402764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 13412764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 13422764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 13432764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 13442764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 13452764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+0] = g0; 13462764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+1] = g1; 13472764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+2] = g2; 13482764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+3] = g3; 13492764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 13502764a2aaSMatthew G. Knepley } 13512764a2aaSMatthew G. Knepley 1352475e0ac9SMatthew G. Knepley /*@C 135355c1f793SMatthew G. Knepley PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner 135455c1f793SMatthew G. Knepley 135555c1f793SMatthew G. Knepley Not collective 135655c1f793SMatthew G. Knepley 135755c1f793SMatthew G. Knepley Input Parameters: 135855c1f793SMatthew G. Knepley + prob - The PetscDS 135955c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner 136055c1f793SMatthew G. Knepley 136155c1f793SMatthew G. Knepley Level: intermediate 136255c1f793SMatthew G. Knepley 136355c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 136455c1f793SMatthew G. Knepley @*/ 136555c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre) 136655c1f793SMatthew G. Knepley { 136755c1f793SMatthew G. Knepley PetscFunctionBegin; 136855c1f793SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 136955c1f793SMatthew G. Knepley prob->useJacPre = useJacPre; 137055c1f793SMatthew G. Knepley PetscFunctionReturn(0); 137155c1f793SMatthew G. Knepley } 137255c1f793SMatthew G. Knepley 137355c1f793SMatthew G. Knepley /*@C 1374475e0ac9SMatthew G. Knepley PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set 1375475e0ac9SMatthew G. Knepley 1376475e0ac9SMatthew G. Knepley Not collective 1377475e0ac9SMatthew G. Knepley 1378475e0ac9SMatthew G. Knepley Input Parameter: 1379475e0ac9SMatthew G. Knepley . prob - The PetscDS 1380475e0ac9SMatthew G. Knepley 1381475e0ac9SMatthew G. Knepley Output Parameter: 1382475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set 1383475e0ac9SMatthew G. Knepley 1384475e0ac9SMatthew G. Knepley Level: intermediate 1385475e0ac9SMatthew G. Knepley 1386475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1387475e0ac9SMatthew G. Knepley @*/ 1388475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre) 1389475e0ac9SMatthew G. Knepley { 1390475e0ac9SMatthew G. Knepley PetscInt f, g, h; 1391475e0ac9SMatthew G. Knepley 1392475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1393475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1394475e0ac9SMatthew G. Knepley *hasJacPre = PETSC_FALSE; 139555c1f793SMatthew G. Knepley if (!prob->useJacPre) PetscFunctionReturn(0); 1396475e0ac9SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1397475e0ac9SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1398475e0ac9SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1399475e0ac9SMatthew G. Knepley if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE; 1400475e0ac9SMatthew G. Knepley } 1401475e0ac9SMatthew G. Knepley } 1402475e0ac9SMatthew G. Knepley } 1403475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1404475e0ac9SMatthew G. Knepley } 1405475e0ac9SMatthew G. Knepley 1406475e0ac9SMatthew G. Knepley /*@C 1407475e0ac9SMatthew 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. 1408475e0ac9SMatthew G. Knepley 1409475e0ac9SMatthew G. Knepley Not collective 1410475e0ac9SMatthew G. Knepley 1411475e0ac9SMatthew G. Knepley Input Parameters: 1412475e0ac9SMatthew G. Knepley + prob - The PetscDS 1413475e0ac9SMatthew G. Knepley . f - The test field number 1414475e0ac9SMatthew G. Knepley - g - The field number 1415475e0ac9SMatthew G. Knepley 1416475e0ac9SMatthew G. Knepley Output Parameters: 1417475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term 1418475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1419475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1420475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1421475e0ac9SMatthew G. Knepley 1422475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1423475e0ac9SMatthew G. Knepley 1424475e0ac9SMatthew 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 1425475e0ac9SMatthew G. Knepley 1426475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1427475e0ac9SMatthew G. Knepley 1428475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1429475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1430475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1431475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1432475e0ac9SMatthew G. Knepley 1433475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1434475e0ac9SMatthew G. Knepley . Nf - the number of fields 1435475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1436475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1437475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1438475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1439475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1440475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1441475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1442475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1443475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1444475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1445475e0ac9SMatthew G. Knepley . t - current time 1446475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1447475e0ac9SMatthew G. Knepley . x - coordinates of the current point 144897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 144997b6e6e8SMatthew G. Knepley . constants - constant parameters 1450475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1451475e0ac9SMatthew G. Knepley 1452475e0ac9SMatthew G. Knepley Level: intermediate 1453475e0ac9SMatthew G. Knepley 1454475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1455475e0ac9SMatthew G. Knepley @*/ 1456475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1457475e0ac9SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1458475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1459475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 146097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1461475e0ac9SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1462475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1463475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 146497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1465475e0ac9SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1466475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1467475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 146897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1469475e0ac9SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1470475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1471475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 147297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1473475e0ac9SMatthew G. Knepley { 1474475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1475475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1476475e0ac9SMatthew 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); 1477475e0ac9SMatthew 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); 1478475e0ac9SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];} 1479475e0ac9SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];} 1480475e0ac9SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];} 1481475e0ac9SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];} 1482475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1483475e0ac9SMatthew G. Knepley } 1484475e0ac9SMatthew G. Knepley 1485475e0ac9SMatthew G. Knepley /*@C 1486475e0ac9SMatthew 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. 1487475e0ac9SMatthew G. Knepley 1488475e0ac9SMatthew G. Knepley Not collective 1489475e0ac9SMatthew G. Knepley 1490475e0ac9SMatthew G. Knepley Input Parameters: 1491475e0ac9SMatthew G. Knepley + prob - The PetscDS 1492475e0ac9SMatthew G. Knepley . f - The test field number 1493475e0ac9SMatthew G. Knepley . g - The field number 1494475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term 1495475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1496475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1497475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1498475e0ac9SMatthew G. Knepley 1499475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1500475e0ac9SMatthew G. Knepley 1501475e0ac9SMatthew 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 1502475e0ac9SMatthew G. Knepley 1503475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1504475e0ac9SMatthew G. Knepley 1505475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1506475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1507475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1508475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1509475e0ac9SMatthew G. Knepley 1510475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1511475e0ac9SMatthew G. Knepley . Nf - the number of fields 1512475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1513475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1514475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1515475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1516475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1517475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1518475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1519475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1520475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1521475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1522475e0ac9SMatthew G. Knepley . t - current time 1523475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1524475e0ac9SMatthew G. Knepley . x - coordinates of the current point 152597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 152697b6e6e8SMatthew G. Knepley . constants - constant parameters 1527475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1528475e0ac9SMatthew G. Knepley 1529475e0ac9SMatthew G. Knepley Level: intermediate 1530475e0ac9SMatthew G. Knepley 1531475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian() 1532475e0ac9SMatthew G. Knepley @*/ 1533475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1534475e0ac9SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1535475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1536475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 153797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1538475e0ac9SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1539475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1540475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 154197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1542475e0ac9SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1543475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1544475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 154597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1546475e0ac9SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1547475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1548475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 154997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1550475e0ac9SMatthew G. Knepley { 1551475e0ac9SMatthew G. Knepley PetscErrorCode ierr; 1552475e0ac9SMatthew G. Knepley 1553475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1554475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1555475e0ac9SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1556475e0ac9SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1557475e0ac9SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1558475e0ac9SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1559475e0ac9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1560475e0ac9SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1561475e0ac9SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1562475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+0] = g0; 1563475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+1] = g1; 1564475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+2] = g2; 1565475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+3] = g3; 1566475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1567475e0ac9SMatthew G. Knepley } 1568475e0ac9SMatthew G. Knepley 1569b7e05686SMatthew G. Knepley /*@C 1570b7e05686SMatthew G. Knepley PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set 1571b7e05686SMatthew G. Knepley 1572b7e05686SMatthew G. Knepley Not collective 1573b7e05686SMatthew G. Knepley 1574b7e05686SMatthew G. Knepley Input Parameter: 1575b7e05686SMatthew G. Knepley . prob - The PetscDS 1576b7e05686SMatthew G. Knepley 1577b7e05686SMatthew G. Knepley Output Parameter: 1578b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set 1579b7e05686SMatthew G. Knepley 1580b7e05686SMatthew G. Knepley Level: intermediate 1581b7e05686SMatthew G. Knepley 1582b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian() 1583b7e05686SMatthew G. Knepley @*/ 1584b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac) 1585b7e05686SMatthew G. Knepley { 1586b7e05686SMatthew G. Knepley PetscInt f, g, h; 1587b7e05686SMatthew G. Knepley 1588b7e05686SMatthew G. Knepley PetscFunctionBegin; 1589b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1590b7e05686SMatthew G. Knepley *hasDynJac = PETSC_FALSE; 1591b7e05686SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1592b7e05686SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1593b7e05686SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1594b7e05686SMatthew G. Knepley if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE; 1595b7e05686SMatthew G. Knepley } 1596b7e05686SMatthew G. Knepley } 1597b7e05686SMatthew G. Knepley } 1598b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1599b7e05686SMatthew G. Knepley } 1600b7e05686SMatthew G. Knepley 1601b7e05686SMatthew G. Knepley /*@C 1602b7e05686SMatthew G. Knepley PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field 1603b7e05686SMatthew G. Knepley 1604b7e05686SMatthew G. Knepley Not collective 1605b7e05686SMatthew G. Knepley 1606b7e05686SMatthew G. Knepley Input Parameters: 1607b7e05686SMatthew G. Knepley + prob - The PetscDS 1608b7e05686SMatthew G. Knepley . f - The test field number 1609b7e05686SMatthew G. Knepley - g - The field number 1610b7e05686SMatthew G. Knepley 1611b7e05686SMatthew G. Knepley Output Parameters: 1612b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term 1613b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1614b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1615b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1616b7e05686SMatthew G. Knepley 1617b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1618b7e05686SMatthew G. Knepley 1619b7e05686SMatthew 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 1620b7e05686SMatthew G. Knepley 1621b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1622b7e05686SMatthew G. Knepley 1623b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1624b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1625b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1626b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1627b7e05686SMatthew G. Knepley 1628b7e05686SMatthew G. Knepley + dim - the spatial dimension 1629b7e05686SMatthew G. Knepley . Nf - the number of fields 1630b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1631b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1632b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1633b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1634b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1635b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1636b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1637b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1638b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1639b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1640b7e05686SMatthew G. Knepley . t - current time 1641b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1642b7e05686SMatthew G. Knepley . x - coordinates of the current point 164397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 164497b6e6e8SMatthew G. Knepley . constants - constant parameters 1645b7e05686SMatthew G. Knepley - g0 - output values at the current point 1646b7e05686SMatthew G. Knepley 1647b7e05686SMatthew G. Knepley Level: intermediate 1648b7e05686SMatthew G. Knepley 1649b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1650b7e05686SMatthew G. Knepley @*/ 1651b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1652b7e05686SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1653b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1654b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 165597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1656b7e05686SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1657b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1658b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 165997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1660b7e05686SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1661b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1662b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 166397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1664b7e05686SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1665b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1666b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 166797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1668b7e05686SMatthew G. Knepley { 1669b7e05686SMatthew G. Knepley PetscFunctionBegin; 1670b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1671b7e05686SMatthew 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); 1672b7e05686SMatthew 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); 1673b7e05686SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];} 1674b7e05686SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];} 1675b7e05686SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];} 1676b7e05686SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];} 1677b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1678b7e05686SMatthew G. Knepley } 1679b7e05686SMatthew G. Knepley 1680b7e05686SMatthew G. Knepley /*@C 1681b7e05686SMatthew G. Knepley PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields 1682b7e05686SMatthew G. Knepley 1683b7e05686SMatthew G. Knepley Not collective 1684b7e05686SMatthew G. Knepley 1685b7e05686SMatthew G. Knepley Input Parameters: 1686b7e05686SMatthew G. Knepley + prob - The PetscDS 1687b7e05686SMatthew G. Knepley . f - The test field number 1688b7e05686SMatthew G. Knepley . g - The field number 1689b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term 1690b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1691b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1692b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1693b7e05686SMatthew G. Knepley 1694b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1695b7e05686SMatthew G. Knepley 1696b7e05686SMatthew 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 1697b7e05686SMatthew G. Knepley 1698b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1699b7e05686SMatthew G. Knepley 1700b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1701b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1702b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1703b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1704b7e05686SMatthew G. Knepley 1705b7e05686SMatthew G. Knepley + dim - the spatial dimension 1706b7e05686SMatthew G. Knepley . Nf - the number of fields 1707b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1708b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1709b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1710b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1711b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1712b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1713b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1714b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1715b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1716b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1717b7e05686SMatthew G. Knepley . t - current time 1718b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1719b7e05686SMatthew G. Knepley . x - coordinates of the current point 172097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 172197b6e6e8SMatthew G. Knepley . constants - constant parameters 1722b7e05686SMatthew G. Knepley - g0 - output values at the current point 1723b7e05686SMatthew G. Knepley 1724b7e05686SMatthew G. Knepley Level: intermediate 1725b7e05686SMatthew G. Knepley 1726b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1727b7e05686SMatthew G. Knepley @*/ 1728b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1729b7e05686SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1730b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1731b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 173297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1733b7e05686SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1734b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1735b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 173697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1737b7e05686SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1738b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1739b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 174097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1741b7e05686SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1742b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1743b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 174497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1745b7e05686SMatthew G. Knepley { 1746b7e05686SMatthew G. Knepley PetscErrorCode ierr; 1747b7e05686SMatthew G. Knepley 1748b7e05686SMatthew G. Knepley PetscFunctionBegin; 1749b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1750b7e05686SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1751b7e05686SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1752b7e05686SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1753b7e05686SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1754b7e05686SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1755b7e05686SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1756b7e05686SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1757b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+0] = g0; 1758b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+1] = g1; 1759b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+2] = g2; 1760b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+3] = g3; 1761b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1762b7e05686SMatthew G. Knepley } 1763b7e05686SMatthew G. Knepley 17640c2f2876SMatthew G. Knepley /*@C 17650c2f2876SMatthew G. Knepley PetscDSGetRiemannSolver - Returns the Riemann solver for the given field 17660c2f2876SMatthew G. Knepley 17670c2f2876SMatthew G. Knepley Not collective 17680c2f2876SMatthew G. Knepley 17690c2f2876SMatthew G. Knepley Input Arguments: 17700c2f2876SMatthew G. Knepley + prob - The PetscDS object 17710c2f2876SMatthew G. Knepley - f - The field number 17720c2f2876SMatthew G. Knepley 17730c2f2876SMatthew G. Knepley Output Argument: 17740c2f2876SMatthew G. Knepley . r - Riemann solver 17750c2f2876SMatthew G. Knepley 17760c2f2876SMatthew G. Knepley Calling sequence for r: 17770c2f2876SMatthew G. Knepley 17785db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 17790c2f2876SMatthew G. Knepley 17805db36cf9SMatthew G. Knepley + dim - The spatial dimension 17815db36cf9SMatthew G. Knepley . Nf - The number of fields 17825db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 17830c2f2876SMatthew G. Knepley . n - The normal vector to the interface 17840c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 17850c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 17860c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 178797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 178897b6e6e8SMatthew G. Knepley . constants - constant parameters 17890c2f2876SMatthew G. Knepley - ctx - optional user context 17900c2f2876SMatthew G. Knepley 17910c2f2876SMatthew G. Knepley Level: intermediate 17920c2f2876SMatthew G. Knepley 17930c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver() 17940c2f2876SMatthew G. Knepley @*/ 17950c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f, 179697b6e6e8SMatthew 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)) 17970c2f2876SMatthew G. Knepley { 17980c2f2876SMatthew G. Knepley PetscFunctionBegin; 17990c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 18000c2f2876SMatthew 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); 18010c2f2876SMatthew G. Knepley PetscValidPointer(r, 3); 18020c2f2876SMatthew G. Knepley *r = prob->r[f]; 18030c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18040c2f2876SMatthew G. Knepley } 18050c2f2876SMatthew G. Knepley 18060c2f2876SMatthew G. Knepley /*@C 18070c2f2876SMatthew G. Knepley PetscDSSetRiemannSolver - Sets the Riemann solver for the given field 18080c2f2876SMatthew G. Knepley 18090c2f2876SMatthew G. Knepley Not collective 18100c2f2876SMatthew G. Knepley 18110c2f2876SMatthew G. Knepley Input Arguments: 18120c2f2876SMatthew G. Knepley + prob - The PetscDS object 18130c2f2876SMatthew G. Knepley . f - The field number 18140c2f2876SMatthew G. Knepley - r - Riemann solver 18150c2f2876SMatthew G. Knepley 18160c2f2876SMatthew G. Knepley Calling sequence for r: 18170c2f2876SMatthew G. Knepley 18185db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 18190c2f2876SMatthew G. Knepley 18205db36cf9SMatthew G. Knepley + dim - The spatial dimension 18215db36cf9SMatthew G. Knepley . Nf - The number of fields 18225db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 18230c2f2876SMatthew G. Knepley . n - The normal vector to the interface 18240c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 18250c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 18260c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 182797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 182897b6e6e8SMatthew G. Knepley . constants - constant parameters 18290c2f2876SMatthew G. Knepley - ctx - optional user context 18300c2f2876SMatthew G. Knepley 18310c2f2876SMatthew G. Knepley Level: intermediate 18320c2f2876SMatthew G. Knepley 18330c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver() 18340c2f2876SMatthew G. Knepley @*/ 18350c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f, 183697b6e6e8SMatthew 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)) 18370c2f2876SMatthew G. Knepley { 18380c2f2876SMatthew G. Knepley PetscErrorCode ierr; 18390c2f2876SMatthew G. Knepley 18400c2f2876SMatthew G. Knepley PetscFunctionBegin; 18410c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1842de716cbcSToby Isaac if (r) PetscValidFunction(r, 3); 18430c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 18440c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 18450c2f2876SMatthew G. Knepley prob->r[f] = r; 18460c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18470c2f2876SMatthew G. Knepley } 18480c2f2876SMatthew G. Knepley 184932d2bbc9SMatthew G. Knepley /*@C 185032d2bbc9SMatthew G. Knepley PetscDSGetUpdate - Get the pointwise update function for a given field 185132d2bbc9SMatthew G. Knepley 185232d2bbc9SMatthew G. Knepley Not collective 185332d2bbc9SMatthew G. Knepley 185432d2bbc9SMatthew G. Knepley Input Parameters: 185532d2bbc9SMatthew G. Knepley + prob - The PetscDS 185632d2bbc9SMatthew G. Knepley - f - The field number 185732d2bbc9SMatthew G. Knepley 185832d2bbc9SMatthew G. Knepley Output Parameters: 1859a2b725a8SWilliam Gropp . update - update function 186032d2bbc9SMatthew G. Knepley 186132d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 186232d2bbc9SMatthew G. Knepley 186332d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 186432d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 186532d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 186632d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 186732d2bbc9SMatthew G. Knepley 186832d2bbc9SMatthew G. Knepley + dim - the spatial dimension 186932d2bbc9SMatthew G. Knepley . Nf - the number of fields 187032d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 187132d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 187232d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 187332d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 187432d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 187532d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 187632d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 187732d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 187832d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 187932d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 188032d2bbc9SMatthew G. Knepley . t - current time 188132d2bbc9SMatthew G. Knepley . x - coordinates of the current point 188232d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point 188332d2bbc9SMatthew G. Knepley 188432d2bbc9SMatthew G. Knepley Level: intermediate 188532d2bbc9SMatthew G. Knepley 188632d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual() 188732d2bbc9SMatthew G. Knepley @*/ 188832d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f, 188932d2bbc9SMatthew G. Knepley void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 189032d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 189132d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 18923fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 189332d2bbc9SMatthew G. Knepley { 189432d2bbc9SMatthew G. Knepley PetscFunctionBegin; 189532d2bbc9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 189632d2bbc9SMatthew 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); 189732d2bbc9SMatthew G. Knepley if (update) {PetscValidPointer(update, 3); *update = prob->update[f];} 189832d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 189932d2bbc9SMatthew G. Knepley } 190032d2bbc9SMatthew G. Knepley 190132d2bbc9SMatthew G. Knepley /*@C 19023fa77dffSMatthew G. Knepley PetscDSSetUpdate - Set the pointwise update function for a given field 190332d2bbc9SMatthew G. Knepley 190432d2bbc9SMatthew G. Knepley Not collective 190532d2bbc9SMatthew G. Knepley 190632d2bbc9SMatthew G. Knepley Input Parameters: 190732d2bbc9SMatthew G. Knepley + prob - The PetscDS 190832d2bbc9SMatthew G. Knepley . f - The field number 190932d2bbc9SMatthew G. Knepley - update - update function 191032d2bbc9SMatthew G. Knepley 191132d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 191232d2bbc9SMatthew G. Knepley 191332d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 191432d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 191532d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 191632d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 191732d2bbc9SMatthew G. Knepley 191832d2bbc9SMatthew G. Knepley + dim - the spatial dimension 191932d2bbc9SMatthew G. Knepley . Nf - the number of fields 192032d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 192132d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 192232d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 192332d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 192432d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 192532d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 192632d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 192732d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 192832d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 192932d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 193032d2bbc9SMatthew G. Knepley . t - current time 193132d2bbc9SMatthew G. Knepley . x - coordinates of the current point 193232d2bbc9SMatthew G. Knepley - uNew - new field values at the current point 193332d2bbc9SMatthew G. Knepley 193432d2bbc9SMatthew G. Knepley Level: intermediate 193532d2bbc9SMatthew G. Knepley 193632d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual() 193732d2bbc9SMatthew G. Knepley @*/ 193832d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f, 193932d2bbc9SMatthew G. Knepley void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 194032d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 194132d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 19423fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 194332d2bbc9SMatthew G. Knepley { 194432d2bbc9SMatthew G. Knepley PetscErrorCode ierr; 194532d2bbc9SMatthew G. Knepley 194632d2bbc9SMatthew G. Knepley PetscFunctionBegin; 194732d2bbc9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 194832d2bbc9SMatthew G. Knepley if (update) PetscValidFunction(update, 3); 194932d2bbc9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 195032d2bbc9SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 195132d2bbc9SMatthew G. Knepley prob->update[f] = update; 195232d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 195332d2bbc9SMatthew G. Knepley } 195432d2bbc9SMatthew G. Knepley 19550c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx) 19560c2f2876SMatthew G. Knepley { 19570c2f2876SMatthew G. Knepley PetscFunctionBegin; 19580c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19590c2f2876SMatthew 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); 19600c2f2876SMatthew G. Knepley PetscValidPointer(ctx, 3); 19610c2f2876SMatthew G. Knepley *ctx = prob->ctx[f]; 19620c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19630c2f2876SMatthew G. Knepley } 19640c2f2876SMatthew G. Knepley 19650c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx) 19660c2f2876SMatthew G. Knepley { 19670c2f2876SMatthew G. Knepley PetscErrorCode ierr; 19680c2f2876SMatthew G. Knepley 19690c2f2876SMatthew G. Knepley PetscFunctionBegin; 19700c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19710c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 19720c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 19730c2f2876SMatthew G. Knepley prob->ctx[f] = ctx; 19740c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19750c2f2876SMatthew G. Knepley } 19760c2f2876SMatthew G. Knepley 1977194d53e6SMatthew G. Knepley /*@C 1978194d53e6SMatthew G. Knepley PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field 1979194d53e6SMatthew G. Knepley 1980194d53e6SMatthew G. Knepley Not collective 1981194d53e6SMatthew G. Knepley 1982194d53e6SMatthew G. Knepley Input Parameters: 1983194d53e6SMatthew G. Knepley + prob - The PetscDS 1984194d53e6SMatthew G. Knepley - f - The test field number 1985194d53e6SMatthew G. Knepley 1986194d53e6SMatthew G. Knepley Output Parameters: 1987194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term 1988194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 1989194d53e6SMatthew G. Knepley 1990194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1991194d53e6SMatthew G. Knepley 1992194d53e6SMatthew 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 1993194d53e6SMatthew G. Knepley 1994194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1995194d53e6SMatthew G. Knepley 199630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1997194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1998194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 199930b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2000194d53e6SMatthew G. Knepley 2001194d53e6SMatthew G. Knepley + dim - the spatial dimension 2002194d53e6SMatthew G. Knepley . Nf - the number of fields 2003194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2004194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2005194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2006194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2007194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2008194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2009194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2010194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2011194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2012194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2013194d53e6SMatthew G. Knepley . t - current time 2014194d53e6SMatthew G. Knepley . x - coordinates of the current point 2015194d53e6SMatthew G. Knepley . n - unit normal at the current point 201697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 201797b6e6e8SMatthew G. Knepley . constants - constant parameters 2018194d53e6SMatthew G. Knepley - f0 - output values at the current point 2019194d53e6SMatthew G. Knepley 2020194d53e6SMatthew G. Knepley Level: intermediate 2021194d53e6SMatthew G. Knepley 2022194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual() 2023194d53e6SMatthew G. Knepley @*/ 20242764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f, 202530b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2026194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2027194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 202897b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 202930b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2030194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2031194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 203297b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 20332764a2aaSMatthew G. Knepley { 20342764a2aaSMatthew G. Knepley PetscFunctionBegin; 20352764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 20362764a2aaSMatthew 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); 20372764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];} 20382764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];} 20392764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 20402764a2aaSMatthew G. Knepley } 20412764a2aaSMatthew G. Knepley 2042194d53e6SMatthew G. Knepley /*@C 2043194d53e6SMatthew G. Knepley PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field 2044194d53e6SMatthew G. Knepley 2045194d53e6SMatthew G. Knepley Not collective 2046194d53e6SMatthew G. Knepley 2047194d53e6SMatthew G. Knepley Input Parameters: 2048194d53e6SMatthew G. Knepley + prob - The PetscDS 2049194d53e6SMatthew G. Knepley . f - The test field number 2050194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term 2051194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2052194d53e6SMatthew G. Knepley 2053194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2054194d53e6SMatthew G. Knepley 2055194d53e6SMatthew 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 2056194d53e6SMatthew G. Knepley 2057194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2058194d53e6SMatthew G. Knepley 205930b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2060194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2061194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 206230b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2063194d53e6SMatthew G. Knepley 2064194d53e6SMatthew G. Knepley + dim - the spatial dimension 2065194d53e6SMatthew G. Knepley . Nf - the number of fields 2066194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2067194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2068194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2069194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2070194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2071194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2072194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2073194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2074194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2075194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2076194d53e6SMatthew G. Knepley . t - current time 2077194d53e6SMatthew G. Knepley . x - coordinates of the current point 2078194d53e6SMatthew G. Knepley . n - unit normal at the current point 207997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 208097b6e6e8SMatthew G. Knepley . constants - constant parameters 2081194d53e6SMatthew G. Knepley - f0 - output values at the current point 2082194d53e6SMatthew G. Knepley 2083194d53e6SMatthew G. Knepley Level: intermediate 2084194d53e6SMatthew G. Knepley 2085194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual() 2086194d53e6SMatthew G. Knepley @*/ 20872764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f, 208830b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2089194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2090194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 209197b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 209230b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2093194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2094194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 209597b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 20962764a2aaSMatthew G. Knepley { 20972764a2aaSMatthew G. Knepley PetscErrorCode ierr; 20982764a2aaSMatthew G. Knepley 20992764a2aaSMatthew G. Knepley PetscFunctionBegin; 21002764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 21012764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 21022764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 21032764a2aaSMatthew G. Knepley if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;} 21042764a2aaSMatthew G. Knepley if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;} 21052764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21062764a2aaSMatthew G. Knepley } 21072764a2aaSMatthew G. Knepley 210827f02ce8SMatthew G. Knepley /*@ 210927f02ce8SMatthew G. Knepley PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set 211027f02ce8SMatthew G. Knepley 211127f02ce8SMatthew G. Knepley Not collective 211227f02ce8SMatthew G. Knepley 211327f02ce8SMatthew G. Knepley Input Parameter: 211427f02ce8SMatthew G. Knepley . prob - The PetscDS 211527f02ce8SMatthew G. Knepley 211627f02ce8SMatthew G. Knepley Output Parameter: 211727f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set 211827f02ce8SMatthew G. Knepley 211927f02ce8SMatthew G. Knepley Level: intermediate 212027f02ce8SMatthew G. Knepley 212127f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian() 212227f02ce8SMatthew G. Knepley @*/ 212327f02ce8SMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobian(PetscDS prob, PetscBool *hasBdJac) 212427f02ce8SMatthew G. Knepley { 212527f02ce8SMatthew G. Knepley PetscInt f, g, h; 212627f02ce8SMatthew G. Knepley 212727f02ce8SMatthew G. Knepley PetscFunctionBegin; 212827f02ce8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 212927f02ce8SMatthew G. Knepley *hasBdJac = PETSC_FALSE; 213027f02ce8SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 213127f02ce8SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 213227f02ce8SMatthew G. Knepley for (h = 0; h < 4; ++h) { 213327f02ce8SMatthew G. Knepley if (prob->gBd[(f*prob->Nf + g)*4+h]) *hasBdJac = PETSC_TRUE; 213427f02ce8SMatthew G. Knepley } 213527f02ce8SMatthew G. Knepley } 213627f02ce8SMatthew G. Knepley } 213727f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 213827f02ce8SMatthew G. Knepley } 213927f02ce8SMatthew G. Knepley 2140194d53e6SMatthew G. Knepley /*@C 2141194d53e6SMatthew G. Knepley PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field 2142194d53e6SMatthew G. Knepley 2143194d53e6SMatthew G. Knepley Not collective 2144194d53e6SMatthew G. Knepley 2145194d53e6SMatthew G. Knepley Input Parameters: 2146194d53e6SMatthew G. Knepley + prob - The PetscDS 2147194d53e6SMatthew G. Knepley . f - The test field number 2148194d53e6SMatthew G. Knepley - g - The field number 2149194d53e6SMatthew G. Knepley 2150194d53e6SMatthew G. Knepley Output Parameters: 2151194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 2152194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2153194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2154194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2155194d53e6SMatthew G. Knepley 2156194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2157194d53e6SMatthew G. Knepley 2158194d53e6SMatthew 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 2159194d53e6SMatthew G. Knepley 2160194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2161194d53e6SMatthew G. Knepley 216230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2163194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2164194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 216530b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2166194d53e6SMatthew G. Knepley 2167194d53e6SMatthew G. Knepley + dim - the spatial dimension 2168194d53e6SMatthew G. Knepley . Nf - the number of fields 2169194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2170194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2171194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2172194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2173194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2174194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2175194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2176194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2177194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2178194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2179194d53e6SMatthew G. Knepley . t - current time 21802aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2181194d53e6SMatthew G. Knepley . x - coordinates of the current point 2182194d53e6SMatthew G. Knepley . n - normal at the current point 218397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 218497b6e6e8SMatthew G. Knepley . constants - constant parameters 2185194d53e6SMatthew G. Knepley - g0 - output values at the current point 2186194d53e6SMatthew G. Knepley 2187194d53e6SMatthew G. Knepley Level: intermediate 2188194d53e6SMatthew G. Knepley 2189194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian() 2190194d53e6SMatthew G. Knepley @*/ 21912764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 219230b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2193194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2194194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 219597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 219630b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2197194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2198194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 219997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 220030b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2201194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2202194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 220397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 220430b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2205194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2206194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 220797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 22082764a2aaSMatthew G. Knepley { 22092764a2aaSMatthew G. Knepley PetscFunctionBegin; 22102764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 22112764a2aaSMatthew 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); 22122764a2aaSMatthew 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); 22132764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];} 22142764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];} 22152764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];} 22162764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];} 22172764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22182764a2aaSMatthew G. Knepley } 22192764a2aaSMatthew G. Knepley 2220194d53e6SMatthew G. Knepley /*@C 2221194d53e6SMatthew G. Knepley PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field 2222194d53e6SMatthew G. Knepley 2223194d53e6SMatthew G. Knepley Not collective 2224194d53e6SMatthew G. Knepley 2225194d53e6SMatthew G. Knepley Input Parameters: 2226194d53e6SMatthew G. Knepley + prob - The PetscDS 2227194d53e6SMatthew G. Knepley . f - The test field number 2228194d53e6SMatthew G. Knepley . g - The field number 2229194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 2230194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2231194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2232194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2233194d53e6SMatthew G. Knepley 2234194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2235194d53e6SMatthew G. Knepley 2236194d53e6SMatthew 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 2237194d53e6SMatthew G. Knepley 2238194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2239194d53e6SMatthew G. Knepley 224030b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2241194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2242194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 224330b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2244194d53e6SMatthew G. Knepley 2245194d53e6SMatthew G. Knepley + dim - the spatial dimension 2246194d53e6SMatthew G. Knepley . Nf - the number of fields 2247194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2248194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2249194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2250194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2251194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2252194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2253194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2254194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2255194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2256194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2257194d53e6SMatthew G. Knepley . t - current time 22582aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2259194d53e6SMatthew G. Knepley . x - coordinates of the current point 2260194d53e6SMatthew G. Knepley . n - normal at the current point 226197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 226297b6e6e8SMatthew G. Knepley . constants - constant parameters 2263194d53e6SMatthew G. Knepley - g0 - output values at the current point 2264194d53e6SMatthew G. Knepley 2265194d53e6SMatthew G. Knepley Level: intermediate 2266194d53e6SMatthew G. Knepley 2267194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian() 2268194d53e6SMatthew G. Knepley @*/ 22692764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 227030b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2271194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2272194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 227397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 227430b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2275194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2276194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 227797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 227830b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2279194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2280194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 228197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 228230b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2283194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2284194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 228597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 22862764a2aaSMatthew G. Knepley { 22872764a2aaSMatthew G. Knepley PetscErrorCode ierr; 22882764a2aaSMatthew G. Knepley 22892764a2aaSMatthew G. Knepley PetscFunctionBegin; 22902764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 22912764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 22922764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 22932764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 22942764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 22952764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 22962764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 22972764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 22982764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+0] = g0; 22992764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+1] = g1; 23002764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+2] = g2; 23012764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+3] = g3; 23022764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 23032764a2aaSMatthew G. Knepley } 23042764a2aaSMatthew G. Knepley 230527f02ce8SMatthew G. Knepley /*@ 230627f02ce8SMatthew G. Knepley PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set 230727f02ce8SMatthew G. Knepley 230827f02ce8SMatthew G. Knepley Not collective 230927f02ce8SMatthew G. Knepley 231027f02ce8SMatthew G. Knepley Input Parameter: 231127f02ce8SMatthew G. Knepley . prob - The PetscDS 231227f02ce8SMatthew G. Knepley 231327f02ce8SMatthew G. Knepley Output Parameter: 231427f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set 231527f02ce8SMatthew G. Knepley 231627f02ce8SMatthew G. Knepley Level: intermediate 231727f02ce8SMatthew G. Knepley 231827f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian() 231927f02ce8SMatthew G. Knepley @*/ 232027f02ce8SMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS prob, PetscBool *hasBdJacPre) 232127f02ce8SMatthew G. Knepley { 232227f02ce8SMatthew G. Knepley PetscInt f, g, h; 232327f02ce8SMatthew G. Knepley 232427f02ce8SMatthew G. Knepley PetscFunctionBegin; 232527f02ce8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 232627f02ce8SMatthew G. Knepley *hasBdJacPre = PETSC_FALSE; 232727f02ce8SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 232827f02ce8SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 232927f02ce8SMatthew G. Knepley for (h = 0; h < 4; ++h) { 233027f02ce8SMatthew G. Knepley if (prob->gpBd[(f*prob->Nf + g)*4+h]) *hasBdJacPre = PETSC_TRUE; 233127f02ce8SMatthew G. Knepley } 233227f02ce8SMatthew G. Knepley } 233327f02ce8SMatthew G. Knepley } 233427f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 233527f02ce8SMatthew G. Knepley } 233627f02ce8SMatthew G. Knepley 233727f02ce8SMatthew G. Knepley /*@C 233827f02ce8SMatthew G. Knepley PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field 233927f02ce8SMatthew G. Knepley 234027f02ce8SMatthew G. Knepley Not collective 234127f02ce8SMatthew G. Knepley 234227f02ce8SMatthew G. Knepley Input Parameters: 234327f02ce8SMatthew G. Knepley + prob - The PetscDS 234427f02ce8SMatthew G. Knepley . f - The test field number 234527f02ce8SMatthew G. Knepley - g - The field number 234627f02ce8SMatthew G. Knepley 234727f02ce8SMatthew G. Knepley Output Parameters: 234827f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term 234927f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 235027f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 235127f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 235227f02ce8SMatthew G. Knepley 235327f02ce8SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 235427f02ce8SMatthew G. Knepley 235527f02ce8SMatthew 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 235627f02ce8SMatthew G. Knepley 235727f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 235827f02ce8SMatthew G. Knepley 235927f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 236027f02ce8SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 236127f02ce8SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 236227f02ce8SMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 236327f02ce8SMatthew G. Knepley 236427f02ce8SMatthew G. Knepley + dim - the spatial dimension 236527f02ce8SMatthew G. Knepley . Nf - the number of fields 236627f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 236727f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 236827f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 236927f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 237027f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 237127f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 237227f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 237327f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 237427f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 237527f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 237627f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 237727f02ce8SMatthew G. Knepley . t - current time 237827f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 237927f02ce8SMatthew G. Knepley . x - coordinates of the current point 238027f02ce8SMatthew G. Knepley . n - normal at the current point 238127f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 238227f02ce8SMatthew G. Knepley . constants - constant parameters 238327f02ce8SMatthew G. Knepley - g0 - output values at the current point 238427f02ce8SMatthew G. Knepley 238527f02ce8SMatthew G. Knepley This is not yet available in Fortran. 238627f02ce8SMatthew G. Knepley 238727f02ce8SMatthew G. Knepley Level: intermediate 238827f02ce8SMatthew G. Knepley 238927f02ce8SMatthew G. Knepley .seealso: PetscDSSetBdJacobianPreconditioner() 239027f02ce8SMatthew G. Knepley @*/ 239127f02ce8SMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 239227f02ce8SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 239327f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 239427f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 239527f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 239627f02ce8SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 239727f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 239827f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 239927f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 240027f02ce8SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 240127f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 240227f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 240327f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 240427f02ce8SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 240527f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 240627f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 240727f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 240827f02ce8SMatthew G. Knepley { 240927f02ce8SMatthew G. Knepley PetscFunctionBegin; 241027f02ce8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 241127f02ce8SMatthew 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); 241227f02ce8SMatthew 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); 241327f02ce8SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gpBd[(f*prob->Nf + g)*4+0];} 241427f02ce8SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gpBd[(f*prob->Nf + g)*4+1];} 241527f02ce8SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gpBd[(f*prob->Nf + g)*4+2];} 241627f02ce8SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gpBd[(f*prob->Nf + g)*4+3];} 241727f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 241827f02ce8SMatthew G. Knepley } 241927f02ce8SMatthew G. Knepley 242027f02ce8SMatthew G. Knepley /*@C 242127f02ce8SMatthew G. Knepley PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field 242227f02ce8SMatthew G. Knepley 242327f02ce8SMatthew G. Knepley Not collective 242427f02ce8SMatthew G. Knepley 242527f02ce8SMatthew G. Knepley Input Parameters: 242627f02ce8SMatthew G. Knepley + prob - The PetscDS 242727f02ce8SMatthew G. Knepley . f - The test field number 242827f02ce8SMatthew G. Knepley . g - The field number 242927f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term 243027f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 243127f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 243227f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 243327f02ce8SMatthew G. Knepley 243427f02ce8SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 243527f02ce8SMatthew G. Knepley 243627f02ce8SMatthew 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 243727f02ce8SMatthew G. Knepley 243827f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 243927f02ce8SMatthew G. Knepley 244027f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 244127f02ce8SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 244227f02ce8SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 244327f02ce8SMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 244427f02ce8SMatthew G. Knepley 244527f02ce8SMatthew G. Knepley + dim - the spatial dimension 244627f02ce8SMatthew G. Knepley . Nf - the number of fields 244727f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 244827f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 244927f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 245027f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 245127f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 245227f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 245327f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 245427f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 245527f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 245627f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 245727f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 245827f02ce8SMatthew G. Knepley . t - current time 245927f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 246027f02ce8SMatthew G. Knepley . x - coordinates of the current point 246127f02ce8SMatthew G. Knepley . n - normal at the current point 246227f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 246327f02ce8SMatthew G. Knepley . constants - constant parameters 246427f02ce8SMatthew G. Knepley - g0 - output values at the current point 246527f02ce8SMatthew G. Knepley 246627f02ce8SMatthew G. Knepley This is not yet available in Fortran. 246727f02ce8SMatthew G. Knepley 246827f02ce8SMatthew G. Knepley Level: intermediate 246927f02ce8SMatthew G. Knepley 247027f02ce8SMatthew G. Knepley .seealso: PetscDSGetBdJacobianPreconditioner() 247127f02ce8SMatthew G. Knepley @*/ 247227f02ce8SMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 247327f02ce8SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 247427f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 247527f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 247627f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 247727f02ce8SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 247827f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 247927f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 248027f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 248127f02ce8SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 248227f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 248327f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 248427f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 248527f02ce8SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 248627f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 248727f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 248827f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 248927f02ce8SMatthew G. Knepley { 249027f02ce8SMatthew G. Knepley PetscErrorCode ierr; 249127f02ce8SMatthew G. Knepley 249227f02ce8SMatthew G. Knepley PetscFunctionBegin; 249327f02ce8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 249427f02ce8SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 249527f02ce8SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 249627f02ce8SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 249727f02ce8SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 249827f02ce8SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 249927f02ce8SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 250027f02ce8SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 250127f02ce8SMatthew G. Knepley prob->gpBd[(f*prob->Nf + g)*4+0] = g0; 250227f02ce8SMatthew G. Knepley prob->gpBd[(f*prob->Nf + g)*4+1] = g1; 250327f02ce8SMatthew G. Knepley prob->gpBd[(f*prob->Nf + g)*4+2] = g2; 250427f02ce8SMatthew G. Knepley prob->gpBd[(f*prob->Nf + g)*4+3] = g3; 250527f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 250627f02ce8SMatthew G. Knepley } 250727f02ce8SMatthew G. Knepley 25080d3e9b51SMatthew G. Knepley /*@C 2509c371a6d1SMatthew G. Knepley PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field 2510c371a6d1SMatthew G. Knepley 2511c371a6d1SMatthew G. Knepley Not collective 2512c371a6d1SMatthew G. Knepley 2513c371a6d1SMatthew G. Knepley Input Parameters: 2514c371a6d1SMatthew G. Knepley + prob - The PetscDS 2515c371a6d1SMatthew G. Knepley - f - The test field number 2516c371a6d1SMatthew G. Knepley 2517c371a6d1SMatthew G. Knepley Output Parameter: 251895cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field 251995cbbfd3SMatthew G. Knepley - exactCtx - exact solution context 2520c371a6d1SMatthew G. Knepley 2521c371a6d1SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2522c371a6d1SMatthew G. Knepley 2523c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2524c371a6d1SMatthew G. Knepley 2525c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2526c371a6d1SMatthew G. Knepley . t - current time 2527c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2528c371a6d1SMatthew G. Knepley . Nc - the number of field components 2529c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2530c371a6d1SMatthew G. Knepley - ctx - a user context 2531c371a6d1SMatthew G. Knepley 2532c371a6d1SMatthew G. Knepley Level: intermediate 2533c371a6d1SMatthew G. Knepley 2534c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution() 2535c371a6d1SMatthew G. Knepley @*/ 253695cbbfd3SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx) 2537c371a6d1SMatthew G. Knepley { 2538c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2539c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2540c371a6d1SMatthew 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); 2541c371a6d1SMatthew G. Knepley if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];} 254295cbbfd3SMatthew G. Knepley if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];} 2543c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2544c371a6d1SMatthew G. Knepley } 2545c371a6d1SMatthew G. Knepley 2546c371a6d1SMatthew G. Knepley /*@C 2547578a5ef5SMatthew Knepley PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field 2548c371a6d1SMatthew G. Knepley 2549c371a6d1SMatthew G. Knepley Not collective 2550c371a6d1SMatthew G. Knepley 2551c371a6d1SMatthew G. Knepley Input Parameters: 2552c371a6d1SMatthew G. Knepley + prob - The PetscDS 2553c371a6d1SMatthew G. Knepley . f - The test field number 255495cbbfd3SMatthew G. Knepley . sol - solution function for the test fields 255595cbbfd3SMatthew G. Knepley - ctx - solution context or NULL 2556c371a6d1SMatthew G. Knepley 2557c371a6d1SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2558c371a6d1SMatthew G. Knepley 2559c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2560c371a6d1SMatthew G. Knepley 2561c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2562c371a6d1SMatthew G. Knepley . t - current time 2563c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2564c371a6d1SMatthew G. Knepley . Nc - the number of field components 2565c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2566c371a6d1SMatthew G. Knepley - ctx - a user context 2567c371a6d1SMatthew G. Knepley 2568c371a6d1SMatthew G. Knepley Level: intermediate 2569c371a6d1SMatthew G. Knepley 2570c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution() 2571c371a6d1SMatthew G. Knepley @*/ 257295cbbfd3SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx) 2573c371a6d1SMatthew G. Knepley { 2574c371a6d1SMatthew G. Knepley PetscErrorCode ierr; 2575c371a6d1SMatthew G. Knepley 2576c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2577c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2578c371a6d1SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 2579c371a6d1SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 2580c371a6d1SMatthew G. Knepley if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;} 258195cbbfd3SMatthew G. Knepley if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;} 2582c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2583c371a6d1SMatthew G. Knepley } 2584c371a6d1SMatthew G. Knepley 25855638fd0eSMatthew G. Knepley /*@C 258697b6e6e8SMatthew G. Knepley PetscDSGetConstants - Returns the array of constants passed to point functions 258797b6e6e8SMatthew G. Knepley 258897b6e6e8SMatthew G. Knepley Not collective 258997b6e6e8SMatthew G. Knepley 259097b6e6e8SMatthew G. Knepley Input Parameter: 259197b6e6e8SMatthew G. Knepley . prob - The PetscDS object 259297b6e6e8SMatthew G. Knepley 259397b6e6e8SMatthew G. Knepley Output Parameters: 259497b6e6e8SMatthew G. Knepley + numConstants - The number of constants 259597b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 259697b6e6e8SMatthew G. Knepley 259797b6e6e8SMatthew G. Knepley Level: intermediate 259897b6e6e8SMatthew G. Knepley 259997b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate() 260097b6e6e8SMatthew G. Knepley @*/ 260197b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[]) 260297b6e6e8SMatthew G. Knepley { 260397b6e6e8SMatthew G. Knepley PetscFunctionBegin; 260497b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 260597b6e6e8SMatthew G. Knepley if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;} 260697b6e6e8SMatthew G. Knepley if (constants) {PetscValidPointer(constants, 3); *constants = prob->constants;} 260797b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 260897b6e6e8SMatthew G. Knepley } 260997b6e6e8SMatthew G. Knepley 26100d3e9b51SMatthew G. Knepley /*@C 261197b6e6e8SMatthew G. Knepley PetscDSSetConstants - Set the array of constants passed to point functions 261297b6e6e8SMatthew G. Knepley 261397b6e6e8SMatthew G. Knepley Not collective 261497b6e6e8SMatthew G. Knepley 261597b6e6e8SMatthew G. Knepley Input Parameters: 261697b6e6e8SMatthew G. Knepley + prob - The PetscDS object 261797b6e6e8SMatthew G. Knepley . numConstants - The number of constants 261897b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 261997b6e6e8SMatthew G. Knepley 262097b6e6e8SMatthew G. Knepley Level: intermediate 262197b6e6e8SMatthew G. Knepley 262297b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate() 262397b6e6e8SMatthew G. Knepley @*/ 262497b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[]) 262597b6e6e8SMatthew G. Knepley { 262697b6e6e8SMatthew G. Knepley PetscErrorCode ierr; 262797b6e6e8SMatthew G. Knepley 262897b6e6e8SMatthew G. Knepley PetscFunctionBegin; 262997b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 263097b6e6e8SMatthew G. Knepley if (numConstants != prob->numConstants) { 263197b6e6e8SMatthew G. Knepley ierr = PetscFree(prob->constants);CHKERRQ(ierr); 263297b6e6e8SMatthew G. Knepley prob->numConstants = numConstants; 263397b6e6e8SMatthew G. Knepley if (prob->numConstants) { 263497b6e6e8SMatthew G. Knepley ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr); 263520be0f5bSMatthew G. Knepley } else { 263620be0f5bSMatthew G. Knepley prob->constants = NULL; 263720be0f5bSMatthew G. Knepley } 263820be0f5bSMatthew G. Knepley } 263920be0f5bSMatthew G. Knepley if (prob->numConstants) { 264020be0f5bSMatthew G. Knepley PetscValidPointer(constants, 3); 2641580bdb30SBarry Smith ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr); 264297b6e6e8SMatthew G. Knepley } 264397b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 264497b6e6e8SMatthew G. Knepley } 264597b6e6e8SMatthew G. Knepley 26464cd1e086SMatthew G. Knepley /*@ 26474cd1e086SMatthew G. Knepley PetscDSGetFieldIndex - Returns the index of the given field 26484cd1e086SMatthew G. Knepley 26494cd1e086SMatthew G. Knepley Not collective 26504cd1e086SMatthew G. Knepley 26514cd1e086SMatthew G. Knepley Input Parameters: 26524cd1e086SMatthew G. Knepley + prob - The PetscDS object 26534cd1e086SMatthew G. Knepley - disc - The discretization object 26544cd1e086SMatthew G. Knepley 26554cd1e086SMatthew G. Knepley Output Parameter: 26564cd1e086SMatthew G. Knepley . f - The field number 26574cd1e086SMatthew G. Knepley 26584cd1e086SMatthew G. Knepley Level: beginner 26594cd1e086SMatthew G. Knepley 2660f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 26614cd1e086SMatthew G. Knepley @*/ 26624cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f) 26634cd1e086SMatthew G. Knepley { 26644cd1e086SMatthew G. Knepley PetscInt g; 26654cd1e086SMatthew G. Knepley 26664cd1e086SMatthew G. Knepley PetscFunctionBegin; 26674cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26684cd1e086SMatthew G. Knepley PetscValidPointer(f, 3); 26694cd1e086SMatthew G. Knepley *f = -1; 26704cd1e086SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;} 26714cd1e086SMatthew G. Knepley if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS."); 26724cd1e086SMatthew G. Knepley *f = g; 26734cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 26744cd1e086SMatthew G. Knepley } 26754cd1e086SMatthew G. Knepley 26764cd1e086SMatthew G. Knepley /*@ 26774cd1e086SMatthew G. Knepley PetscDSGetFieldSize - Returns the size of the given field in the full space basis 26784cd1e086SMatthew G. Knepley 26794cd1e086SMatthew G. Knepley Not collective 26804cd1e086SMatthew G. Knepley 26814cd1e086SMatthew G. Knepley Input Parameters: 26824cd1e086SMatthew G. Knepley + prob - The PetscDS object 26834cd1e086SMatthew G. Knepley - f - The field number 26844cd1e086SMatthew G. Knepley 26854cd1e086SMatthew G. Knepley Output Parameter: 26864cd1e086SMatthew G. Knepley . size - The size 26874cd1e086SMatthew G. Knepley 26884cd1e086SMatthew G. Knepley Level: beginner 26894cd1e086SMatthew G. Knepley 2690f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate() 26914cd1e086SMatthew G. Knepley @*/ 26924cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size) 26934cd1e086SMatthew G. Knepley { 26942166fd64SMatthew G. Knepley PetscErrorCode ierr; 26952166fd64SMatthew G. Knepley 26964cd1e086SMatthew G. Knepley PetscFunctionBegin; 26974cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26984cd1e086SMatthew G. Knepley PetscValidPointer(size, 3); 26994cd1e086SMatthew 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); 27002166fd64SMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2701d4742ddaSMatthew G. Knepley *size = prob->Nb[f]; 27024cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 27034cd1e086SMatthew G. Knepley } 27044cd1e086SMatthew G. Knepley 2705bc4ae4beSMatthew G. Knepley /*@ 2706bc4ae4beSMatthew G. Knepley PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis 2707bc4ae4beSMatthew G. Knepley 2708bc4ae4beSMatthew G. Knepley Not collective 2709bc4ae4beSMatthew G. Knepley 2710bc4ae4beSMatthew G. Knepley Input Parameters: 2711bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 2712bc4ae4beSMatthew G. Knepley - f - The field number 2713bc4ae4beSMatthew G. Knepley 2714bc4ae4beSMatthew G. Knepley Output Parameter: 2715bc4ae4beSMatthew G. Knepley . off - The offset 2716bc4ae4beSMatthew G. Knepley 2717bc4ae4beSMatthew G. Knepley Level: beginner 2718bc4ae4beSMatthew G. Knepley 2719f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate() 2720bc4ae4beSMatthew G. Knepley @*/ 27212764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 27222764a2aaSMatthew G. Knepley { 27234cd1e086SMatthew G. Knepley PetscInt size, g; 27242764a2aaSMatthew G. Knepley PetscErrorCode ierr; 27252764a2aaSMatthew G. Knepley 27262764a2aaSMatthew G. Knepley PetscFunctionBegin; 27272764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 27282764a2aaSMatthew G. Knepley PetscValidPointer(off, 3); 27292764a2aaSMatthew 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); 27302764a2aaSMatthew G. Knepley *off = 0; 27312764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 27324cd1e086SMatthew G. Knepley ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr); 27334cd1e086SMatthew G. Knepley *off += size; 27342764a2aaSMatthew G. Knepley } 27352764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27362764a2aaSMatthew G. Knepley } 27372764a2aaSMatthew G. Knepley 2738bc4ae4beSMatthew G. Knepley /*@ 273947e57110SSander Arens PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point 2740bc4ae4beSMatthew G. Knepley 2741bc4ae4beSMatthew G. Knepley Not collective 2742bc4ae4beSMatthew G. Knepley 274347e57110SSander Arens Input Parameter: 274447e57110SSander Arens . prob - The PetscDS object 2745bc4ae4beSMatthew G. Knepley 2746bc4ae4beSMatthew G. Knepley Output Parameter: 274747e57110SSander Arens . dimensions - The number of dimensions 2748bc4ae4beSMatthew G. Knepley 2749bc4ae4beSMatthew G. Knepley Level: beginner 2750bc4ae4beSMatthew G. Knepley 275147e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 2752bc4ae4beSMatthew G. Knepley @*/ 275347e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[]) 27542764a2aaSMatthew G. Knepley { 27552764a2aaSMatthew G. Knepley PetscErrorCode ierr; 27562764a2aaSMatthew G. Knepley 27572764a2aaSMatthew G. Knepley PetscFunctionBegin; 27582764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 275947e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 276047e57110SSander Arens PetscValidPointer(dimensions, 2); 276147e57110SSander Arens *dimensions = prob->Nb; 276247e57110SSander Arens PetscFunctionReturn(0); 27636ce16762SMatthew G. Knepley } 276447e57110SSander Arens 276547e57110SSander Arens /*@ 276647e57110SSander Arens PetscDSGetComponents - Returns the number of components for each field on an evaluation point 276747e57110SSander Arens 276847e57110SSander Arens Not collective 276947e57110SSander Arens 277047e57110SSander Arens Input Parameter: 277147e57110SSander Arens . prob - The PetscDS object 277247e57110SSander Arens 277347e57110SSander Arens Output Parameter: 277447e57110SSander Arens . components - The number of components 277547e57110SSander Arens 277647e57110SSander Arens Level: beginner 277747e57110SSander Arens 277847e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 277947e57110SSander Arens @*/ 278047e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[]) 278147e57110SSander Arens { 278247e57110SSander Arens PetscErrorCode ierr; 278347e57110SSander Arens 278447e57110SSander Arens PetscFunctionBegin; 278547e57110SSander Arens PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 278647e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 278747e57110SSander Arens PetscValidPointer(components, 2); 278847e57110SSander Arens *components = prob->Nc; 27896ce16762SMatthew G. Knepley PetscFunctionReturn(0); 27906ce16762SMatthew G. Knepley } 27916ce16762SMatthew G. Knepley 27926ce16762SMatthew G. Knepley /*@ 27936ce16762SMatthew G. Knepley PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point 27946ce16762SMatthew G. Knepley 27956ce16762SMatthew G. Knepley Not collective 27966ce16762SMatthew G. Knepley 27976ce16762SMatthew G. Knepley Input Parameters: 27986ce16762SMatthew G. Knepley + prob - The PetscDS object 27996ce16762SMatthew G. Knepley - f - The field number 28006ce16762SMatthew G. Knepley 28016ce16762SMatthew G. Knepley Output Parameter: 28026ce16762SMatthew G. Knepley . off - The offset 28036ce16762SMatthew G. Knepley 28046ce16762SMatthew G. Knepley Level: beginner 28056ce16762SMatthew G. Knepley 2806f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 28076ce16762SMatthew G. Knepley @*/ 28086ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off) 28096ce16762SMatthew G. Knepley { 28106ce16762SMatthew G. Knepley PetscFunctionBegin; 28116ce16762SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 28126ce16762SMatthew G. Knepley PetscValidPointer(off, 3); 28136ce16762SMatthew 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); 281447e57110SSander Arens *off = prob->off[f]; 28152764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 28162764a2aaSMatthew G. Knepley } 28172764a2aaSMatthew G. Knepley 2818194d53e6SMatthew G. Knepley /*@ 2819194d53e6SMatthew G. Knepley PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point 2820194d53e6SMatthew G. Knepley 2821194d53e6SMatthew G. Knepley Not collective 2822194d53e6SMatthew G. Knepley 2823194d53e6SMatthew G. Knepley Input Parameter: 2824194d53e6SMatthew G. Knepley . prob - The PetscDS object 2825194d53e6SMatthew G. Knepley 2826194d53e6SMatthew G. Knepley Output Parameter: 2827194d53e6SMatthew G. Knepley . offsets - The offsets 2828194d53e6SMatthew G. Knepley 2829194d53e6SMatthew G. Knepley Level: beginner 2830194d53e6SMatthew G. Knepley 2831f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2832194d53e6SMatthew G. Knepley @*/ 2833194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[]) 2834194d53e6SMatthew G. Knepley { 2835194d53e6SMatthew G. Knepley PetscFunctionBegin; 2836194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2837194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2838194d53e6SMatthew G. Knepley *offsets = prob->off; 2839194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2840194d53e6SMatthew G. Knepley } 2841194d53e6SMatthew G. Knepley 2842194d53e6SMatthew G. Knepley /*@ 2843194d53e6SMatthew G. Knepley PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point 2844194d53e6SMatthew G. Knepley 2845194d53e6SMatthew G. Knepley Not collective 2846194d53e6SMatthew G. Knepley 2847194d53e6SMatthew G. Knepley Input Parameter: 2848194d53e6SMatthew G. Knepley . prob - The PetscDS object 2849194d53e6SMatthew G. Knepley 2850194d53e6SMatthew G. Knepley Output Parameter: 2851194d53e6SMatthew G. Knepley . offsets - The offsets 2852194d53e6SMatthew G. Knepley 2853194d53e6SMatthew G. Knepley Level: beginner 2854194d53e6SMatthew G. Knepley 2855f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2856194d53e6SMatthew G. Knepley @*/ 2857194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[]) 2858194d53e6SMatthew G. Knepley { 2859194d53e6SMatthew G. Knepley PetscFunctionBegin; 2860194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2861194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2862194d53e6SMatthew G. Knepley *offsets = prob->offDer; 2863194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2864194d53e6SMatthew G. Knepley } 2865194d53e6SMatthew G. Knepley 286668c9edb9SMatthew G. Knepley /*@C 286768c9edb9SMatthew G. Knepley PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization 286868c9edb9SMatthew G. Knepley 286968c9edb9SMatthew G. Knepley Not collective 287068c9edb9SMatthew G. Knepley 287168c9edb9SMatthew G. Knepley Input Parameter: 287268c9edb9SMatthew G. Knepley . prob - The PetscDS object 287368c9edb9SMatthew G. Knepley 2874ef0bb6c7SMatthew G. Knepley Output Parameter: 2875ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field 287668c9edb9SMatthew G. Knepley 287768c9edb9SMatthew G. Knepley Level: intermediate 287868c9edb9SMatthew G. Knepley 2879f744cafaSSander Arens .seealso: PetscDSCreate() 288068c9edb9SMatthew G. Knepley @*/ 2881ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[]) 28822764a2aaSMatthew G. Knepley { 28832764a2aaSMatthew G. Knepley PetscErrorCode ierr; 28842764a2aaSMatthew G. Knepley 28852764a2aaSMatthew G. Knepley PetscFunctionBegin; 28862764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2887ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 2); 28882764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2889ef0bb6c7SMatthew G. Knepley *T = prob->T; 28902764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 28912764a2aaSMatthew G. Knepley } 28922764a2aaSMatthew G. Knepley 289368c9edb9SMatthew G. Knepley /*@C 28944d0b9603SSander Arens PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces 289568c9edb9SMatthew G. Knepley 289668c9edb9SMatthew G. Knepley Not collective 289768c9edb9SMatthew G. Knepley 289868c9edb9SMatthew G. Knepley Input Parameter: 289968c9edb9SMatthew G. Knepley . prob - The PetscDS object 290068c9edb9SMatthew G. Knepley 2901ef0bb6c7SMatthew G. Knepley Output Parameter: 2902ef0bb6c7SMatthew G. Knepley . Tf - The basis function and derviative tabulation on each lcoal face at quadrature points for each and field 290368c9edb9SMatthew G. Knepley 290468c9edb9SMatthew G. Knepley Level: intermediate 290568c9edb9SMatthew G. Knepley 290668c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate() 290768c9edb9SMatthew G. Knepley @*/ 2908ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[]) 29092764a2aaSMatthew G. Knepley { 29102764a2aaSMatthew G. Knepley PetscErrorCode ierr; 29112764a2aaSMatthew G. Knepley 29122764a2aaSMatthew G. Knepley PetscFunctionBegin; 29132764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2914ef0bb6c7SMatthew G. Knepley PetscValidPointer(Tf, 2); 29152764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2916ef0bb6c7SMatthew G. Knepley *Tf = prob->Tf; 29172764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 29182764a2aaSMatthew G. Knepley } 29192764a2aaSMatthew G. Knepley 29202764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) 29212764a2aaSMatthew G. Knepley { 29222764a2aaSMatthew G. Knepley PetscErrorCode ierr; 29232764a2aaSMatthew G. Knepley 29242764a2aaSMatthew G. Knepley PetscFunctionBegin; 29252764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 29262764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 29272764a2aaSMatthew G. Knepley if (u) {PetscValidPointer(u, 2); *u = prob->u;} 29282764a2aaSMatthew G. Knepley if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;} 29292764a2aaSMatthew G. Knepley if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;} 29302764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 29312764a2aaSMatthew G. Knepley } 29322764a2aaSMatthew G. Knepley 29332764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) 29342764a2aaSMatthew G. Knepley { 29352764a2aaSMatthew G. Knepley PetscErrorCode ierr; 29362764a2aaSMatthew G. Knepley 29372764a2aaSMatthew G. Knepley PetscFunctionBegin; 29382764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 29392764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 29402764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;} 29412764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;} 29422764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;} 29432764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;} 29442764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;} 29452764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;} 29462764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 29472764a2aaSMatthew G. Knepley } 29482764a2aaSMatthew G. Knepley 29494bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal) 29502764a2aaSMatthew G. Knepley { 29512764a2aaSMatthew G. Knepley PetscErrorCode ierr; 29522764a2aaSMatthew G. Knepley 29532764a2aaSMatthew G. Knepley PetscFunctionBegin; 29542764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 29552764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 29562764a2aaSMatthew G. Knepley if (x) {PetscValidPointer(x, 2); *x = prob->x;} 29574bee2e38SMatthew G. Knepley if (basisReal) {PetscValidPointer(basisReal, 3); *basisReal = prob->basisReal;} 29587506b574SStefano Zampini if (basisDerReal) {PetscValidPointer(basisDerReal, 4); *basisDerReal = prob->basisDerReal;} 29597506b574SStefano Zampini if (testReal) {PetscValidPointer(testReal, 5); *testReal = prob->testReal;} 29607506b574SStefano Zampini if (testDerReal) {PetscValidPointer(testDerReal, 6); *testDerReal = prob->testDerReal;} 29612764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 29622764a2aaSMatthew G. Knepley } 29632764a2aaSMatthew G. Knepley 296458ebd649SToby Isaac /*@C 296558ebd649SToby Isaac PetscDSAddBoundary - Add a boundary condition to the model 296658ebd649SToby Isaac 2967783e2ec8SMatthew G. Knepley Collective on ds 2968783e2ec8SMatthew G. Knepley 296958ebd649SToby Isaac Input Parameters: 297058ebd649SToby Isaac + ds - The PetscDS object 29712d47a189SJulian Andrej . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 297258ebd649SToby Isaac . name - The BC name 297358ebd649SToby Isaac . labelname - The label defining constrained points 297458ebd649SToby Isaac . field - The field to constrain 2975e8ecbf3fSStefano Zampini . numcomps - The number of constrained field components (0 will constrain all fields) 297658ebd649SToby Isaac . comps - An array of constrained component numbers 297758ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 297858ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 297958ebd649SToby Isaac . ids - An array of ids for constrained points 298058ebd649SToby Isaac - ctx - An optional user context for bcFunc 298158ebd649SToby Isaac 298258ebd649SToby Isaac Options Database Keys: 298358ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 298458ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 298558ebd649SToby Isaac 298658ebd649SToby Isaac Level: developer 298758ebd649SToby Isaac 298858ebd649SToby Isaac .seealso: PetscDSGetBoundary() 298958ebd649SToby Isaac @*/ 2990a30ec4eaSSatish 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) 299158ebd649SToby Isaac { 299258ebd649SToby Isaac DSBoundary b; 299358ebd649SToby Isaac PetscErrorCode ierr; 299458ebd649SToby Isaac 299558ebd649SToby Isaac PetscFunctionBegin; 299658ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 2997783e2ec8SMatthew G. Knepley PetscValidLogicalCollectiveEnum(ds, type, 2); 2998783e2ec8SMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, field, 5); 2999783e2ec8SMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, numcomps, 6); 3000783e2ec8SMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, numids, 9); 300158ebd649SToby Isaac ierr = PetscNew(&b);CHKERRQ(ierr); 300258ebd649SToby Isaac ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 300358ebd649SToby Isaac ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 300458ebd649SToby Isaac ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 3005580bdb30SBarry Smith if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);} 300658ebd649SToby Isaac ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 3007580bdb30SBarry Smith if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);} 3008f971fd6bSMatthew G. Knepley b->type = type; 300958ebd649SToby Isaac b->field = field; 301058ebd649SToby Isaac b->numcomps = numcomps; 301158ebd649SToby Isaac b->func = bcFunc; 301258ebd649SToby Isaac b->numids = numids; 301358ebd649SToby Isaac b->ctx = ctx; 301458ebd649SToby Isaac b->next = ds->boundary; 301558ebd649SToby Isaac ds->boundary = b; 301658ebd649SToby Isaac PetscFunctionReturn(0); 301758ebd649SToby Isaac } 301858ebd649SToby Isaac 3019b67eacb3SMatthew G. Knepley /*@C 3020b67eacb3SMatthew G. Knepley PetscDSUpdateBoundary - Change a boundary condition for the model 3021b67eacb3SMatthew G. Knepley 3022b67eacb3SMatthew G. Knepley Input Parameters: 3023b67eacb3SMatthew G. Knepley + ds - The PetscDS object 3024b67eacb3SMatthew G. Knepley . bd - The boundary condition number 3025b67eacb3SMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 3026b67eacb3SMatthew G. Knepley . name - The BC name 3027b67eacb3SMatthew G. Knepley . labelname - The label defining constrained points 3028b67eacb3SMatthew G. Knepley . field - The field to constrain 3029b67eacb3SMatthew G. Knepley . numcomps - The number of constrained field components 3030b67eacb3SMatthew G. Knepley . comps - An array of constrained component numbers 3031b67eacb3SMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 3032b67eacb3SMatthew G. Knepley . numids - The number of DMLabel ids for constrained points 3033b67eacb3SMatthew G. Knepley . ids - An array of ids for constrained points 3034b67eacb3SMatthew G. Knepley - ctx - An optional user context for bcFunc 3035b67eacb3SMatthew G. Knepley 30369a6efb6aSMatthew 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(). 30379a6efb6aSMatthew G. Knepley 3038b67eacb3SMatthew G. Knepley Level: developer 3039b67eacb3SMatthew G. Knepley 30409a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary() 3041b67eacb3SMatthew G. Knepley @*/ 3042b67eacb3SMatthew 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) 3043b67eacb3SMatthew G. Knepley { 3044b67eacb3SMatthew G. Knepley DSBoundary b = ds->boundary; 3045b67eacb3SMatthew G. Knepley PetscInt n = 0; 3046b67eacb3SMatthew G. Knepley PetscErrorCode ierr; 3047b67eacb3SMatthew G. Knepley 3048b67eacb3SMatthew G. Knepley PetscFunctionBegin; 3049b67eacb3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3050b67eacb3SMatthew G. Knepley while (b) { 3051b67eacb3SMatthew G. Knepley if (n == bd) break; 3052b67eacb3SMatthew G. Knepley b = b->next; 3053b67eacb3SMatthew G. Knepley ++n; 3054b67eacb3SMatthew G. Knepley } 3055b67eacb3SMatthew G. Knepley if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 3056b67eacb3SMatthew G. Knepley if (name) { 3057b67eacb3SMatthew G. Knepley ierr = PetscFree(b->name);CHKERRQ(ierr); 3058b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 3059b67eacb3SMatthew G. Knepley } 3060b67eacb3SMatthew G. Knepley if (labelname) { 3061b67eacb3SMatthew G. Knepley ierr = PetscFree(b->labelname);CHKERRQ(ierr); 3062b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 3063b67eacb3SMatthew G. Knepley } 3064b67eacb3SMatthew G. Knepley if (numcomps >= 0 && numcomps != b->numcomps) { 3065b67eacb3SMatthew G. Knepley b->numcomps = numcomps; 3066b67eacb3SMatthew G. Knepley ierr = PetscFree(b->comps);CHKERRQ(ierr); 3067b67eacb3SMatthew G. Knepley ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 3068580bdb30SBarry Smith if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);} 3069b67eacb3SMatthew G. Knepley } 3070b67eacb3SMatthew G. Knepley if (numids >= 0 && numids != b->numids) { 3071b67eacb3SMatthew G. Knepley b->numids = numids; 3072b67eacb3SMatthew G. Knepley ierr = PetscFree(b->ids);CHKERRQ(ierr); 3073b67eacb3SMatthew G. Knepley ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 3074580bdb30SBarry Smith if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);} 3075b67eacb3SMatthew G. Knepley } 3076b67eacb3SMatthew G. Knepley b->type = type; 3077b67eacb3SMatthew G. Knepley if (field >= 0) {b->field = field;} 3078b67eacb3SMatthew G. Knepley if (bcFunc) {b->func = bcFunc;} 3079b67eacb3SMatthew G. Knepley if (ctx) {b->ctx = ctx;} 3080b67eacb3SMatthew G. Knepley PetscFunctionReturn(0); 3081b67eacb3SMatthew G. Knepley } 3082b67eacb3SMatthew G. Knepley 308358ebd649SToby Isaac /*@ 308458ebd649SToby Isaac PetscDSGetNumBoundary - Get the number of registered BC 308558ebd649SToby Isaac 308658ebd649SToby Isaac Input Parameters: 308758ebd649SToby Isaac . ds - The PetscDS object 308858ebd649SToby Isaac 308958ebd649SToby Isaac Output Parameters: 309058ebd649SToby Isaac . numBd - The number of BC 309158ebd649SToby Isaac 309258ebd649SToby Isaac Level: intermediate 309358ebd649SToby Isaac 309458ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary() 309558ebd649SToby Isaac @*/ 309658ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd) 309758ebd649SToby Isaac { 309858ebd649SToby Isaac DSBoundary b = ds->boundary; 309958ebd649SToby Isaac 310058ebd649SToby Isaac PetscFunctionBegin; 310158ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 310258ebd649SToby Isaac PetscValidPointer(numBd, 2); 310358ebd649SToby Isaac *numBd = 0; 310458ebd649SToby Isaac while (b) {++(*numBd); b = b->next;} 310558ebd649SToby Isaac PetscFunctionReturn(0); 310658ebd649SToby Isaac } 310758ebd649SToby Isaac 310858ebd649SToby Isaac /*@C 31099a6efb6aSMatthew G. Knepley PetscDSGetBoundary - Gets a boundary condition to the model 311058ebd649SToby Isaac 311158ebd649SToby Isaac Input Parameters: 311258ebd649SToby Isaac + ds - The PetscDS object 311358ebd649SToby Isaac - bd - The BC number 311458ebd649SToby Isaac 311558ebd649SToby Isaac Output Parameters: 31162d47a189SJulian Andrej + type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 311758ebd649SToby Isaac . name - The BC name 311858ebd649SToby Isaac . labelname - The label defining constrained points 311958ebd649SToby Isaac . field - The field to constrain 312058ebd649SToby Isaac . numcomps - The number of constrained field components 312158ebd649SToby Isaac . comps - An array of constrained component numbers 312258ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 312358ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 312458ebd649SToby Isaac . ids - An array of ids for constrained points 312558ebd649SToby Isaac - ctx - An optional user context for bcFunc 312658ebd649SToby Isaac 312758ebd649SToby Isaac Options Database Keys: 312858ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 312958ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 313058ebd649SToby Isaac 313158ebd649SToby Isaac Level: developer 313258ebd649SToby Isaac 313358ebd649SToby Isaac .seealso: PetscDSAddBoundary() 313458ebd649SToby Isaac @*/ 3135a30ec4eaSSatish 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) 313658ebd649SToby Isaac { 313758ebd649SToby Isaac DSBoundary b = ds->boundary; 313858ebd649SToby Isaac PetscInt n = 0; 313958ebd649SToby Isaac 314058ebd649SToby Isaac PetscFunctionBegin; 314158ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 314258ebd649SToby Isaac while (b) { 314358ebd649SToby Isaac if (n == bd) break; 314458ebd649SToby Isaac b = b->next; 314558ebd649SToby Isaac ++n; 314658ebd649SToby Isaac } 314758ebd649SToby Isaac if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 3148f971fd6bSMatthew G. Knepley if (type) { 3149f971fd6bSMatthew G. Knepley PetscValidPointer(type, 3); 3150f971fd6bSMatthew G. Knepley *type = b->type; 315158ebd649SToby Isaac } 315258ebd649SToby Isaac if (name) { 315358ebd649SToby Isaac PetscValidPointer(name, 4); 315458ebd649SToby Isaac *name = b->name; 315558ebd649SToby Isaac } 315658ebd649SToby Isaac if (labelname) { 315758ebd649SToby Isaac PetscValidPointer(labelname, 5); 315858ebd649SToby Isaac *labelname = b->labelname; 315958ebd649SToby Isaac } 316058ebd649SToby Isaac if (field) { 316158ebd649SToby Isaac PetscValidPointer(field, 6); 316258ebd649SToby Isaac *field = b->field; 316358ebd649SToby Isaac } 316458ebd649SToby Isaac if (numcomps) { 316558ebd649SToby Isaac PetscValidPointer(numcomps, 7); 316658ebd649SToby Isaac *numcomps = b->numcomps; 316758ebd649SToby Isaac } 316858ebd649SToby Isaac if (comps) { 316958ebd649SToby Isaac PetscValidPointer(comps, 8); 317058ebd649SToby Isaac *comps = b->comps; 317158ebd649SToby Isaac } 317258ebd649SToby Isaac if (func) { 317358ebd649SToby Isaac PetscValidPointer(func, 9); 317458ebd649SToby Isaac *func = b->func; 317558ebd649SToby Isaac } 317658ebd649SToby Isaac if (numids) { 317758ebd649SToby Isaac PetscValidPointer(numids, 10); 317858ebd649SToby Isaac *numids = b->numids; 317958ebd649SToby Isaac } 318058ebd649SToby Isaac if (ids) { 318158ebd649SToby Isaac PetscValidPointer(ids, 11); 318258ebd649SToby Isaac *ids = b->ids; 318358ebd649SToby Isaac } 318458ebd649SToby Isaac if (ctx) { 318558ebd649SToby Isaac PetscValidPointer(ctx, 12); 318658ebd649SToby Isaac *ctx = b->ctx; 318758ebd649SToby Isaac } 318858ebd649SToby Isaac PetscFunctionReturn(0); 318958ebd649SToby Isaac } 319058ebd649SToby Isaac 31919252d075SMatthew G. Knepley /*@ 31929252d075SMatthew G. Knepley PetscDSCopyBoundary - Copy all boundary condition objects to the new problem 31939252d075SMatthew G. Knepley 31949252d075SMatthew G. Knepley Not collective 31959252d075SMatthew G. Knepley 31969252d075SMatthew G. Knepley Input Parameter: 31979252d075SMatthew G. Knepley . prob - The PetscDS object 31989252d075SMatthew G. Knepley 31999252d075SMatthew G. Knepley Output Parameter: 32009252d075SMatthew G. Knepley . newprob - The PetscDS copy 32019252d075SMatthew G. Knepley 32029252d075SMatthew G. Knepley Level: intermediate 32039252d075SMatthew G. Knepley 32049252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 32059252d075SMatthew G. Knepley @*/ 3206dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB) 3207dff059c6SToby Isaac { 3208dff059c6SToby Isaac DSBoundary b, next, *lastnext; 3209dff059c6SToby Isaac PetscErrorCode ierr; 3210dff059c6SToby Isaac 3211dff059c6SToby Isaac PetscFunctionBegin; 3212dff059c6SToby Isaac PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1); 3213dff059c6SToby Isaac PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2); 3214dff059c6SToby Isaac if (probA == probB) PetscFunctionReturn(0); 3215dff059c6SToby Isaac next = probB->boundary; 3216dff059c6SToby Isaac while (next) { 3217dff059c6SToby Isaac DSBoundary b = next; 3218dff059c6SToby Isaac 3219dff059c6SToby Isaac next = b->next; 3220dff059c6SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 3221dff059c6SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 3222dff059c6SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 3223dff059c6SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 3224dff059c6SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 3225dff059c6SToby Isaac } 3226dff059c6SToby Isaac lastnext = &(probB->boundary); 3227dff059c6SToby Isaac for (b = probA->boundary; b; b = b->next) { 3228dff059c6SToby Isaac DSBoundary bNew; 3229dff059c6SToby Isaac 3230459726d8SSatish Balay ierr = PetscNew(&bNew);CHKERRQ(ierr); 3231dff059c6SToby Isaac bNew->numcomps = b->numcomps; 3232dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr); 3233580bdb30SBarry Smith ierr = PetscArraycpy(bNew->comps, b->comps, bNew->numcomps);CHKERRQ(ierr); 3234dff059c6SToby Isaac bNew->numids = b->numids; 3235dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr); 3236580bdb30SBarry Smith ierr = PetscArraycpy(bNew->ids, b->ids, bNew->numids);CHKERRQ(ierr); 3237dff059c6SToby Isaac ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr); 3238dff059c6SToby Isaac ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr); 3239dff059c6SToby Isaac bNew->ctx = b->ctx; 3240f971fd6bSMatthew G. Knepley bNew->type = b->type; 3241dff059c6SToby Isaac bNew->field = b->field; 3242dff059c6SToby Isaac bNew->func = b->func; 3243dff059c6SToby Isaac 3244dff059c6SToby Isaac *lastnext = bNew; 3245dff059c6SToby Isaac lastnext = &(bNew->next); 3246dff059c6SToby Isaac } 3247dff059c6SToby Isaac PetscFunctionReturn(0); 3248dff059c6SToby Isaac } 3249dff059c6SToby Isaac 32509252d075SMatthew G. Knepley /*@C 32519252d075SMatthew G. Knepley PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout 32529252d075SMatthew G. Knepley 32539252d075SMatthew G. Knepley Not collective 32549252d075SMatthew G. Knepley 32559252d075SMatthew G. Knepley Input Parameter: 32569252d075SMatthew G. Knepley + prob - The PetscDS object 32579252d075SMatthew G. Knepley . numFields - Number of new fields 32589252d075SMatthew G. Knepley - fields - Old field number for each new field 32599252d075SMatthew G. Knepley 32609252d075SMatthew G. Knepley Output Parameter: 32619252d075SMatthew G. Knepley . newprob - The PetscDS copy 32629252d075SMatthew G. Knepley 32639252d075SMatthew G. Knepley Level: intermediate 32649252d075SMatthew G. Knepley 32659252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 32669252d075SMatthew G. Knepley @*/ 32679252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 32689252d075SMatthew G. Knepley { 32699252d075SMatthew G. Knepley PetscInt Nf, Nfn, fn, gn; 32709252d075SMatthew G. Knepley PetscErrorCode ierr; 32719252d075SMatthew G. Knepley 32729252d075SMatthew G. Knepley PetscFunctionBegin; 32739252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 32749252d075SMatthew G. Knepley if (fields) PetscValidPointer(fields, 3); 32759252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 32769252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 32779252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr); 32789252d075SMatthew 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); 32799252d075SMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 32809252d075SMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 32819252d075SMatthew G. Knepley PetscPointFunc obj; 32829252d075SMatthew G. Knepley PetscPointFunc f0, f1; 32839252d075SMatthew G. Knepley PetscBdPointFunc f0Bd, f1Bd; 32849252d075SMatthew G. Knepley PetscRiemannFunc r; 32859252d075SMatthew G. Knepley 3286c52f1e13SMatthew G. Knepley if (f >= Nf) continue; 32879252d075SMatthew G. Knepley ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr); 32889252d075SMatthew G. Knepley ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr); 32899252d075SMatthew G. Knepley ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr); 32909252d075SMatthew G. Knepley ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr); 32919252d075SMatthew G. Knepley ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr); 32929252d075SMatthew G. Knepley ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr); 32939252d075SMatthew G. Knepley ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr); 32949252d075SMatthew G. Knepley ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr); 32959252d075SMatthew G. Knepley for (gn = 0; gn < numFields; ++gn) { 32969252d075SMatthew G. Knepley const PetscInt g = fields ? fields[gn] : gn; 32979252d075SMatthew G. Knepley PetscPointJac g0, g1, g2, g3; 32989252d075SMatthew G. Knepley PetscPointJac g0p, g1p, g2p, g3p; 32999252d075SMatthew G. Knepley PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd; 33009252d075SMatthew G. Knepley 3301c52f1e13SMatthew G. Knepley if (g >= Nf) continue; 33029252d075SMatthew G. Knepley ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr); 33039252d075SMatthew G. Knepley ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr); 33049252d075SMatthew G. Knepley ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr); 33059252d075SMatthew G. Knepley ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr); 33069252d075SMatthew G. Knepley ierr = PetscDSSetJacobianPreconditioner(prob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr); 33079252d075SMatthew G. Knepley ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr); 33089252d075SMatthew G. Knepley } 33099252d075SMatthew G. Knepley } 33109252d075SMatthew G. Knepley PetscFunctionReturn(0); 33119252d075SMatthew G. Knepley } 33129252d075SMatthew G. Knepley 3313da51fcedSMatthew G. Knepley /*@ 3314da51fcedSMatthew G. Knepley PetscDSCopyEquations - Copy all pointwise function pointers to the new problem 3315da51fcedSMatthew G. Knepley 3316da51fcedSMatthew G. Knepley Not collective 3317da51fcedSMatthew G. Knepley 3318da51fcedSMatthew G. Knepley Input Parameter: 3319da51fcedSMatthew G. Knepley . prob - The PetscDS object 3320da51fcedSMatthew G. Knepley 3321da51fcedSMatthew G. Knepley Output Parameter: 3322da51fcedSMatthew G. Knepley . newprob - The PetscDS copy 3323da51fcedSMatthew G. Knepley 3324da51fcedSMatthew G. Knepley Level: intermediate 3325da51fcedSMatthew G. Knepley 33269252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 3327da51fcedSMatthew G. Knepley @*/ 3328da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob) 3329da51fcedSMatthew G. Knepley { 33309252d075SMatthew G. Knepley PetscInt Nf, Ng; 3331da51fcedSMatthew G. Knepley PetscErrorCode ierr; 3332da51fcedSMatthew G. Knepley 3333da51fcedSMatthew G. Knepley PetscFunctionBegin; 3334da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3335da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 3336da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3337da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr); 333813903a91SSatish Balay if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng); 33399252d075SMatthew G. Knepley ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr); 33409252d075SMatthew G. Knepley PetscFunctionReturn(0); 33419252d075SMatthew G. Knepley } 33429252d075SMatthew G. Knepley /*@ 33439252d075SMatthew G. Knepley PetscDSCopyConstants - Copy all constants to the new problem 3344da51fcedSMatthew G. Knepley 33459252d075SMatthew G. Knepley Not collective 33469252d075SMatthew G. Knepley 33479252d075SMatthew G. Knepley Input Parameter: 33489252d075SMatthew G. Knepley . prob - The PetscDS object 33499252d075SMatthew G. Knepley 33509252d075SMatthew G. Knepley Output Parameter: 33519252d075SMatthew G. Knepley . newprob - The PetscDS copy 33529252d075SMatthew G. Knepley 33539252d075SMatthew G. Knepley Level: intermediate 33549252d075SMatthew G. Knepley 33559252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 33569252d075SMatthew G. Knepley @*/ 33579252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob) 33589252d075SMatthew G. Knepley { 33599252d075SMatthew G. Knepley PetscInt Nc; 33609252d075SMatthew G. Knepley const PetscScalar *constants; 33619252d075SMatthew G. Knepley PetscErrorCode ierr; 33629252d075SMatthew G. Knepley 33639252d075SMatthew G. Knepley PetscFunctionBegin; 33649252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 33659252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 33669252d075SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr); 33679252d075SMatthew G. Knepley ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr); 3368da51fcedSMatthew G. Knepley PetscFunctionReturn(0); 3369da51fcedSMatthew G. Knepley } 3370da51fcedSMatthew G. Knepley 3371b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob) 3372b1353e8eSMatthew G. Knepley { 3373df3a45bdSMatthew G. Knepley PetscInt dim, Nf, f; 3374b1353e8eSMatthew G. Knepley PetscErrorCode ierr; 3375b1353e8eSMatthew G. Knepley 3376b1353e8eSMatthew G. Knepley PetscFunctionBegin; 3377b1353e8eSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3378b1353e8eSMatthew G. Knepley PetscValidPointer(subprob, 3); 3379b1353e8eSMatthew G. Knepley if (height == 0) {*subprob = prob; PetscFunctionReturn(0);} 3380b1353e8eSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3381df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 3382df3a45bdSMatthew 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); 3383df3a45bdSMatthew G. Knepley if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);} 3384df3a45bdSMatthew G. Knepley if (!prob->subprobs[height-1]) { 3385b1353e8eSMatthew G. Knepley PetscInt cdim; 3386b1353e8eSMatthew G. Knepley 3387df3a45bdSMatthew G. Knepley ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr); 3388b1353e8eSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr); 3389df3a45bdSMatthew G. Knepley ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr); 3390b1353e8eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3391b1353e8eSMatthew G. Knepley PetscFE subfe; 3392b1353e8eSMatthew G. Knepley PetscObject obj; 3393b1353e8eSMatthew G. Knepley PetscClassId id; 3394b1353e8eSMatthew G. Knepley 3395b1353e8eSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 3396b1353e8eSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3397b1353e8eSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);} 3398b1353e8eSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f); 3399df3a45bdSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr); 3400b1353e8eSMatthew G. Knepley } 3401b1353e8eSMatthew G. Knepley } 3402df3a45bdSMatthew G. Knepley *subprob = prob->subprobs[height-1]; 3403b1353e8eSMatthew G. Knepley PetscFunctionReturn(0); 3404b1353e8eSMatthew G. Knepley } 3405b1353e8eSMatthew G. Knepley 3406665f567fSMatthew G. Knepley PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype) 3407c7bd5f0bSMatthew G. Knepley { 3408c7bd5f0bSMatthew G. Knepley PetscObject obj; 3409c7bd5f0bSMatthew G. Knepley PetscClassId id; 3410c7bd5f0bSMatthew G. Knepley PetscInt Nf; 3411c7bd5f0bSMatthew G. Knepley PetscErrorCode ierr; 3412c7bd5f0bSMatthew G. Knepley 3413c7bd5f0bSMatthew G. Knepley PetscFunctionBegin; 3414c7bd5f0bSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3415665f567fSMatthew G. Knepley PetscValidPointer(disctype, 3); 3416665f567fSMatthew G. Knepley *disctype = PETSC_DISC_NONE; 3417c7bd5f0bSMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 3418c7bd5f0bSMatthew G. Knepley if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf); 3419c7bd5f0bSMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr); 3420665f567fSMatthew G. Knepley if (obj) { 3421c7bd5f0bSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3422665f567fSMatthew G. Knepley if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE; 3423665f567fSMatthew G. Knepley else *disctype = PETSC_DISC_FV; 3424665f567fSMatthew G. Knepley } 3425c7bd5f0bSMatthew G. Knepley PetscFunctionReturn(0); 3426c7bd5f0bSMatthew G. Knepley } 3427c7bd5f0bSMatthew G. Knepley 3428bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob) 34292764a2aaSMatthew G. Knepley { 3430931fb3b8SToby Isaac PetscErrorCode ierr; 3431931fb3b8SToby Isaac 34322764a2aaSMatthew G. Knepley PetscFunctionBegin; 3433931fb3b8SToby Isaac ierr = PetscFree(prob->data);CHKERRQ(ierr); 34342764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 34352764a2aaSMatthew G. Knepley } 34362764a2aaSMatthew G. Knepley 3437bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob) 34382764a2aaSMatthew G. Knepley { 34392764a2aaSMatthew G. Knepley PetscFunctionBegin; 34402764a2aaSMatthew G. Knepley prob->ops->setfromoptions = NULL; 34412764a2aaSMatthew G. Knepley prob->ops->setup = NULL; 34422764a2aaSMatthew G. Knepley prob->ops->view = NULL; 34432764a2aaSMatthew G. Knepley prob->ops->destroy = PetscDSDestroy_Basic; 34442764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 34452764a2aaSMatthew G. Knepley } 34462764a2aaSMatthew G. Knepley 34472764a2aaSMatthew G. Knepley /*MC 34482764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 34492764a2aaSMatthew G. Knepley 34502764a2aaSMatthew G. Knepley Level: intermediate 34512764a2aaSMatthew G. Knepley 34522764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType() 34532764a2aaSMatthew G. Knepley M*/ 34542764a2aaSMatthew G. Knepley 34552764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob) 34562764a2aaSMatthew G. Knepley { 34572764a2aaSMatthew G. Knepley PetscDS_Basic *b; 34582764a2aaSMatthew G. Knepley PetscErrorCode ierr; 34592764a2aaSMatthew G. Knepley 34602764a2aaSMatthew G. Knepley PetscFunctionBegin; 3461931fb3b8SToby Isaac PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 34622764a2aaSMatthew G. Knepley ierr = PetscNewLog(prob, &b);CHKERRQ(ierr); 34632764a2aaSMatthew G. Knepley prob->data = b; 34642764a2aaSMatthew G. Knepley 34652764a2aaSMatthew G. Knepley ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr); 34662764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 34672764a2aaSMatthew G. Knepley } 3468