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); 381*ef0bb6c7SMatthew 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; 3852764a2aaSMatthew G. Knepley PetscQuadrature q; 3869de99aefSMatthew G. Knepley PetscInt Nq = 0, Nb, Nc; 3872764a2aaSMatthew G. Knepley 3889de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 3899de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3909de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 3919de99aefSMatthew G. Knepley PetscFE fe = (PetscFE) obj; 3929de99aefSMatthew G. Knepley 3932764a2aaSMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr); 3942764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 3952764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 396*ef0bb6c7SMatthew G. Knepley ierr = PetscFEGetCellTabulation(fe, &prob->T[f]);CHKERRQ(ierr); 397*ef0bb6c7SMatthew G. Knepley ierr = PetscFEGetFaceTabulation(fe, &prob->Tf[f]);CHKERRQ(ierr); 3989de99aefSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 3999de99aefSMatthew G. Knepley PetscFV fv = (PetscFV) obj; 4009de99aefSMatthew G. Knepley 4019de99aefSMatthew G. Knepley ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr); 4029de99aefSMatthew G. Knepley ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr); 4039c3cf19fSMatthew G. Knepley Nb = Nc; 404*ef0bb6c7SMatthew G. Knepley ierr = PetscFVGetCellTabulation(fv, &prob->T[f]);CHKERRQ(ierr); 4054d0b9603SSander Arens /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */ 406abac5ca0SMatthew G. Knepley } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f); 40747e57110SSander Arens prob->Nc[f] = Nc; 40847e57110SSander Arens prob->Nb[f] = Nb; 409194d53e6SMatthew G. Knepley prob->off[f+1] = Nc + prob->off[f]; 410194d53e6SMatthew G. Knepley prob->offDer[f+1] = Nc*dim + prob->offDer[f]; 411a6b92713SMatthew G. Knepley if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);} 4122764a2aaSMatthew G. Knepley NqMax = PetscMax(NqMax, Nq); 4134bee2e38SMatthew G. Knepley NbMax = PetscMax(NbMax, Nb); 4142764a2aaSMatthew G. Knepley NcMax = PetscMax(NcMax, Nc); 4159c3cf19fSMatthew G. Knepley prob->totDim += Nb; 4162764a2aaSMatthew G. Knepley prob->totComp += Nc; 41794a5e212SMatthew G. Knepley /* There are two faces for all fields but the cohesive field on a hybrid cell */ 41894a5e212SMatthew G. Knepley if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb; 4192764a2aaSMatthew G. Knepley } 4202764a2aaSMatthew G. Knepley /* Allocate works space */ 42194a5e212SMatthew G. Knepley if (prob->isHybrid) NsMax = 2; 4224bee2e38SMatthew G. Knepley ierr = PetscMalloc3(NsMax*prob->totComp,&prob->u,NsMax*prob->totComp,&prob->u_t,NsMax*prob->totComp*dimEmbed,&prob->u_x);CHKERRQ(ierr); 4234bee2e38SMatthew 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); 42494a5e212SMatthew G. Knepley ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dim,&prob->f1, 42594a5e212SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dim,&prob->g1, 42694a5e212SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax*dim,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dim*dim,&prob->g3);CHKERRQ(ierr); 4272764a2aaSMatthew G. Knepley if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);} 4282764a2aaSMatthew G. Knepley prob->setup = PETSC_TRUE; 4292764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4302764a2aaSMatthew G. Knepley } 4312764a2aaSMatthew G. Knepley 4322764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob) 4332764a2aaSMatthew G. Knepley { 4342764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4352764a2aaSMatthew G. Knepley 4362764a2aaSMatthew G. Knepley PetscFunctionBegin; 43747e57110SSander Arens ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr); 438f744cafaSSander Arens ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr); 439*ef0bb6c7SMatthew G. Knepley ierr = PetscFree2(prob->T,prob->Tf);CHKERRQ(ierr); 4404bee2e38SMatthew G. Knepley ierr = PetscFree3(prob->u,prob->u_t,prob->u_x);CHKERRQ(ierr); 4414bee2e38SMatthew G. Knepley ierr = PetscFree5(prob->x,prob->basisReal, prob->basisDerReal,prob->testReal,prob->testDerReal);CHKERRQ(ierr); 4422764a2aaSMatthew G. Knepley ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr); 4432764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4442764a2aaSMatthew G. Knepley } 4452764a2aaSMatthew G. Knepley 4462764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew) 4472764a2aaSMatthew G. Knepley { 448f744cafaSSander Arens PetscObject *tmpd; 44934aa8a36SMatthew G. Knepley PetscBool *tmpi; 45032d2bbc9SMatthew G. Knepley PetscPointFunc *tmpobj, *tmpf, *tmpup; 451b7e05686SMatthew G. Knepley PetscPointJac *tmpg, *tmpgp, *tmpgt; 4522aa1fc23SMatthew G. Knepley PetscBdPointFunc *tmpfbd; 4532aa1fc23SMatthew G. Knepley PetscBdPointJac *tmpgbd; 454194d53e6SMatthew G. Knepley PetscRiemannFunc *tmpr; 455c371a6d1SMatthew G. Knepley PetscSimplePointFunc *tmpexactSol; 45695cbbfd3SMatthew G. Knepley void **tmpexactCtx; 4570c2f2876SMatthew G. Knepley void **tmpctx; 45834aa8a36SMatthew G. Knepley PetscInt Nf = prob->Nf, f; 4592764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4602764a2aaSMatthew G. Knepley 4612764a2aaSMatthew G. Knepley PetscFunctionBegin; 4622764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 4632764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 4642764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr); 46534aa8a36SMatthew G. Knepley ierr = PetscMalloc2(NfNew, &tmpd, NfNew, &tmpi);CHKERRQ(ierr); 46634aa8a36SMatthew G. Knepley for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f];} 46734aa8a36SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE;} 46834aa8a36SMatthew G. Knepley ierr = PetscFree2(prob->disc, prob->implicit);CHKERRQ(ierr); 4692764a2aaSMatthew G. Knepley prob->Nf = NfNew; 4702764a2aaSMatthew G. Knepley prob->disc = tmpd; 471249df284SMatthew G. Knepley prob->implicit = tmpi; 472b7e05686SMatthew 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); 47332d2bbc9SMatthew G. Knepley ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr); 4742764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f]; 4752764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f]; 4762764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f]; 477475e0ac9SMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f]; 4780c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f]; 47932d2bbc9SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f]; 4800c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f]; 4812764a2aaSMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL; 4822764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL; 4832764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL; 484475e0ac9SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL; 485b7e05686SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL; 4860c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL; 48732d2bbc9SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL; 4880c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL; 489b7e05686SMatthew G. Knepley ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr); 49032d2bbc9SMatthew G. Knepley ierr = PetscFree(prob->update);CHKERRQ(ierr); 4912764a2aaSMatthew G. Knepley prob->obj = tmpobj; 4922764a2aaSMatthew G. Knepley prob->f = tmpf; 4932764a2aaSMatthew G. Knepley prob->g = tmpg; 494475e0ac9SMatthew G. Knepley prob->gp = tmpgp; 495b7e05686SMatthew G. Knepley prob->gt = tmpgt; 4960c2f2876SMatthew G. Knepley prob->r = tmpr; 49732d2bbc9SMatthew G. Knepley prob->update = tmpup; 4980c2f2876SMatthew G. Knepley prob->ctx = tmpctx; 49995cbbfd3SMatthew G. Knepley ierr = PetscCalloc4(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew, &tmpexactSol, NfNew, &tmpexactCtx);CHKERRQ(ierr); 5002764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f]; 5012764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f]; 502c371a6d1SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f]; 50395cbbfd3SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f]; 5042764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL; 5052764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL; 506c371a6d1SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL; 50795cbbfd3SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL; 50895cbbfd3SMatthew G. Knepley ierr = PetscFree4(prob->fBd, prob->gBd, prob->exactSol, prob->exactCtx);CHKERRQ(ierr); 5092764a2aaSMatthew G. Knepley prob->fBd = tmpfbd; 5102764a2aaSMatthew G. Knepley prob->gBd = tmpgbd; 511c371a6d1SMatthew G. Knepley prob->exactSol = tmpexactSol; 51295cbbfd3SMatthew G. Knepley prob->exactCtx = tmpexactCtx; 5132764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5142764a2aaSMatthew G. Knepley } 5152764a2aaSMatthew G. Knepley 5162764a2aaSMatthew G. Knepley /*@ 5172764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 5182764a2aaSMatthew G. Knepley 519d083f849SBarry Smith Collective on prob 5202764a2aaSMatthew G. Knepley 5212764a2aaSMatthew G. Knepley Input Parameter: 5222764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 5232764a2aaSMatthew G. Knepley 5242764a2aaSMatthew G. Knepley Level: developer 5252764a2aaSMatthew G. Knepley 5262764a2aaSMatthew G. Knepley .seealso PetscDSView() 5272764a2aaSMatthew G. Knepley @*/ 5282764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob) 5292764a2aaSMatthew G. Knepley { 5302764a2aaSMatthew G. Knepley PetscInt f; 53158ebd649SToby Isaac DSBoundary next; 5322764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5332764a2aaSMatthew G. Knepley 5342764a2aaSMatthew G. Knepley PetscFunctionBegin; 5352764a2aaSMatthew G. Knepley if (!*prob) PetscFunctionReturn(0); 5362764a2aaSMatthew G. Knepley PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1); 5372764a2aaSMatthew G. Knepley 5382764a2aaSMatthew G. Knepley if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);} 5392764a2aaSMatthew G. Knepley ((PetscObject) (*prob))->refct = 0; 540df3a45bdSMatthew G. Knepley if ((*prob)->subprobs) { 541df3a45bdSMatthew G. Knepley PetscInt dim, d; 542df3a45bdSMatthew G. Knepley 543df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(*prob, &dim);CHKERRQ(ierr); 544df3a45bdSMatthew G. Knepley for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*prob)->subprobs[d]);CHKERRQ(ierr);} 545df3a45bdSMatthew G. Knepley } 546df3a45bdSMatthew G. Knepley ierr = PetscFree((*prob)->subprobs);CHKERRQ(ierr); 5472764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr); 5482764a2aaSMatthew G. Knepley for (f = 0; f < (*prob)->Nf; ++f) { 5492764a2aaSMatthew G. Knepley ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr); 5502764a2aaSMatthew G. Knepley } 55134aa8a36SMatthew G. Knepley ierr = PetscFree2((*prob)->disc, (*prob)->implicit);CHKERRQ(ierr); 552b7e05686SMatthew G. Knepley ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr); 55332d2bbc9SMatthew G. Knepley ierr = PetscFree((*prob)->update);CHKERRQ(ierr); 55495cbbfd3SMatthew G. Knepley ierr = PetscFree4((*prob)->fBd,(*prob)->gBd,(*prob)->exactSol,(*prob)->exactCtx);CHKERRQ(ierr); 5552764a2aaSMatthew G. Knepley if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);} 55658ebd649SToby Isaac next = (*prob)->boundary; 55758ebd649SToby Isaac while (next) { 55858ebd649SToby Isaac DSBoundary b = next; 55958ebd649SToby Isaac 56058ebd649SToby Isaac next = b->next; 56158ebd649SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 56258ebd649SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 56358ebd649SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 56458ebd649SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 56558ebd649SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 56658ebd649SToby Isaac } 56797b6e6e8SMatthew G. Knepley ierr = PetscFree((*prob)->constants);CHKERRQ(ierr); 5682764a2aaSMatthew G. Knepley ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr); 5692764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5702764a2aaSMatthew G. Knepley } 5712764a2aaSMatthew G. Knepley 5722764a2aaSMatthew G. Knepley /*@ 5732764a2aaSMatthew G. Knepley PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType(). 5742764a2aaSMatthew G. Knepley 575d083f849SBarry Smith Collective 5762764a2aaSMatthew G. Knepley 5772764a2aaSMatthew G. Knepley Input Parameter: 5782764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object 5792764a2aaSMatthew G. Knepley 5802764a2aaSMatthew G. Knepley Output Parameter: 5812764a2aaSMatthew G. Knepley . prob - The PetscDS object 5822764a2aaSMatthew G. Knepley 5832764a2aaSMatthew G. Knepley Level: beginner 5842764a2aaSMatthew G. Knepley 5852764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC 5862764a2aaSMatthew G. Knepley @*/ 5872764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob) 5882764a2aaSMatthew G. Knepley { 5892764a2aaSMatthew G. Knepley PetscDS p; 5902764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5912764a2aaSMatthew G. Knepley 5922764a2aaSMatthew G. Knepley PetscFunctionBegin; 5932764a2aaSMatthew G. Knepley PetscValidPointer(prob, 2); 5942764a2aaSMatthew G. Knepley *prob = NULL; 5952764a2aaSMatthew G. Knepley ierr = PetscDSInitializePackage();CHKERRQ(ierr); 5962764a2aaSMatthew G. Knepley 59773107ff1SLisandro Dalcin ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr); 5982764a2aaSMatthew G. Knepley 5992764a2aaSMatthew G. Knepley p->Nf = 0; 6002764a2aaSMatthew G. Knepley p->setup = PETSC_FALSE; 60197b6e6e8SMatthew G. Knepley p->numConstants = 0; 60297b6e6e8SMatthew G. Knepley p->constants = NULL; 603a859676bSMatthew G. Knepley p->dimEmbed = -1; 60455c1f793SMatthew G. Knepley p->useJacPre = PETSC_TRUE; 6052764a2aaSMatthew G. Knepley 6062764a2aaSMatthew G. Knepley *prob = p; 6072764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6082764a2aaSMatthew G. Knepley } 6092764a2aaSMatthew G. Knepley 610bc4ae4beSMatthew G. Knepley /*@ 611bc4ae4beSMatthew G. Knepley PetscDSGetNumFields - Returns the number of fields in the DS 612bc4ae4beSMatthew G. Knepley 613bc4ae4beSMatthew G. Knepley Not collective 614bc4ae4beSMatthew G. Knepley 615bc4ae4beSMatthew G. Knepley Input Parameter: 616bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 617bc4ae4beSMatthew G. Knepley 618bc4ae4beSMatthew G. Knepley Output Parameter: 619bc4ae4beSMatthew G. Knepley . Nf - The number of fields 620bc4ae4beSMatthew G. Knepley 621bc4ae4beSMatthew G. Knepley Level: beginner 622bc4ae4beSMatthew G. Knepley 623bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate() 624bc4ae4beSMatthew G. Knepley @*/ 6252764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) 6262764a2aaSMatthew G. Knepley { 6272764a2aaSMatthew G. Knepley PetscFunctionBegin; 6282764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6292764a2aaSMatthew G. Knepley PetscValidPointer(Nf, 2); 6302764a2aaSMatthew G. Knepley *Nf = prob->Nf; 6312764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6322764a2aaSMatthew G. Knepley } 6332764a2aaSMatthew G. Knepley 634bc4ae4beSMatthew G. Knepley /*@ 635a859676bSMatthew G. Knepley PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations 636bc4ae4beSMatthew G. Knepley 637bc4ae4beSMatthew G. Knepley Not collective 638bc4ae4beSMatthew G. Knepley 639bc4ae4beSMatthew G. Knepley Input Parameter: 640bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 641bc4ae4beSMatthew G. Knepley 642bc4ae4beSMatthew G. Knepley Output Parameter: 643bc4ae4beSMatthew G. Knepley . dim - The spatial dimension 644bc4ae4beSMatthew G. Knepley 645bc4ae4beSMatthew G. Knepley Level: beginner 646bc4ae4beSMatthew G. Knepley 647a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate() 648bc4ae4beSMatthew G. Knepley @*/ 6492764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) 6502764a2aaSMatthew G. Knepley { 6512764a2aaSMatthew G. Knepley PetscErrorCode ierr; 6522764a2aaSMatthew G. Knepley 6532764a2aaSMatthew G. Knepley PetscFunctionBegin; 6542764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6552764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 6562764a2aaSMatthew G. Knepley *dim = 0; 6579de99aefSMatthew G. Knepley if (prob->Nf) { 6589de99aefSMatthew G. Knepley PetscObject obj; 6599de99aefSMatthew G. Knepley PetscClassId id; 6609de99aefSMatthew G. Knepley 6619de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 6629de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 6639de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);} 6649de99aefSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);} 6659de99aefSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 6669de99aefSMatthew G. Knepley } 6672764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6682764a2aaSMatthew G. Knepley } 6692764a2aaSMatthew G. Knepley 670bc4ae4beSMatthew G. Knepley /*@ 671a859676bSMatthew G. Knepley PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 672a859676bSMatthew G. Knepley 673a859676bSMatthew G. Knepley Not collective 674a859676bSMatthew G. Knepley 675a859676bSMatthew G. Knepley Input Parameter: 676a859676bSMatthew G. Knepley . prob - The PetscDS object 677a859676bSMatthew G. Knepley 678a859676bSMatthew G. Knepley Output Parameter: 679a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension 680a859676bSMatthew G. Knepley 681a859676bSMatthew G. Knepley Level: beginner 682a859676bSMatthew G. Knepley 683a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 684a859676bSMatthew G. Knepley @*/ 685a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed) 686a859676bSMatthew G. Knepley { 687a859676bSMatthew G. Knepley PetscFunctionBegin; 688a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 689a859676bSMatthew G. Knepley PetscValidPointer(dimEmbed, 2); 690a859676bSMatthew G. Knepley if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS"); 691a859676bSMatthew G. Knepley *dimEmbed = prob->dimEmbed; 692a859676bSMatthew G. Knepley PetscFunctionReturn(0); 693a859676bSMatthew G. Knepley } 694a859676bSMatthew G. Knepley 695a859676bSMatthew G. Knepley /*@ 696a859676bSMatthew G. Knepley PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 697a859676bSMatthew G. Knepley 698d083f849SBarry Smith Logically collective on prob 699a859676bSMatthew G. Knepley 700a859676bSMatthew G. Knepley Input Parameters: 701a859676bSMatthew G. Knepley + prob - The PetscDS object 702a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension 703a859676bSMatthew G. Knepley 704a859676bSMatthew G. Knepley Level: beginner 705a859676bSMatthew G. Knepley 706a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 707a859676bSMatthew G. Knepley @*/ 708a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed) 709a859676bSMatthew G. Knepley { 710a859676bSMatthew G. Knepley PetscFunctionBegin; 711a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 712ebfe4b0dSMatthew G. Knepley if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed); 713a859676bSMatthew G. Knepley prob->dimEmbed = dimEmbed; 714a859676bSMatthew G. Knepley PetscFunctionReturn(0); 715a859676bSMatthew G. Knepley } 716a859676bSMatthew G. Knepley 717a859676bSMatthew G. Knepley /*@ 7188edf6225SMatthew G. Knepley PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell 7198edf6225SMatthew G. Knepley 7208edf6225SMatthew G. Knepley Not collective 7218edf6225SMatthew G. Knepley 7228edf6225SMatthew G. Knepley Input Parameter: 7238edf6225SMatthew G. Knepley . prob - The PetscDS object 7248edf6225SMatthew G. Knepley 7258edf6225SMatthew G. Knepley Output Parameter: 7268edf6225SMatthew G. Knepley . isHybrid - The flag 7278edf6225SMatthew G. Knepley 7288edf6225SMatthew G. Knepley Level: developer 7298edf6225SMatthew G. Knepley 7308edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate() 7318edf6225SMatthew G. Knepley @*/ 7328edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid) 7338edf6225SMatthew G. Knepley { 7348edf6225SMatthew G. Knepley PetscFunctionBegin; 7358edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7368edf6225SMatthew G. Knepley PetscValidPointer(isHybrid, 2); 7378edf6225SMatthew G. Knepley *isHybrid = prob->isHybrid; 7388edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7398edf6225SMatthew G. Knepley } 7408edf6225SMatthew G. Knepley 7418edf6225SMatthew G. Knepley /*@ 7428edf6225SMatthew G. Knepley PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell 7438edf6225SMatthew G. Knepley 7448edf6225SMatthew G. Knepley Not collective 7458edf6225SMatthew G. Knepley 7468edf6225SMatthew G. Knepley Input Parameters: 7478edf6225SMatthew G. Knepley + prob - The PetscDS object 7488edf6225SMatthew G. Knepley - isHybrid - The flag 7498edf6225SMatthew G. Knepley 7508edf6225SMatthew G. Knepley Level: developer 7518edf6225SMatthew G. Knepley 7528edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate() 7538edf6225SMatthew G. Knepley @*/ 7548edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid) 7558edf6225SMatthew G. Knepley { 7568edf6225SMatthew G. Knepley PetscFunctionBegin; 7578edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7588edf6225SMatthew G. Knepley prob->isHybrid = isHybrid; 7598edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7608edf6225SMatthew G. Knepley } 7618edf6225SMatthew G. Knepley 7628edf6225SMatthew G. Knepley /*@ 763bc4ae4beSMatthew G. Knepley PetscDSGetTotalDimension - Returns the total size of the approximation space for this system 764bc4ae4beSMatthew G. Knepley 765bc4ae4beSMatthew G. Knepley Not collective 766bc4ae4beSMatthew G. Knepley 767bc4ae4beSMatthew G. Knepley Input Parameter: 768bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 769bc4ae4beSMatthew G. Knepley 770bc4ae4beSMatthew G. Knepley Output Parameter: 771bc4ae4beSMatthew G. Knepley . dim - The total problem dimension 772bc4ae4beSMatthew G. Knepley 773bc4ae4beSMatthew G. Knepley Level: beginner 774bc4ae4beSMatthew G. Knepley 775bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 776bc4ae4beSMatthew G. Knepley @*/ 7772764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) 7782764a2aaSMatthew G. Knepley { 7792764a2aaSMatthew G. Knepley PetscErrorCode ierr; 7802764a2aaSMatthew G. Knepley 7812764a2aaSMatthew G. Knepley PetscFunctionBegin; 7822764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7832764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 7842764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 7852764a2aaSMatthew G. Knepley *dim = prob->totDim; 7862764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 7872764a2aaSMatthew G. Knepley } 7882764a2aaSMatthew G. Knepley 789bc4ae4beSMatthew G. Knepley /*@ 790bc4ae4beSMatthew G. Knepley PetscDSGetTotalComponents - Returns the total number of components in this system 791bc4ae4beSMatthew G. Knepley 792bc4ae4beSMatthew G. Knepley Not collective 793bc4ae4beSMatthew G. Knepley 794bc4ae4beSMatthew G. Knepley Input Parameter: 795bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 796bc4ae4beSMatthew G. Knepley 797bc4ae4beSMatthew G. Knepley Output Parameter: 798bc4ae4beSMatthew G. Knepley . dim - The total number of components 799bc4ae4beSMatthew G. Knepley 800bc4ae4beSMatthew G. Knepley Level: beginner 801bc4ae4beSMatthew G. Knepley 802bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 803bc4ae4beSMatthew G. Knepley @*/ 8042764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) 8052764a2aaSMatthew G. Knepley { 8062764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8072764a2aaSMatthew G. Knepley 8082764a2aaSMatthew G. Knepley PetscFunctionBegin; 8092764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8102764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 8112764a2aaSMatthew G. Knepley PetscValidPointer(Nc, 2); 8122764a2aaSMatthew G. Knepley *Nc = prob->totComp; 8132764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8142764a2aaSMatthew G. Knepley } 8152764a2aaSMatthew G. Knepley 816bc4ae4beSMatthew G. Knepley /*@ 817bc4ae4beSMatthew G. Knepley PetscDSGetDiscretization - Returns the discretization object for the given field 818bc4ae4beSMatthew G. Knepley 819bc4ae4beSMatthew G. Knepley Not collective 820bc4ae4beSMatthew G. Knepley 821bc4ae4beSMatthew G. Knepley Input Parameters: 822bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 823bc4ae4beSMatthew G. Knepley - f - The field number 824bc4ae4beSMatthew G. Knepley 825bc4ae4beSMatthew G. Knepley Output Parameter: 826bc4ae4beSMatthew G. Knepley . disc - The discretization object 827bc4ae4beSMatthew G. Knepley 828bc4ae4beSMatthew G. Knepley Level: beginner 829bc4ae4beSMatthew G. Knepley 830f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 831bc4ae4beSMatthew G. Knepley @*/ 8322764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 8332764a2aaSMatthew G. Knepley { 8342764a2aaSMatthew G. Knepley PetscFunctionBegin; 8352764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8362764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 8372764a2aaSMatthew 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); 8382764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 8392764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8402764a2aaSMatthew G. Knepley } 8412764a2aaSMatthew G. Knepley 842bc4ae4beSMatthew G. Knepley /*@ 843bc4ae4beSMatthew G. Knepley PetscDSSetDiscretization - Sets the discretization object for the given field 844bc4ae4beSMatthew G. Knepley 845bc4ae4beSMatthew G. Knepley Not collective 846bc4ae4beSMatthew G. Knepley 847bc4ae4beSMatthew G. Knepley Input Parameters: 848bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 849bc4ae4beSMatthew G. Knepley . f - The field number 850bc4ae4beSMatthew G. Knepley - disc - The discretization object 851bc4ae4beSMatthew G. Knepley 852bc4ae4beSMatthew G. Knepley Level: beginner 853bc4ae4beSMatthew G. Knepley 854bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 855bc4ae4beSMatthew G. Knepley @*/ 8562764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 8572764a2aaSMatthew G. Knepley { 8582764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8592764a2aaSMatthew G. Knepley 8602764a2aaSMatthew G. Knepley PetscFunctionBegin; 8612764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8622764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 8632764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 8642764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 865c10f2116SMatthew G. Knepley ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr); 8662764a2aaSMatthew G. Knepley prob->disc[f] = disc; 8672764a2aaSMatthew G. Knepley ierr = PetscObjectReference(disc);CHKERRQ(ierr); 868249df284SMatthew G. Knepley { 869249df284SMatthew G. Knepley PetscClassId id; 870249df284SMatthew G. Knepley 871249df284SMatthew G. Knepley ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr); 8721cf84007SMatthew G. Knepley if (id == PETSCFE_CLASSID) { 8731cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr); 8741cf84007SMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 8751cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr); 876a6cbbb48SMatthew G. Knepley } 877249df284SMatthew G. Knepley } 8782764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8792764a2aaSMatthew G. Knepley } 8802764a2aaSMatthew G. Knepley 881bc4ae4beSMatthew G. Knepley /*@ 882bc4ae4beSMatthew G. Knepley PetscDSAddDiscretization - Adds a discretization object 883bc4ae4beSMatthew G. Knepley 884bc4ae4beSMatthew G. Knepley Not collective 885bc4ae4beSMatthew G. Knepley 886bc4ae4beSMatthew G. Knepley Input Parameters: 887bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 888bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object 889bc4ae4beSMatthew G. Knepley 890bc4ae4beSMatthew G. Knepley Level: beginner 891bc4ae4beSMatthew G. Knepley 892bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 893bc4ae4beSMatthew G. Knepley @*/ 8942764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) 8952764a2aaSMatthew G. Knepley { 8962764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8972764a2aaSMatthew G. Knepley 8982764a2aaSMatthew G. Knepley PetscFunctionBegin; 8992764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr); 9002764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9012764a2aaSMatthew G. Knepley } 9022764a2aaSMatthew G. Knepley 903249df284SMatthew G. Knepley /*@ 904249df284SMatthew G. Knepley PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX 905249df284SMatthew G. Knepley 906249df284SMatthew G. Knepley Not collective 907249df284SMatthew G. Knepley 908249df284SMatthew G. Knepley Input Parameters: 909249df284SMatthew G. Knepley + prob - The PetscDS object 910249df284SMatthew G. Knepley - f - The field number 911249df284SMatthew G. Knepley 912249df284SMatthew G. Knepley Output Parameter: 913249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field 914249df284SMatthew G. Knepley 915249df284SMatthew G. Knepley Level: developer 916249df284SMatthew G. Knepley 917f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 918249df284SMatthew G. Knepley @*/ 919249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit) 920249df284SMatthew G. Knepley { 921249df284SMatthew G. Knepley PetscFunctionBegin; 922249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 923249df284SMatthew G. Knepley PetscValidPointer(implicit, 3); 924249df284SMatthew 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); 925249df284SMatthew G. Knepley *implicit = prob->implicit[f]; 926249df284SMatthew G. Knepley PetscFunctionReturn(0); 927249df284SMatthew G. Knepley } 928249df284SMatthew G. Knepley 929249df284SMatthew G. Knepley /*@ 930249df284SMatthew G. Knepley PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX 931249df284SMatthew G. Knepley 932249df284SMatthew G. Knepley Not collective 933249df284SMatthew G. Knepley 934249df284SMatthew G. Knepley Input Parameters: 935249df284SMatthew G. Knepley + prob - The PetscDS object 936249df284SMatthew G. Knepley . f - The field number 937249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field 938249df284SMatthew G. Knepley 939249df284SMatthew G. Knepley Level: developer 940249df284SMatthew G. Knepley 941f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 942249df284SMatthew G. Knepley @*/ 943249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit) 944249df284SMatthew G. Knepley { 945249df284SMatthew G. Knepley PetscFunctionBegin; 946249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 947249df284SMatthew 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); 948249df284SMatthew G. Knepley prob->implicit[f] = implicit; 949249df284SMatthew G. Knepley PetscFunctionReturn(0); 950249df284SMatthew G. Knepley } 951249df284SMatthew G. Knepley 9522764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f, 95330b9ff8bSMatthew G. Knepley void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 954194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 955194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 95697b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 9572764a2aaSMatthew G. Knepley { 9582764a2aaSMatthew G. Knepley PetscFunctionBegin; 9592764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 9602764a2aaSMatthew G. Knepley PetscValidPointer(obj, 2); 9612764a2aaSMatthew 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); 9622764a2aaSMatthew G. Knepley *obj = prob->obj[f]; 9632764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9642764a2aaSMatthew G. Knepley } 9652764a2aaSMatthew G. Knepley 9662764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f, 96730b9ff8bSMatthew G. Knepley void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 968194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 969194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 97097b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 9712764a2aaSMatthew G. Knepley { 9722764a2aaSMatthew G. Knepley PetscErrorCode ierr; 9732764a2aaSMatthew G. Knepley 9742764a2aaSMatthew G. Knepley PetscFunctionBegin; 9752764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 976de716cbcSToby Isaac if (obj) PetscValidFunction(obj, 2); 9772764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 9782764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 9792764a2aaSMatthew G. Knepley prob->obj[f] = obj; 9802764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9812764a2aaSMatthew G. Knepley } 9822764a2aaSMatthew G. Knepley 983194d53e6SMatthew G. Knepley /*@C 984194d53e6SMatthew G. Knepley PetscDSGetResidual - Get the pointwise residual function for a given test field 985194d53e6SMatthew G. Knepley 986194d53e6SMatthew G. Knepley Not collective 987194d53e6SMatthew G. Knepley 988194d53e6SMatthew G. Knepley Input Parameters: 989194d53e6SMatthew G. Knepley + prob - The PetscDS 990194d53e6SMatthew G. Knepley - f - The test field number 991194d53e6SMatthew G. Knepley 992194d53e6SMatthew G. Knepley Output Parameters: 993194d53e6SMatthew G. Knepley + f0 - integrand for the test function term 994194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 995194d53e6SMatthew G. Knepley 996194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 997194d53e6SMatthew G. Knepley 998194d53e6SMatthew 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) 999194d53e6SMatthew G. Knepley 1000194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1001194d53e6SMatthew G. Knepley 100230b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1003194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1004194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 100530b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1006194d53e6SMatthew G. Knepley 1007194d53e6SMatthew G. Knepley + dim - the spatial dimension 1008194d53e6SMatthew G. Knepley . Nf - the number of fields 1009194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1010194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1011194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1012194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1013194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1014194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1015194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1016194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1017194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1018194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1019194d53e6SMatthew G. Knepley . t - current time 1020194d53e6SMatthew G. Knepley . x - coordinates of the current point 102197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 102297b6e6e8SMatthew G. Knepley . constants - constant parameters 1023194d53e6SMatthew G. Knepley - f0 - output values at the current point 1024194d53e6SMatthew G. Knepley 1025194d53e6SMatthew G. Knepley Level: intermediate 1026194d53e6SMatthew G. Knepley 1027194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual() 1028194d53e6SMatthew G. Knepley @*/ 10292764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f, 103030b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1031194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1032194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 103397b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 103430b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1035194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1036194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 103797b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 10382764a2aaSMatthew G. Knepley { 10392764a2aaSMatthew G. Knepley PetscFunctionBegin; 10402764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 10412764a2aaSMatthew 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); 10422764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];} 10432764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];} 10442764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10452764a2aaSMatthew G. Knepley } 10462764a2aaSMatthew G. Knepley 1047194d53e6SMatthew G. Knepley /*@C 1048194d53e6SMatthew G. Knepley PetscDSSetResidual - Set the pointwise residual function for a given test field 1049194d53e6SMatthew G. Knepley 1050194d53e6SMatthew G. Knepley Not collective 1051194d53e6SMatthew G. Knepley 1052194d53e6SMatthew G. Knepley Input Parameters: 1053194d53e6SMatthew G. Knepley + prob - The PetscDS 1054194d53e6SMatthew G. Knepley . f - The test field number 1055194d53e6SMatthew G. Knepley . f0 - integrand for the test function term 1056194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1057194d53e6SMatthew G. Knepley 1058194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1059194d53e6SMatthew G. Knepley 1060194d53e6SMatthew 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) 1061194d53e6SMatthew G. Knepley 1062194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1063194d53e6SMatthew G. Knepley 106430b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1065194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1066194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 106730b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1068194d53e6SMatthew G. Knepley 1069194d53e6SMatthew G. Knepley + dim - the spatial dimension 1070194d53e6SMatthew G. Knepley . Nf - the number of fields 1071194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1072194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1073194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1074194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1075194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1076194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1077194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1078194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1079194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1080194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1081194d53e6SMatthew G. Knepley . t - current time 1082194d53e6SMatthew G. Knepley . x - coordinates of the current point 108397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 108497b6e6e8SMatthew G. Knepley . constants - constant parameters 1085194d53e6SMatthew G. Knepley - f0 - output values at the current point 1086194d53e6SMatthew G. Knepley 1087194d53e6SMatthew G. Knepley Level: intermediate 1088194d53e6SMatthew G. Knepley 1089194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual() 1090194d53e6SMatthew G. Knepley @*/ 10912764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f, 109230b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1093194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1094194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 109597b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 109630b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1097194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1098194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 109997b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 11002764a2aaSMatthew G. Knepley { 11012764a2aaSMatthew G. Knepley PetscErrorCode ierr; 11022764a2aaSMatthew G. Knepley 11032764a2aaSMatthew G. Knepley PetscFunctionBegin; 11042764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1105f866a1d0SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1106f866a1d0SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 11072764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 11082764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 11092764a2aaSMatthew G. Knepley prob->f[f*2+0] = f0; 11102764a2aaSMatthew G. Knepley prob->f[f*2+1] = f1; 11112764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11122764a2aaSMatthew G. Knepley } 11132764a2aaSMatthew G. Knepley 11143e75805dSMatthew G. Knepley /*@C 11153e75805dSMatthew G. Knepley PetscDSHasJacobian - Signals that Jacobian functions have been set 11163e75805dSMatthew G. Knepley 11173e75805dSMatthew G. Knepley Not collective 11183e75805dSMatthew G. Knepley 11193e75805dSMatthew G. Knepley Input Parameter: 11203e75805dSMatthew G. Knepley . prob - The PetscDS 11213e75805dSMatthew G. Knepley 11223e75805dSMatthew G. Knepley Output Parameter: 11233e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set 11243e75805dSMatthew G. Knepley 11253e75805dSMatthew G. Knepley Level: intermediate 11263e75805dSMatthew G. Knepley 11273e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 11283e75805dSMatthew G. Knepley @*/ 11293e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac) 11303e75805dSMatthew G. Knepley { 11313e75805dSMatthew G. Knepley PetscInt f, g, h; 11323e75805dSMatthew G. Knepley 11333e75805dSMatthew G. Knepley PetscFunctionBegin; 11343e75805dSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 11353e75805dSMatthew G. Knepley *hasJac = PETSC_FALSE; 11363e75805dSMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 11373e75805dSMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 11383e75805dSMatthew G. Knepley for (h = 0; h < 4; ++h) { 11393e75805dSMatthew G. Knepley if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE; 11403e75805dSMatthew G. Knepley } 11413e75805dSMatthew G. Knepley } 11423e75805dSMatthew G. Knepley } 11433e75805dSMatthew G. Knepley PetscFunctionReturn(0); 11443e75805dSMatthew G. Knepley } 11453e75805dSMatthew G. Knepley 1146194d53e6SMatthew G. Knepley /*@C 1147194d53e6SMatthew G. Knepley PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field 1148194d53e6SMatthew G. Knepley 1149194d53e6SMatthew G. Knepley Not collective 1150194d53e6SMatthew G. Knepley 1151194d53e6SMatthew G. Knepley Input Parameters: 1152194d53e6SMatthew G. Knepley + prob - The PetscDS 1153194d53e6SMatthew G. Knepley . f - The test field number 1154194d53e6SMatthew G. Knepley - g - The field number 1155194d53e6SMatthew G. Knepley 1156194d53e6SMatthew G. Knepley Output Parameters: 1157194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1158194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1159194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1160194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1161194d53e6SMatthew G. Knepley 1162194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1163194d53e6SMatthew G. Knepley 1164194d53e6SMatthew 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 1165194d53e6SMatthew G. Knepley 1166194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1167194d53e6SMatthew G. Knepley 116830b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1169194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1170194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 117130b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1172194d53e6SMatthew G. Knepley 1173194d53e6SMatthew G. Knepley + dim - the spatial dimension 1174194d53e6SMatthew G. Knepley . Nf - the number of fields 1175194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1176194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1177194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1178194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1179194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1180194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1181194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1182194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1183194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1184194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1185194d53e6SMatthew G. Knepley . t - current time 11862aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1187194d53e6SMatthew G. Knepley . x - coordinates of the current point 118897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 118997b6e6e8SMatthew G. Knepley . constants - constant parameters 1190194d53e6SMatthew G. Knepley - g0 - output values at the current point 1191194d53e6SMatthew G. Knepley 1192194d53e6SMatthew G. Knepley Level: intermediate 1193194d53e6SMatthew G. Knepley 1194194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1195194d53e6SMatthew G. Knepley @*/ 11962764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g, 119730b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1198194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1199194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 120097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 120130b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1202194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1203194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 120497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 120530b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1206194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1207194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 120897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 120930b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1210194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1211194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 121297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 12132764a2aaSMatthew G. Knepley { 12142764a2aaSMatthew G. Knepley PetscFunctionBegin; 12152764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 12162764a2aaSMatthew 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); 12172764a2aaSMatthew 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); 12182764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];} 12192764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];} 12202764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];} 12212764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];} 12222764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 12232764a2aaSMatthew G. Knepley } 12242764a2aaSMatthew G. Knepley 1225194d53e6SMatthew G. Knepley /*@C 1226194d53e6SMatthew G. Knepley PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields 1227194d53e6SMatthew G. Knepley 1228194d53e6SMatthew G. Knepley Not collective 1229194d53e6SMatthew G. Knepley 1230194d53e6SMatthew G. Knepley Input Parameters: 1231194d53e6SMatthew G. Knepley + prob - The PetscDS 1232194d53e6SMatthew G. Knepley . f - The test field number 1233194d53e6SMatthew G. Knepley . g - The field number 1234194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1235194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1236194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1237194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1238194d53e6SMatthew G. Knepley 1239194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1240194d53e6SMatthew G. Knepley 1241194d53e6SMatthew 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 1242194d53e6SMatthew G. Knepley 1243194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1244194d53e6SMatthew G. Knepley 124530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1246194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1247194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 124830b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1249194d53e6SMatthew G. Knepley 1250194d53e6SMatthew G. Knepley + dim - the spatial dimension 1251194d53e6SMatthew G. Knepley . Nf - the number of fields 1252194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1253194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1254194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1255194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1256194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1257194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1258194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1259194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1260194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1261194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1262194d53e6SMatthew G. Knepley . t - current time 12632aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1264194d53e6SMatthew G. Knepley . x - coordinates of the current point 126597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 126697b6e6e8SMatthew G. Knepley . constants - constant parameters 1267194d53e6SMatthew G. Knepley - g0 - output values at the current point 1268194d53e6SMatthew G. Knepley 1269194d53e6SMatthew G. Knepley Level: intermediate 1270194d53e6SMatthew G. Knepley 1271194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1272194d53e6SMatthew G. Knepley @*/ 12732764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g, 127430b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1275194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1276194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 127797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 127830b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1279194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1280194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 128197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 128230b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1283194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1284194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 128597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 128630b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1287194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1288194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 128997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 12902764a2aaSMatthew G. Knepley { 12912764a2aaSMatthew G. Knepley PetscErrorCode ierr; 12922764a2aaSMatthew G. Knepley 12932764a2aaSMatthew G. Knepley PetscFunctionBegin; 12942764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 12952764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 12962764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 12972764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 12982764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 12992764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 13002764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 13012764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 13022764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+0] = g0; 13032764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+1] = g1; 13042764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+2] = g2; 13052764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+3] = g3; 13062764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 13072764a2aaSMatthew G. Knepley } 13082764a2aaSMatthew G. Knepley 1309475e0ac9SMatthew G. Knepley /*@C 131055c1f793SMatthew G. Knepley PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner 131155c1f793SMatthew G. Knepley 131255c1f793SMatthew G. Knepley Not collective 131355c1f793SMatthew G. Knepley 131455c1f793SMatthew G. Knepley Input Parameters: 131555c1f793SMatthew G. Knepley + prob - The PetscDS 131655c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner 131755c1f793SMatthew G. Knepley 131855c1f793SMatthew G. Knepley Level: intermediate 131955c1f793SMatthew G. Knepley 132055c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 132155c1f793SMatthew G. Knepley @*/ 132255c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre) 132355c1f793SMatthew G. Knepley { 132455c1f793SMatthew G. Knepley PetscFunctionBegin; 132555c1f793SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 132655c1f793SMatthew G. Knepley prob->useJacPre = useJacPre; 132755c1f793SMatthew G. Knepley PetscFunctionReturn(0); 132855c1f793SMatthew G. Knepley } 132955c1f793SMatthew G. Knepley 133055c1f793SMatthew G. Knepley /*@C 1331475e0ac9SMatthew G. Knepley PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set 1332475e0ac9SMatthew G. Knepley 1333475e0ac9SMatthew G. Knepley Not collective 1334475e0ac9SMatthew G. Knepley 1335475e0ac9SMatthew G. Knepley Input Parameter: 1336475e0ac9SMatthew G. Knepley . prob - The PetscDS 1337475e0ac9SMatthew G. Knepley 1338475e0ac9SMatthew G. Knepley Output Parameter: 1339475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set 1340475e0ac9SMatthew G. Knepley 1341475e0ac9SMatthew G. Knepley Level: intermediate 1342475e0ac9SMatthew G. Knepley 1343475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1344475e0ac9SMatthew G. Knepley @*/ 1345475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre) 1346475e0ac9SMatthew G. Knepley { 1347475e0ac9SMatthew G. Knepley PetscInt f, g, h; 1348475e0ac9SMatthew G. Knepley 1349475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1350475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1351475e0ac9SMatthew G. Knepley *hasJacPre = PETSC_FALSE; 135255c1f793SMatthew G. Knepley if (!prob->useJacPre) PetscFunctionReturn(0); 1353475e0ac9SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1354475e0ac9SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1355475e0ac9SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1356475e0ac9SMatthew G. Knepley if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE; 1357475e0ac9SMatthew G. Knepley } 1358475e0ac9SMatthew G. Knepley } 1359475e0ac9SMatthew G. Knepley } 1360475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1361475e0ac9SMatthew G. Knepley } 1362475e0ac9SMatthew G. Knepley 1363475e0ac9SMatthew G. Knepley /*@C 1364475e0ac9SMatthew 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. 1365475e0ac9SMatthew G. Knepley 1366475e0ac9SMatthew G. Knepley Not collective 1367475e0ac9SMatthew G. Knepley 1368475e0ac9SMatthew G. Knepley Input Parameters: 1369475e0ac9SMatthew G. Knepley + prob - The PetscDS 1370475e0ac9SMatthew G. Knepley . f - The test field number 1371475e0ac9SMatthew G. Knepley - g - The field number 1372475e0ac9SMatthew G. Knepley 1373475e0ac9SMatthew G. Knepley Output Parameters: 1374475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term 1375475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1376475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1377475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1378475e0ac9SMatthew G. Knepley 1379475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1380475e0ac9SMatthew G. Knepley 1381475e0ac9SMatthew 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 1382475e0ac9SMatthew G. Knepley 1383475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1384475e0ac9SMatthew G. Knepley 1385475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1386475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1387475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1388475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1389475e0ac9SMatthew G. Knepley 1390475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1391475e0ac9SMatthew G. Knepley . Nf - the number of fields 1392475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1393475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1394475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1395475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1396475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1397475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1398475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1399475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1400475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1401475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1402475e0ac9SMatthew G. Knepley . t - current time 1403475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1404475e0ac9SMatthew G. Knepley . x - coordinates of the current point 140597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 140697b6e6e8SMatthew G. Knepley . constants - constant parameters 1407475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1408475e0ac9SMatthew G. Knepley 1409475e0ac9SMatthew G. Knepley Level: intermediate 1410475e0ac9SMatthew G. Knepley 1411475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1412475e0ac9SMatthew G. Knepley @*/ 1413475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1414475e0ac9SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1415475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1416475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 141797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1418475e0ac9SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1419475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1420475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 142197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1422475e0ac9SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1423475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1424475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 142597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1426475e0ac9SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1427475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1428475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 142997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1430475e0ac9SMatthew G. Knepley { 1431475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1432475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1433475e0ac9SMatthew 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); 1434475e0ac9SMatthew 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); 1435475e0ac9SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];} 1436475e0ac9SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];} 1437475e0ac9SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];} 1438475e0ac9SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];} 1439475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1440475e0ac9SMatthew G. Knepley } 1441475e0ac9SMatthew G. Knepley 1442475e0ac9SMatthew G. Knepley /*@C 1443475e0ac9SMatthew 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. 1444475e0ac9SMatthew G. Knepley 1445475e0ac9SMatthew G. Knepley Not collective 1446475e0ac9SMatthew G. Knepley 1447475e0ac9SMatthew G. Knepley Input Parameters: 1448475e0ac9SMatthew G. Knepley + prob - The PetscDS 1449475e0ac9SMatthew G. Knepley . f - The test field number 1450475e0ac9SMatthew G. Knepley . g - The field number 1451475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term 1452475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1453475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1454475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1455475e0ac9SMatthew G. Knepley 1456475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1457475e0ac9SMatthew G. Knepley 1458475e0ac9SMatthew 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 1459475e0ac9SMatthew G. Knepley 1460475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1461475e0ac9SMatthew G. Knepley 1462475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1463475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1464475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1465475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1466475e0ac9SMatthew G. Knepley 1467475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1468475e0ac9SMatthew G. Knepley . Nf - the number of fields 1469475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1470475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1471475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1472475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1473475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1474475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1475475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1476475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1477475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1478475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1479475e0ac9SMatthew G. Knepley . t - current time 1480475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1481475e0ac9SMatthew G. Knepley . x - coordinates of the current point 148297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 148397b6e6e8SMatthew G. Knepley . constants - constant parameters 1484475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1485475e0ac9SMatthew G. Knepley 1486475e0ac9SMatthew G. Knepley Level: intermediate 1487475e0ac9SMatthew G. Knepley 1488475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian() 1489475e0ac9SMatthew G. Knepley @*/ 1490475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1491475e0ac9SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1492475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1493475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 149497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1495475e0ac9SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1496475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1497475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 149897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1499475e0ac9SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1500475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1501475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 150297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1503475e0ac9SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1504475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1505475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 150697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1507475e0ac9SMatthew G. Knepley { 1508475e0ac9SMatthew G. Knepley PetscErrorCode ierr; 1509475e0ac9SMatthew G. Knepley 1510475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1511475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1512475e0ac9SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1513475e0ac9SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1514475e0ac9SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1515475e0ac9SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1516475e0ac9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1517475e0ac9SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1518475e0ac9SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1519475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+0] = g0; 1520475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+1] = g1; 1521475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+2] = g2; 1522475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+3] = g3; 1523475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1524475e0ac9SMatthew G. Knepley } 1525475e0ac9SMatthew G. Knepley 1526b7e05686SMatthew G. Knepley /*@C 1527b7e05686SMatthew G. Knepley PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set 1528b7e05686SMatthew G. Knepley 1529b7e05686SMatthew G. Knepley Not collective 1530b7e05686SMatthew G. Knepley 1531b7e05686SMatthew G. Knepley Input Parameter: 1532b7e05686SMatthew G. Knepley . prob - The PetscDS 1533b7e05686SMatthew G. Knepley 1534b7e05686SMatthew G. Knepley Output Parameter: 1535b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set 1536b7e05686SMatthew G. Knepley 1537b7e05686SMatthew G. Knepley Level: intermediate 1538b7e05686SMatthew G. Knepley 1539b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian() 1540b7e05686SMatthew G. Knepley @*/ 1541b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac) 1542b7e05686SMatthew G. Knepley { 1543b7e05686SMatthew G. Knepley PetscInt f, g, h; 1544b7e05686SMatthew G. Knepley 1545b7e05686SMatthew G. Knepley PetscFunctionBegin; 1546b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1547b7e05686SMatthew G. Knepley *hasDynJac = PETSC_FALSE; 1548b7e05686SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1549b7e05686SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1550b7e05686SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1551b7e05686SMatthew G. Knepley if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE; 1552b7e05686SMatthew G. Knepley } 1553b7e05686SMatthew G. Knepley } 1554b7e05686SMatthew G. Knepley } 1555b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1556b7e05686SMatthew G. Knepley } 1557b7e05686SMatthew G. Knepley 1558b7e05686SMatthew G. Knepley /*@C 1559b7e05686SMatthew G. Knepley PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field 1560b7e05686SMatthew G. Knepley 1561b7e05686SMatthew G. Knepley Not collective 1562b7e05686SMatthew G. Knepley 1563b7e05686SMatthew G. Knepley Input Parameters: 1564b7e05686SMatthew G. Knepley + prob - The PetscDS 1565b7e05686SMatthew G. Knepley . f - The test field number 1566b7e05686SMatthew G. Knepley - g - The field number 1567b7e05686SMatthew G. Knepley 1568b7e05686SMatthew G. Knepley Output Parameters: 1569b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term 1570b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1571b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1572b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1573b7e05686SMatthew G. Knepley 1574b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1575b7e05686SMatthew G. Knepley 1576b7e05686SMatthew 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 1577b7e05686SMatthew G. Knepley 1578b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1579b7e05686SMatthew G. Knepley 1580b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1581b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1582b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1583b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1584b7e05686SMatthew G. Knepley 1585b7e05686SMatthew G. Knepley + dim - the spatial dimension 1586b7e05686SMatthew G. Knepley . Nf - the number of fields 1587b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1588b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1589b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1590b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1591b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1592b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1593b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1594b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1595b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1596b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1597b7e05686SMatthew G. Knepley . t - current time 1598b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1599b7e05686SMatthew G. Knepley . x - coordinates of the current point 160097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 160197b6e6e8SMatthew G. Knepley . constants - constant parameters 1602b7e05686SMatthew G. Knepley - g0 - output values at the current point 1603b7e05686SMatthew G. Knepley 1604b7e05686SMatthew G. Knepley Level: intermediate 1605b7e05686SMatthew G. Knepley 1606b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1607b7e05686SMatthew G. Knepley @*/ 1608b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1609b7e05686SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1610b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1611b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 161297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1613b7e05686SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1614b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1615b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 161697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1617b7e05686SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1618b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1619b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 162097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1621b7e05686SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1622b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1623b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 162497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1625b7e05686SMatthew G. Knepley { 1626b7e05686SMatthew G. Knepley PetscFunctionBegin; 1627b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1628b7e05686SMatthew 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); 1629b7e05686SMatthew 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); 1630b7e05686SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];} 1631b7e05686SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];} 1632b7e05686SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];} 1633b7e05686SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];} 1634b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1635b7e05686SMatthew G. Knepley } 1636b7e05686SMatthew G. Knepley 1637b7e05686SMatthew G. Knepley /*@C 1638b7e05686SMatthew G. Knepley PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields 1639b7e05686SMatthew G. Knepley 1640b7e05686SMatthew G. Knepley Not collective 1641b7e05686SMatthew G. Knepley 1642b7e05686SMatthew G. Knepley Input Parameters: 1643b7e05686SMatthew G. Knepley + prob - The PetscDS 1644b7e05686SMatthew G. Knepley . f - The test field number 1645b7e05686SMatthew G. Knepley . g - The field number 1646b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term 1647b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1648b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1649b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1650b7e05686SMatthew G. Knepley 1651b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1652b7e05686SMatthew G. Knepley 1653b7e05686SMatthew 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 1654b7e05686SMatthew G. Knepley 1655b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1656b7e05686SMatthew G. Knepley 1657b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1658b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1659b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1660b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1661b7e05686SMatthew G. Knepley 1662b7e05686SMatthew G. Knepley + dim - the spatial dimension 1663b7e05686SMatthew G. Knepley . Nf - the number of fields 1664b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1665b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1666b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1667b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1668b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1669b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1670b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1671b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1672b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1673b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1674b7e05686SMatthew G. Knepley . t - current time 1675b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1676b7e05686SMatthew G. Knepley . x - coordinates of the current point 167797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 167897b6e6e8SMatthew G. Knepley . constants - constant parameters 1679b7e05686SMatthew G. Knepley - g0 - output values at the current point 1680b7e05686SMatthew G. Knepley 1681b7e05686SMatthew G. Knepley Level: intermediate 1682b7e05686SMatthew G. Knepley 1683b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1684b7e05686SMatthew G. Knepley @*/ 1685b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1686b7e05686SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1687b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1688b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 168997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1690b7e05686SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1691b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1692b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 169397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1694b7e05686SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1695b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1696b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 169797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1698b7e05686SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1699b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1700b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 170197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1702b7e05686SMatthew G. Knepley { 1703b7e05686SMatthew G. Knepley PetscErrorCode ierr; 1704b7e05686SMatthew G. Knepley 1705b7e05686SMatthew G. Knepley PetscFunctionBegin; 1706b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1707b7e05686SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1708b7e05686SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1709b7e05686SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1710b7e05686SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1711b7e05686SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1712b7e05686SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1713b7e05686SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1714b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+0] = g0; 1715b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+1] = g1; 1716b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+2] = g2; 1717b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+3] = g3; 1718b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1719b7e05686SMatthew G. Knepley } 1720b7e05686SMatthew G. Knepley 17210c2f2876SMatthew G. Knepley /*@C 17220c2f2876SMatthew G. Knepley PetscDSGetRiemannSolver - Returns the Riemann solver for the given field 17230c2f2876SMatthew G. Knepley 17240c2f2876SMatthew G. Knepley Not collective 17250c2f2876SMatthew G. Knepley 17260c2f2876SMatthew G. Knepley Input Arguments: 17270c2f2876SMatthew G. Knepley + prob - The PetscDS object 17280c2f2876SMatthew G. Knepley - f - The field number 17290c2f2876SMatthew G. Knepley 17300c2f2876SMatthew G. Knepley Output Argument: 17310c2f2876SMatthew G. Knepley . r - Riemann solver 17320c2f2876SMatthew G. Knepley 17330c2f2876SMatthew G. Knepley Calling sequence for r: 17340c2f2876SMatthew G. Knepley 17355db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 17360c2f2876SMatthew G. Knepley 17375db36cf9SMatthew G. Knepley + dim - The spatial dimension 17385db36cf9SMatthew G. Knepley . Nf - The number of fields 17395db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 17400c2f2876SMatthew G. Knepley . n - The normal vector to the interface 17410c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 17420c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 17430c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 174497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 174597b6e6e8SMatthew G. Knepley . constants - constant parameters 17460c2f2876SMatthew G. Knepley - ctx - optional user context 17470c2f2876SMatthew G. Knepley 17480c2f2876SMatthew G. Knepley Level: intermediate 17490c2f2876SMatthew G. Knepley 17500c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver() 17510c2f2876SMatthew G. Knepley @*/ 17520c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f, 175397b6e6e8SMatthew 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)) 17540c2f2876SMatthew G. Knepley { 17550c2f2876SMatthew G. Knepley PetscFunctionBegin; 17560c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 17570c2f2876SMatthew 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); 17580c2f2876SMatthew G. Knepley PetscValidPointer(r, 3); 17590c2f2876SMatthew G. Knepley *r = prob->r[f]; 17600c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 17610c2f2876SMatthew G. Knepley } 17620c2f2876SMatthew G. Knepley 17630c2f2876SMatthew G. Knepley /*@C 17640c2f2876SMatthew G. Knepley PetscDSSetRiemannSolver - Sets the Riemann solver for the given field 17650c2f2876SMatthew G. Knepley 17660c2f2876SMatthew G. Knepley Not collective 17670c2f2876SMatthew G. Knepley 17680c2f2876SMatthew G. Knepley Input Arguments: 17690c2f2876SMatthew G. Knepley + prob - The PetscDS object 17700c2f2876SMatthew G. Knepley . f - The field number 17710c2f2876SMatthew G. Knepley - r - Riemann solver 17720c2f2876SMatthew G. Knepley 17730c2f2876SMatthew G. Knepley Calling sequence for r: 17740c2f2876SMatthew G. Knepley 17755db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 17760c2f2876SMatthew G. Knepley 17775db36cf9SMatthew G. Knepley + dim - The spatial dimension 17785db36cf9SMatthew G. Knepley . Nf - The number of fields 17795db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 17800c2f2876SMatthew G. Knepley . n - The normal vector to the interface 17810c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 17820c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 17830c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 178497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 178597b6e6e8SMatthew G. Knepley . constants - constant parameters 17860c2f2876SMatthew G. Knepley - ctx - optional user context 17870c2f2876SMatthew G. Knepley 17880c2f2876SMatthew G. Knepley Level: intermediate 17890c2f2876SMatthew G. Knepley 17900c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver() 17910c2f2876SMatthew G. Knepley @*/ 17920c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f, 179397b6e6e8SMatthew 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)) 17940c2f2876SMatthew G. Knepley { 17950c2f2876SMatthew G. Knepley PetscErrorCode ierr; 17960c2f2876SMatthew G. Knepley 17970c2f2876SMatthew G. Knepley PetscFunctionBegin; 17980c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1799de716cbcSToby Isaac if (r) PetscValidFunction(r, 3); 18000c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 18010c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 18020c2f2876SMatthew G. Knepley prob->r[f] = r; 18030c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18040c2f2876SMatthew G. Knepley } 18050c2f2876SMatthew G. Knepley 180632d2bbc9SMatthew G. Knepley /*@C 180732d2bbc9SMatthew G. Knepley PetscDSGetUpdate - Get the pointwise update function for a given field 180832d2bbc9SMatthew G. Knepley 180932d2bbc9SMatthew G. Knepley Not collective 181032d2bbc9SMatthew G. Knepley 181132d2bbc9SMatthew G. Knepley Input Parameters: 181232d2bbc9SMatthew G. Knepley + prob - The PetscDS 181332d2bbc9SMatthew G. Knepley - f - The field number 181432d2bbc9SMatthew G. Knepley 181532d2bbc9SMatthew G. Knepley Output Parameters: 1816a2b725a8SWilliam Gropp . update - update function 181732d2bbc9SMatthew G. Knepley 181832d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 181932d2bbc9SMatthew G. Knepley 182032d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 182132d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 182232d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 182332d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 182432d2bbc9SMatthew G. Knepley 182532d2bbc9SMatthew G. Knepley + dim - the spatial dimension 182632d2bbc9SMatthew G. Knepley . Nf - the number of fields 182732d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 182832d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 182932d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 183032d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 183132d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 183232d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 183332d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 183432d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 183532d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 183632d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 183732d2bbc9SMatthew G. Knepley . t - current time 183832d2bbc9SMatthew G. Knepley . x - coordinates of the current point 183932d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point 184032d2bbc9SMatthew G. Knepley 184132d2bbc9SMatthew G. Knepley Level: intermediate 184232d2bbc9SMatthew G. Knepley 184332d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual() 184432d2bbc9SMatthew G. Knepley @*/ 184532d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f, 184632d2bbc9SMatthew G. Knepley void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 184732d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 184832d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 18493fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 185032d2bbc9SMatthew G. Knepley { 185132d2bbc9SMatthew G. Knepley PetscFunctionBegin; 185232d2bbc9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 185332d2bbc9SMatthew 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); 185432d2bbc9SMatthew G. Knepley if (update) {PetscValidPointer(update, 3); *update = prob->update[f];} 185532d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 185632d2bbc9SMatthew G. Knepley } 185732d2bbc9SMatthew G. Knepley 185832d2bbc9SMatthew G. Knepley /*@C 18593fa77dffSMatthew G. Knepley PetscDSSetUpdate - Set the pointwise update function for a given field 186032d2bbc9SMatthew G. Knepley 186132d2bbc9SMatthew G. Knepley Not collective 186232d2bbc9SMatthew G. Knepley 186332d2bbc9SMatthew G. Knepley Input Parameters: 186432d2bbc9SMatthew G. Knepley + prob - The PetscDS 186532d2bbc9SMatthew G. Knepley . f - The field number 186632d2bbc9SMatthew G. Knepley - update - update function 186732d2bbc9SMatthew G. Knepley 186832d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 186932d2bbc9SMatthew G. Knepley 187032d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 187132d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 187232d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 187332d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 187432d2bbc9SMatthew G. Knepley 187532d2bbc9SMatthew G. Knepley + dim - the spatial dimension 187632d2bbc9SMatthew G. Knepley . Nf - the number of fields 187732d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 187832d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 187932d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 188032d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 188132d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 188232d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 188332d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 188432d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 188532d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 188632d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 188732d2bbc9SMatthew G. Knepley . t - current time 188832d2bbc9SMatthew G. Knepley . x - coordinates of the current point 188932d2bbc9SMatthew G. Knepley - uNew - new field values at the current point 189032d2bbc9SMatthew G. Knepley 189132d2bbc9SMatthew G. Knepley Level: intermediate 189232d2bbc9SMatthew G. Knepley 189332d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual() 189432d2bbc9SMatthew G. Knepley @*/ 189532d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f, 189632d2bbc9SMatthew G. Knepley void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 189732d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 189832d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 18993fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 190032d2bbc9SMatthew G. Knepley { 190132d2bbc9SMatthew G. Knepley PetscErrorCode ierr; 190232d2bbc9SMatthew G. Knepley 190332d2bbc9SMatthew G. Knepley PetscFunctionBegin; 190432d2bbc9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 190532d2bbc9SMatthew G. Knepley if (update) PetscValidFunction(update, 3); 190632d2bbc9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 190732d2bbc9SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 190832d2bbc9SMatthew G. Knepley prob->update[f] = update; 190932d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 191032d2bbc9SMatthew G. Knepley } 191132d2bbc9SMatthew G. Knepley 19120c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx) 19130c2f2876SMatthew G. Knepley { 19140c2f2876SMatthew G. Knepley PetscFunctionBegin; 19150c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19160c2f2876SMatthew 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); 19170c2f2876SMatthew G. Knepley PetscValidPointer(ctx, 3); 19180c2f2876SMatthew G. Knepley *ctx = prob->ctx[f]; 19190c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19200c2f2876SMatthew G. Knepley } 19210c2f2876SMatthew G. Knepley 19220c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx) 19230c2f2876SMatthew G. Knepley { 19240c2f2876SMatthew G. Knepley PetscErrorCode ierr; 19250c2f2876SMatthew G. Knepley 19260c2f2876SMatthew G. Knepley PetscFunctionBegin; 19270c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19280c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 19290c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 19300c2f2876SMatthew G. Knepley prob->ctx[f] = ctx; 19310c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19320c2f2876SMatthew G. Knepley } 19330c2f2876SMatthew G. Knepley 1934194d53e6SMatthew G. Knepley /*@C 1935194d53e6SMatthew G. Knepley PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field 1936194d53e6SMatthew G. Knepley 1937194d53e6SMatthew G. Knepley Not collective 1938194d53e6SMatthew G. Knepley 1939194d53e6SMatthew G. Knepley Input Parameters: 1940194d53e6SMatthew G. Knepley + prob - The PetscDS 1941194d53e6SMatthew G. Knepley - f - The test field number 1942194d53e6SMatthew G. Knepley 1943194d53e6SMatthew G. Knepley Output Parameters: 1944194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term 1945194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 1946194d53e6SMatthew G. Knepley 1947194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1948194d53e6SMatthew G. Knepley 1949194d53e6SMatthew 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 1950194d53e6SMatthew G. Knepley 1951194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1952194d53e6SMatthew G. Knepley 195330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1954194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1955194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 195630b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 1957194d53e6SMatthew G. Knepley 1958194d53e6SMatthew G. Knepley + dim - the spatial dimension 1959194d53e6SMatthew G. Knepley . Nf - the number of fields 1960194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1961194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1962194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1963194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1964194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1965194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1966194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1967194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1968194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1969194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1970194d53e6SMatthew G. Knepley . t - current time 1971194d53e6SMatthew G. Knepley . x - coordinates of the current point 1972194d53e6SMatthew G. Knepley . n - unit normal at the current point 197397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 197497b6e6e8SMatthew G. Knepley . constants - constant parameters 1975194d53e6SMatthew G. Knepley - f0 - output values at the current point 1976194d53e6SMatthew G. Knepley 1977194d53e6SMatthew G. Knepley Level: intermediate 1978194d53e6SMatthew G. Knepley 1979194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual() 1980194d53e6SMatthew G. Knepley @*/ 19812764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f, 198230b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1983194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1984194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 198597b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 198630b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1987194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1988194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 198997b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 19902764a2aaSMatthew G. Knepley { 19912764a2aaSMatthew G. Knepley PetscFunctionBegin; 19922764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19932764a2aaSMatthew 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); 19942764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];} 19952764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];} 19962764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 19972764a2aaSMatthew G. Knepley } 19982764a2aaSMatthew G. Knepley 1999194d53e6SMatthew G. Knepley /*@C 2000194d53e6SMatthew G. Knepley PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field 2001194d53e6SMatthew G. Knepley 2002194d53e6SMatthew G. Knepley Not collective 2003194d53e6SMatthew G. Knepley 2004194d53e6SMatthew G. Knepley Input Parameters: 2005194d53e6SMatthew G. Knepley + prob - The PetscDS 2006194d53e6SMatthew G. Knepley . f - The test field number 2007194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term 2008194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2009194d53e6SMatthew G. Knepley 2010194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2011194d53e6SMatthew G. Knepley 2012194d53e6SMatthew 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 2013194d53e6SMatthew G. Knepley 2014194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2015194d53e6SMatthew G. Knepley 201630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2017194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2018194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 201930b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2020194d53e6SMatthew G. Knepley 2021194d53e6SMatthew G. Knepley + dim - the spatial dimension 2022194d53e6SMatthew G. Knepley . Nf - the number of fields 2023194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2024194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2025194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2026194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2027194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2028194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2029194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2030194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2031194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2032194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2033194d53e6SMatthew G. Knepley . t - current time 2034194d53e6SMatthew G. Knepley . x - coordinates of the current point 2035194d53e6SMatthew G. Knepley . n - unit normal at the current point 203697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 203797b6e6e8SMatthew G. Knepley . constants - constant parameters 2038194d53e6SMatthew G. Knepley - f0 - output values at the current point 2039194d53e6SMatthew G. Knepley 2040194d53e6SMatthew G. Knepley Level: intermediate 2041194d53e6SMatthew G. Knepley 2042194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual() 2043194d53e6SMatthew G. Knepley @*/ 20442764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f, 204530b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2046194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2047194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 204897b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 204930b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2050194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2051194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 205297b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 20532764a2aaSMatthew G. Knepley { 20542764a2aaSMatthew G. Knepley PetscErrorCode ierr; 20552764a2aaSMatthew G. Knepley 20562764a2aaSMatthew G. Knepley PetscFunctionBegin; 20572764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 20582764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 20592764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 20602764a2aaSMatthew G. Knepley if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;} 20612764a2aaSMatthew G. Knepley if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;} 20622764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 20632764a2aaSMatthew G. Knepley } 20642764a2aaSMatthew G. Knepley 2065194d53e6SMatthew G. Knepley /*@C 2066194d53e6SMatthew G. Knepley PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field 2067194d53e6SMatthew G. Knepley 2068194d53e6SMatthew G. Knepley Not collective 2069194d53e6SMatthew G. Knepley 2070194d53e6SMatthew G. Knepley Input Parameters: 2071194d53e6SMatthew G. Knepley + prob - The PetscDS 2072194d53e6SMatthew G. Knepley . f - The test field number 2073194d53e6SMatthew G. Knepley - g - The field number 2074194d53e6SMatthew G. Knepley 2075194d53e6SMatthew G. Knepley Output Parameters: 2076194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 2077194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2078194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2079194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2080194d53e6SMatthew G. Knepley 2081194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2082194d53e6SMatthew G. Knepley 2083194d53e6SMatthew 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 2084194d53e6SMatthew G. Knepley 2085194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2086194d53e6SMatthew G. Knepley 208730b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2088194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2089194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 209030b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2091194d53e6SMatthew G. Knepley 2092194d53e6SMatthew G. Knepley + dim - the spatial dimension 2093194d53e6SMatthew G. Knepley . Nf - the number of fields 2094194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2095194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2096194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2097194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2098194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2099194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2100194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2101194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2102194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2103194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2104194d53e6SMatthew G. Knepley . t - current time 21052aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2106194d53e6SMatthew G. Knepley . x - coordinates of the current point 2107194d53e6SMatthew G. Knepley . n - normal at the current point 210897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 210997b6e6e8SMatthew G. Knepley . constants - constant parameters 2110194d53e6SMatthew G. Knepley - g0 - output values at the current point 2111194d53e6SMatthew G. Knepley 2112194d53e6SMatthew G. Knepley Level: intermediate 2113194d53e6SMatthew G. Knepley 2114194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian() 2115194d53e6SMatthew G. Knepley @*/ 21162764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 211730b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2118194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2119194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 212097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 212130b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2122194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2123194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 212497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 212530b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2126194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2127194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 212897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 212930b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2130194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2131194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 213297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 21332764a2aaSMatthew G. Knepley { 21342764a2aaSMatthew G. Knepley PetscFunctionBegin; 21352764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 21362764a2aaSMatthew 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); 21372764a2aaSMatthew 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); 21382764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];} 21392764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];} 21402764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];} 21412764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];} 21422764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21432764a2aaSMatthew G. Knepley } 21442764a2aaSMatthew G. Knepley 2145194d53e6SMatthew G. Knepley /*@C 2146194d53e6SMatthew G. Knepley PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field 2147194d53e6SMatthew G. Knepley 2148194d53e6SMatthew G. Knepley Not collective 2149194d53e6SMatthew G. Knepley 2150194d53e6SMatthew G. Knepley Input Parameters: 2151194d53e6SMatthew G. Knepley + prob - The PetscDS 2152194d53e6SMatthew G. Knepley . f - The test field number 2153194d53e6SMatthew G. Knepley . g - The field number 2154194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 2155194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2156194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2157194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2158194d53e6SMatthew G. Knepley 2159194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2160194d53e6SMatthew G. Knepley 2161194d53e6SMatthew 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 2162194d53e6SMatthew G. Knepley 2163194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2164194d53e6SMatthew G. Knepley 216530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2166194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2167194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 216830b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2169194d53e6SMatthew G. Knepley 2170194d53e6SMatthew G. Knepley + dim - the spatial dimension 2171194d53e6SMatthew G. Knepley . Nf - the number of fields 2172194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2173194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2174194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2175194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2176194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2177194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2178194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2179194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2180194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2181194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2182194d53e6SMatthew G. Knepley . t - current time 21832aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2184194d53e6SMatthew G. Knepley . x - coordinates of the current point 2185194d53e6SMatthew G. Knepley . n - normal at the current point 218697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 218797b6e6e8SMatthew G. Knepley . constants - constant parameters 2188194d53e6SMatthew G. Knepley - g0 - output values at the current point 2189194d53e6SMatthew G. Knepley 2190194d53e6SMatthew G. Knepley Level: intermediate 2191194d53e6SMatthew G. Knepley 2192194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian() 2193194d53e6SMatthew G. Knepley @*/ 21942764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 219530b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2196194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2197194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 219897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 219930b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2200194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2201194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 220297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 220330b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2204194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2205194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 220697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 220730b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2208194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2209194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 221097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 22112764a2aaSMatthew G. Knepley { 22122764a2aaSMatthew G. Knepley PetscErrorCode ierr; 22132764a2aaSMatthew G. Knepley 22142764a2aaSMatthew G. Knepley PetscFunctionBegin; 22152764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 22162764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 22172764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 22182764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 22192764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 22202764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 22212764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 22222764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 22232764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+0] = g0; 22242764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+1] = g1; 22252764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+2] = g2; 22262764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+3] = g3; 22272764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22282764a2aaSMatthew G. Knepley } 22292764a2aaSMatthew G. Knepley 22300d3e9b51SMatthew G. Knepley /*@C 2231c371a6d1SMatthew G. Knepley PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field 2232c371a6d1SMatthew G. Knepley 2233c371a6d1SMatthew G. Knepley Not collective 2234c371a6d1SMatthew G. Knepley 2235c371a6d1SMatthew G. Knepley Input Parameters: 2236c371a6d1SMatthew G. Knepley + prob - The PetscDS 2237c371a6d1SMatthew G. Knepley - f - The test field number 2238c371a6d1SMatthew G. Knepley 2239c371a6d1SMatthew G. Knepley Output Parameter: 224095cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field 224195cbbfd3SMatthew G. Knepley - exactCtx - exact solution context 2242c371a6d1SMatthew G. Knepley 2243c371a6d1SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2244c371a6d1SMatthew G. Knepley 2245c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2246c371a6d1SMatthew G. Knepley 2247c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2248c371a6d1SMatthew G. Knepley . t - current time 2249c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2250c371a6d1SMatthew G. Knepley . Nc - the number of field components 2251c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2252c371a6d1SMatthew G. Knepley - ctx - a user context 2253c371a6d1SMatthew G. Knepley 2254c371a6d1SMatthew G. Knepley Level: intermediate 2255c371a6d1SMatthew G. Knepley 2256c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution() 2257c371a6d1SMatthew G. Knepley @*/ 225895cbbfd3SMatthew 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) 2259c371a6d1SMatthew G. Knepley { 2260c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2261c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2262c371a6d1SMatthew 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); 2263c371a6d1SMatthew G. Knepley if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];} 226495cbbfd3SMatthew G. Knepley if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];} 2265c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2266c371a6d1SMatthew G. Knepley } 2267c371a6d1SMatthew G. Knepley 2268c371a6d1SMatthew G. Knepley /*@C 2269578a5ef5SMatthew Knepley PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field 2270c371a6d1SMatthew G. Knepley 2271c371a6d1SMatthew G. Knepley Not collective 2272c371a6d1SMatthew G. Knepley 2273c371a6d1SMatthew G. Knepley Input Parameters: 2274c371a6d1SMatthew G. Knepley + prob - The PetscDS 2275c371a6d1SMatthew G. Knepley . f - The test field number 227695cbbfd3SMatthew G. Knepley . sol - solution function for the test fields 227795cbbfd3SMatthew G. Knepley - ctx - solution context or NULL 2278c371a6d1SMatthew G. Knepley 2279c371a6d1SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2280c371a6d1SMatthew G. Knepley 2281c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2282c371a6d1SMatthew G. Knepley 2283c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2284c371a6d1SMatthew G. Knepley . t - current time 2285c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2286c371a6d1SMatthew G. Knepley . Nc - the number of field components 2287c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2288c371a6d1SMatthew G. Knepley - ctx - a user context 2289c371a6d1SMatthew G. Knepley 2290c371a6d1SMatthew G. Knepley Level: intermediate 2291c371a6d1SMatthew G. Knepley 2292c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution() 2293c371a6d1SMatthew G. Knepley @*/ 229495cbbfd3SMatthew 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) 2295c371a6d1SMatthew G. Knepley { 2296c371a6d1SMatthew G. Knepley PetscErrorCode ierr; 2297c371a6d1SMatthew G. Knepley 2298c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2299c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2300c371a6d1SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 2301c371a6d1SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 2302c371a6d1SMatthew G. Knepley if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;} 230395cbbfd3SMatthew G. Knepley if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;} 2304c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2305c371a6d1SMatthew G. Knepley } 2306c371a6d1SMatthew G. Knepley 23075638fd0eSMatthew G. Knepley /*@C 230897b6e6e8SMatthew G. Knepley PetscDSGetConstants - Returns the array of constants passed to point functions 230997b6e6e8SMatthew G. Knepley 231097b6e6e8SMatthew G. Knepley Not collective 231197b6e6e8SMatthew G. Knepley 231297b6e6e8SMatthew G. Knepley Input Parameter: 231397b6e6e8SMatthew G. Knepley . prob - The PetscDS object 231497b6e6e8SMatthew G. Knepley 231597b6e6e8SMatthew G. Knepley Output Parameters: 231697b6e6e8SMatthew G. Knepley + numConstants - The number of constants 231797b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 231897b6e6e8SMatthew G. Knepley 231997b6e6e8SMatthew G. Knepley Level: intermediate 232097b6e6e8SMatthew G. Knepley 232197b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate() 232297b6e6e8SMatthew G. Knepley @*/ 232397b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[]) 232497b6e6e8SMatthew G. Knepley { 232597b6e6e8SMatthew G. Knepley PetscFunctionBegin; 232697b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 232797b6e6e8SMatthew G. Knepley if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;} 232897b6e6e8SMatthew G. Knepley if (constants) {PetscValidPointer(constants, 3); *constants = prob->constants;} 232997b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 233097b6e6e8SMatthew G. Knepley } 233197b6e6e8SMatthew G. Knepley 23320d3e9b51SMatthew G. Knepley /*@C 233397b6e6e8SMatthew G. Knepley PetscDSSetConstants - Set the array of constants passed to point functions 233497b6e6e8SMatthew G. Knepley 233597b6e6e8SMatthew G. Knepley Not collective 233697b6e6e8SMatthew G. Knepley 233797b6e6e8SMatthew G. Knepley Input Parameters: 233897b6e6e8SMatthew G. Knepley + prob - The PetscDS object 233997b6e6e8SMatthew G. Knepley . numConstants - The number of constants 234097b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 234197b6e6e8SMatthew G. Knepley 234297b6e6e8SMatthew G. Knepley Level: intermediate 234397b6e6e8SMatthew G. Knepley 234497b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate() 234597b6e6e8SMatthew G. Knepley @*/ 234697b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[]) 234797b6e6e8SMatthew G. Knepley { 234897b6e6e8SMatthew G. Knepley PetscErrorCode ierr; 234997b6e6e8SMatthew G. Knepley 235097b6e6e8SMatthew G. Knepley PetscFunctionBegin; 235197b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 235297b6e6e8SMatthew G. Knepley if (numConstants != prob->numConstants) { 235397b6e6e8SMatthew G. Knepley ierr = PetscFree(prob->constants);CHKERRQ(ierr); 235497b6e6e8SMatthew G. Knepley prob->numConstants = numConstants; 235597b6e6e8SMatthew G. Knepley if (prob->numConstants) { 235697b6e6e8SMatthew G. Knepley ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr); 235720be0f5bSMatthew G. Knepley } else { 235820be0f5bSMatthew G. Knepley prob->constants = NULL; 235920be0f5bSMatthew G. Knepley } 236020be0f5bSMatthew G. Knepley } 236120be0f5bSMatthew G. Knepley if (prob->numConstants) { 236220be0f5bSMatthew G. Knepley PetscValidPointer(constants, 3); 2363580bdb30SBarry Smith ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr); 236497b6e6e8SMatthew G. Knepley } 236597b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 236697b6e6e8SMatthew G. Knepley } 236797b6e6e8SMatthew G. Knepley 23684cd1e086SMatthew G. Knepley /*@ 23694cd1e086SMatthew G. Knepley PetscDSGetFieldIndex - Returns the index of the given field 23704cd1e086SMatthew G. Knepley 23714cd1e086SMatthew G. Knepley Not collective 23724cd1e086SMatthew G. Knepley 23734cd1e086SMatthew G. Knepley Input Parameters: 23744cd1e086SMatthew G. Knepley + prob - The PetscDS object 23754cd1e086SMatthew G. Knepley - disc - The discretization object 23764cd1e086SMatthew G. Knepley 23774cd1e086SMatthew G. Knepley Output Parameter: 23784cd1e086SMatthew G. Knepley . f - The field number 23794cd1e086SMatthew G. Knepley 23804cd1e086SMatthew G. Knepley Level: beginner 23814cd1e086SMatthew G. Knepley 2382f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 23834cd1e086SMatthew G. Knepley @*/ 23844cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f) 23854cd1e086SMatthew G. Knepley { 23864cd1e086SMatthew G. Knepley PetscInt g; 23874cd1e086SMatthew G. Knepley 23884cd1e086SMatthew G. Knepley PetscFunctionBegin; 23894cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 23904cd1e086SMatthew G. Knepley PetscValidPointer(f, 3); 23914cd1e086SMatthew G. Knepley *f = -1; 23924cd1e086SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;} 23934cd1e086SMatthew G. Knepley if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS."); 23944cd1e086SMatthew G. Knepley *f = g; 23954cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 23964cd1e086SMatthew G. Knepley } 23974cd1e086SMatthew G. Knepley 23984cd1e086SMatthew G. Knepley /*@ 23994cd1e086SMatthew G. Knepley PetscDSGetFieldSize - Returns the size of the given field in the full space basis 24004cd1e086SMatthew G. Knepley 24014cd1e086SMatthew G. Knepley Not collective 24024cd1e086SMatthew G. Knepley 24034cd1e086SMatthew G. Knepley Input Parameters: 24044cd1e086SMatthew G. Knepley + prob - The PetscDS object 24054cd1e086SMatthew G. Knepley - f - The field number 24064cd1e086SMatthew G. Knepley 24074cd1e086SMatthew G. Knepley Output Parameter: 24084cd1e086SMatthew G. Knepley . size - The size 24094cd1e086SMatthew G. Knepley 24104cd1e086SMatthew G. Knepley Level: beginner 24114cd1e086SMatthew G. Knepley 2412f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate() 24134cd1e086SMatthew G. Knepley @*/ 24144cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size) 24154cd1e086SMatthew G. Knepley { 24162166fd64SMatthew G. Knepley PetscErrorCode ierr; 24172166fd64SMatthew G. Knepley 24184cd1e086SMatthew G. Knepley PetscFunctionBegin; 24194cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 24204cd1e086SMatthew G. Knepley PetscValidPointer(size, 3); 24214cd1e086SMatthew 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); 24222166fd64SMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2423d4742ddaSMatthew G. Knepley *size = prob->Nb[f]; 24244cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 24254cd1e086SMatthew G. Knepley } 24264cd1e086SMatthew G. Knepley 2427bc4ae4beSMatthew G. Knepley /*@ 2428bc4ae4beSMatthew G. Knepley PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis 2429bc4ae4beSMatthew G. Knepley 2430bc4ae4beSMatthew G. Knepley Not collective 2431bc4ae4beSMatthew G. Knepley 2432bc4ae4beSMatthew G. Knepley Input Parameters: 2433bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 2434bc4ae4beSMatthew G. Knepley - f - The field number 2435bc4ae4beSMatthew G. Knepley 2436bc4ae4beSMatthew G. Knepley Output Parameter: 2437bc4ae4beSMatthew G. Knepley . off - The offset 2438bc4ae4beSMatthew G. Knepley 2439bc4ae4beSMatthew G. Knepley Level: beginner 2440bc4ae4beSMatthew G. Knepley 2441f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate() 2442bc4ae4beSMatthew G. Knepley @*/ 24432764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 24442764a2aaSMatthew G. Knepley { 24454cd1e086SMatthew G. Knepley PetscInt size, g; 24462764a2aaSMatthew G. Knepley PetscErrorCode ierr; 24472764a2aaSMatthew G. Knepley 24482764a2aaSMatthew G. Knepley PetscFunctionBegin; 24492764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 24502764a2aaSMatthew G. Knepley PetscValidPointer(off, 3); 24512764a2aaSMatthew 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); 24522764a2aaSMatthew G. Knepley *off = 0; 24532764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 24544cd1e086SMatthew G. Knepley ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr); 24554cd1e086SMatthew G. Knepley *off += size; 24562764a2aaSMatthew G. Knepley } 24572764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 24582764a2aaSMatthew G. Knepley } 24592764a2aaSMatthew G. Knepley 2460bc4ae4beSMatthew G. Knepley /*@ 246147e57110SSander Arens PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point 2462bc4ae4beSMatthew G. Knepley 2463bc4ae4beSMatthew G. Knepley Not collective 2464bc4ae4beSMatthew G. Knepley 246547e57110SSander Arens Input Parameter: 246647e57110SSander Arens . prob - The PetscDS object 2467bc4ae4beSMatthew G. Knepley 2468bc4ae4beSMatthew G. Knepley Output Parameter: 246947e57110SSander Arens . dimensions - The number of dimensions 2470bc4ae4beSMatthew G. Knepley 2471bc4ae4beSMatthew G. Knepley Level: beginner 2472bc4ae4beSMatthew G. Knepley 247347e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 2474bc4ae4beSMatthew G. Knepley @*/ 247547e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[]) 24762764a2aaSMatthew G. Knepley { 24772764a2aaSMatthew G. Knepley PetscErrorCode ierr; 24782764a2aaSMatthew G. Knepley 24792764a2aaSMatthew G. Knepley PetscFunctionBegin; 24802764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 248147e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 248247e57110SSander Arens PetscValidPointer(dimensions, 2); 248347e57110SSander Arens *dimensions = prob->Nb; 248447e57110SSander Arens PetscFunctionReturn(0); 24856ce16762SMatthew G. Knepley } 248647e57110SSander Arens 248747e57110SSander Arens /*@ 248847e57110SSander Arens PetscDSGetComponents - Returns the number of components for each field on an evaluation point 248947e57110SSander Arens 249047e57110SSander Arens Not collective 249147e57110SSander Arens 249247e57110SSander Arens Input Parameter: 249347e57110SSander Arens . prob - The PetscDS object 249447e57110SSander Arens 249547e57110SSander Arens Output Parameter: 249647e57110SSander Arens . components - The number of components 249747e57110SSander Arens 249847e57110SSander Arens Level: beginner 249947e57110SSander Arens 250047e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 250147e57110SSander Arens @*/ 250247e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[]) 250347e57110SSander Arens { 250447e57110SSander Arens PetscErrorCode ierr; 250547e57110SSander Arens 250647e57110SSander Arens PetscFunctionBegin; 250747e57110SSander Arens PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 250847e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 250947e57110SSander Arens PetscValidPointer(components, 2); 251047e57110SSander Arens *components = prob->Nc; 25116ce16762SMatthew G. Knepley PetscFunctionReturn(0); 25126ce16762SMatthew G. Knepley } 25136ce16762SMatthew G. Knepley 25146ce16762SMatthew G. Knepley /*@ 25156ce16762SMatthew G. Knepley PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point 25166ce16762SMatthew G. Knepley 25176ce16762SMatthew G. Knepley Not collective 25186ce16762SMatthew G. Knepley 25196ce16762SMatthew G. Knepley Input Parameters: 25206ce16762SMatthew G. Knepley + prob - The PetscDS object 25216ce16762SMatthew G. Knepley - f - The field number 25226ce16762SMatthew G. Knepley 25236ce16762SMatthew G. Knepley Output Parameter: 25246ce16762SMatthew G. Knepley . off - The offset 25256ce16762SMatthew G. Knepley 25266ce16762SMatthew G. Knepley Level: beginner 25276ce16762SMatthew G. Knepley 2528f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 25296ce16762SMatthew G. Knepley @*/ 25306ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off) 25316ce16762SMatthew G. Knepley { 25326ce16762SMatthew G. Knepley PetscFunctionBegin; 25336ce16762SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 25346ce16762SMatthew G. Knepley PetscValidPointer(off, 3); 25356ce16762SMatthew 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); 253647e57110SSander Arens *off = prob->off[f]; 25372764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 25382764a2aaSMatthew G. Knepley } 25392764a2aaSMatthew G. Knepley 2540194d53e6SMatthew G. Knepley /*@ 2541194d53e6SMatthew G. Knepley PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point 2542194d53e6SMatthew G. Knepley 2543194d53e6SMatthew G. Knepley Not collective 2544194d53e6SMatthew G. Knepley 2545194d53e6SMatthew G. Knepley Input Parameter: 2546194d53e6SMatthew G. Knepley . prob - The PetscDS object 2547194d53e6SMatthew G. Knepley 2548194d53e6SMatthew G. Knepley Output Parameter: 2549194d53e6SMatthew G. Knepley . offsets - The offsets 2550194d53e6SMatthew G. Knepley 2551194d53e6SMatthew G. Knepley Level: beginner 2552194d53e6SMatthew G. Knepley 2553f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2554194d53e6SMatthew G. Knepley @*/ 2555194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[]) 2556194d53e6SMatthew G. Knepley { 2557194d53e6SMatthew G. Knepley PetscFunctionBegin; 2558194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2559194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2560194d53e6SMatthew G. Knepley *offsets = prob->off; 2561194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2562194d53e6SMatthew G. Knepley } 2563194d53e6SMatthew G. Knepley 2564194d53e6SMatthew G. Knepley /*@ 2565194d53e6SMatthew G. Knepley PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point 2566194d53e6SMatthew G. Knepley 2567194d53e6SMatthew G. Knepley Not collective 2568194d53e6SMatthew G. Knepley 2569194d53e6SMatthew G. Knepley Input Parameter: 2570194d53e6SMatthew G. Knepley . prob - The PetscDS object 2571194d53e6SMatthew G. Knepley 2572194d53e6SMatthew G. Knepley Output Parameter: 2573194d53e6SMatthew G. Knepley . offsets - The offsets 2574194d53e6SMatthew G. Knepley 2575194d53e6SMatthew G. Knepley Level: beginner 2576194d53e6SMatthew G. Knepley 2577f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2578194d53e6SMatthew G. Knepley @*/ 2579194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[]) 2580194d53e6SMatthew G. Knepley { 2581194d53e6SMatthew G. Knepley PetscFunctionBegin; 2582194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2583194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2584194d53e6SMatthew G. Knepley *offsets = prob->offDer; 2585194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2586194d53e6SMatthew G. Knepley } 2587194d53e6SMatthew G. Knepley 258868c9edb9SMatthew G. Knepley /*@C 258968c9edb9SMatthew G. Knepley PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization 259068c9edb9SMatthew G. Knepley 259168c9edb9SMatthew G. Knepley Not collective 259268c9edb9SMatthew G. Knepley 259368c9edb9SMatthew G. Knepley Input Parameter: 259468c9edb9SMatthew G. Knepley . prob - The PetscDS object 259568c9edb9SMatthew G. Knepley 2596*ef0bb6c7SMatthew G. Knepley Output Parameter: 2597*ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field 259868c9edb9SMatthew G. Knepley 259968c9edb9SMatthew G. Knepley Level: intermediate 260068c9edb9SMatthew G. Knepley 2601f744cafaSSander Arens .seealso: PetscDSCreate() 260268c9edb9SMatthew G. Knepley @*/ 2603*ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[]) 26042764a2aaSMatthew G. Knepley { 26052764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26062764a2aaSMatthew G. Knepley 26072764a2aaSMatthew G. Knepley PetscFunctionBegin; 26082764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2609*ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 2); 26102764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2611*ef0bb6c7SMatthew G. Knepley *T = prob->T; 26122764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26132764a2aaSMatthew G. Knepley } 26142764a2aaSMatthew G. Knepley 261568c9edb9SMatthew G. Knepley /*@C 26164d0b9603SSander Arens PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces 261768c9edb9SMatthew G. Knepley 261868c9edb9SMatthew G. Knepley Not collective 261968c9edb9SMatthew G. Knepley 262068c9edb9SMatthew G. Knepley Input Parameter: 262168c9edb9SMatthew G. Knepley . prob - The PetscDS object 262268c9edb9SMatthew G. Knepley 2623*ef0bb6c7SMatthew G. Knepley Output Parameter: 2624*ef0bb6c7SMatthew G. Knepley . Tf - The basis function and derviative tabulation on each lcoal face at quadrature points for each and field 262568c9edb9SMatthew G. Knepley 262668c9edb9SMatthew G. Knepley Level: intermediate 262768c9edb9SMatthew G. Knepley 262868c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate() 262968c9edb9SMatthew G. Knepley @*/ 2630*ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[]) 26312764a2aaSMatthew G. Knepley { 26322764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26332764a2aaSMatthew G. Knepley 26342764a2aaSMatthew G. Knepley PetscFunctionBegin; 26352764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2636*ef0bb6c7SMatthew G. Knepley PetscValidPointer(Tf, 2); 26372764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2638*ef0bb6c7SMatthew G. Knepley *Tf = prob->Tf; 26392764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26402764a2aaSMatthew G. Knepley } 26412764a2aaSMatthew G. Knepley 26422764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) 26432764a2aaSMatthew G. Knepley { 26442764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26452764a2aaSMatthew G. Knepley 26462764a2aaSMatthew G. Knepley PetscFunctionBegin; 26472764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26482764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 26492764a2aaSMatthew G. Knepley if (u) {PetscValidPointer(u, 2); *u = prob->u;} 26502764a2aaSMatthew G. Knepley if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;} 26512764a2aaSMatthew G. Knepley if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;} 26522764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26532764a2aaSMatthew G. Knepley } 26542764a2aaSMatthew G. Knepley 26552764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) 26562764a2aaSMatthew G. Knepley { 26572764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26582764a2aaSMatthew G. Knepley 26592764a2aaSMatthew G. Knepley PetscFunctionBegin; 26602764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26612764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 26622764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;} 26632764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;} 26642764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;} 26652764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;} 26662764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;} 26672764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;} 26682764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26692764a2aaSMatthew G. Knepley } 26702764a2aaSMatthew G. Knepley 26714bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal) 26722764a2aaSMatthew G. Knepley { 26732764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26742764a2aaSMatthew G. Knepley 26752764a2aaSMatthew G. Knepley PetscFunctionBegin; 26762764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26772764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 26782764a2aaSMatthew G. Knepley if (x) {PetscValidPointer(x, 2); *x = prob->x;} 26794bee2e38SMatthew G. Knepley if (basisReal) {PetscValidPointer(basisReal, 3); *basisReal = prob->basisReal;} 26804bee2e38SMatthew G. Knepley if (basisDerReal) {PetscValidPointer(basisDerReal, 3); *basisDerReal = prob->basisDerReal;} 26814bee2e38SMatthew G. Knepley if (testReal) {PetscValidPointer(testReal, 3); *testReal = prob->testReal;} 26824bee2e38SMatthew G. Knepley if (testDerReal) {PetscValidPointer(testDerReal, 3); *testDerReal = prob->testDerReal;} 26832764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26842764a2aaSMatthew G. Knepley } 26852764a2aaSMatthew G. Knepley 268658ebd649SToby Isaac /*@C 268758ebd649SToby Isaac PetscDSAddBoundary - Add a boundary condition to the model 268858ebd649SToby Isaac 268958ebd649SToby Isaac Input Parameters: 269058ebd649SToby Isaac + ds - The PetscDS object 26912d47a189SJulian Andrej . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 269258ebd649SToby Isaac . name - The BC name 269358ebd649SToby Isaac . labelname - The label defining constrained points 269458ebd649SToby Isaac . field - The field to constrain 2695e8ecbf3fSStefano Zampini . numcomps - The number of constrained field components (0 will constrain all fields) 269658ebd649SToby Isaac . comps - An array of constrained component numbers 269758ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 269858ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 269958ebd649SToby Isaac . ids - An array of ids for constrained points 270058ebd649SToby Isaac - ctx - An optional user context for bcFunc 270158ebd649SToby Isaac 270258ebd649SToby Isaac Options Database Keys: 270358ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 270458ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 270558ebd649SToby Isaac 270658ebd649SToby Isaac Level: developer 270758ebd649SToby Isaac 270858ebd649SToby Isaac .seealso: PetscDSGetBoundary() 270958ebd649SToby Isaac @*/ 2710a30ec4eaSSatish 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) 271158ebd649SToby Isaac { 271258ebd649SToby Isaac DSBoundary b; 271358ebd649SToby Isaac PetscErrorCode ierr; 271458ebd649SToby Isaac 271558ebd649SToby Isaac PetscFunctionBegin; 271658ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 271758ebd649SToby Isaac ierr = PetscNew(&b);CHKERRQ(ierr); 271858ebd649SToby Isaac ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 271958ebd649SToby Isaac ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 272058ebd649SToby Isaac ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 2721580bdb30SBarry Smith if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);} 272258ebd649SToby Isaac ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 2723580bdb30SBarry Smith if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);} 2724f971fd6bSMatthew G. Knepley b->type = type; 272558ebd649SToby Isaac b->field = field; 272658ebd649SToby Isaac b->numcomps = numcomps; 272758ebd649SToby Isaac b->func = bcFunc; 272858ebd649SToby Isaac b->numids = numids; 272958ebd649SToby Isaac b->ctx = ctx; 273058ebd649SToby Isaac b->next = ds->boundary; 273158ebd649SToby Isaac ds->boundary = b; 273258ebd649SToby Isaac PetscFunctionReturn(0); 273358ebd649SToby Isaac } 273458ebd649SToby Isaac 2735b67eacb3SMatthew G. Knepley /*@C 2736b67eacb3SMatthew G. Knepley PetscDSUpdateBoundary - Change a boundary condition for the model 2737b67eacb3SMatthew G. Knepley 2738b67eacb3SMatthew G. Knepley Input Parameters: 2739b67eacb3SMatthew G. Knepley + ds - The PetscDS object 2740b67eacb3SMatthew G. Knepley . bd - The boundary condition number 2741b67eacb3SMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 2742b67eacb3SMatthew G. Knepley . name - The BC name 2743b67eacb3SMatthew G. Knepley . labelname - The label defining constrained points 2744b67eacb3SMatthew G. Knepley . field - The field to constrain 2745b67eacb3SMatthew G. Knepley . numcomps - The number of constrained field components 2746b67eacb3SMatthew G. Knepley . comps - An array of constrained component numbers 2747b67eacb3SMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 2748b67eacb3SMatthew G. Knepley . numids - The number of DMLabel ids for constrained points 2749b67eacb3SMatthew G. Knepley . ids - An array of ids for constrained points 2750b67eacb3SMatthew G. Knepley - ctx - An optional user context for bcFunc 2751b67eacb3SMatthew G. Knepley 27529a6efb6aSMatthew 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(). 27539a6efb6aSMatthew G. Knepley 2754b67eacb3SMatthew G. Knepley Level: developer 2755b67eacb3SMatthew G. Knepley 27569a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary() 2757b67eacb3SMatthew G. Knepley @*/ 2758b67eacb3SMatthew 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) 2759b67eacb3SMatthew G. Knepley { 2760b67eacb3SMatthew G. Knepley DSBoundary b = ds->boundary; 2761b67eacb3SMatthew G. Knepley PetscInt n = 0; 2762b67eacb3SMatthew G. Knepley PetscErrorCode ierr; 2763b67eacb3SMatthew G. Knepley 2764b67eacb3SMatthew G. Knepley PetscFunctionBegin; 2765b67eacb3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 2766b67eacb3SMatthew G. Knepley while (b) { 2767b67eacb3SMatthew G. Knepley if (n == bd) break; 2768b67eacb3SMatthew G. Knepley b = b->next; 2769b67eacb3SMatthew G. Knepley ++n; 2770b67eacb3SMatthew G. Knepley } 2771b67eacb3SMatthew G. Knepley if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 2772b67eacb3SMatthew G. Knepley if (name) { 2773b67eacb3SMatthew G. Knepley ierr = PetscFree(b->name);CHKERRQ(ierr); 2774b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 2775b67eacb3SMatthew G. Knepley } 2776b67eacb3SMatthew G. Knepley if (labelname) { 2777b67eacb3SMatthew G. Knepley ierr = PetscFree(b->labelname);CHKERRQ(ierr); 2778b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 2779b67eacb3SMatthew G. Knepley } 2780b67eacb3SMatthew G. Knepley if (numcomps >= 0 && numcomps != b->numcomps) { 2781b67eacb3SMatthew G. Knepley b->numcomps = numcomps; 2782b67eacb3SMatthew G. Knepley ierr = PetscFree(b->comps);CHKERRQ(ierr); 2783b67eacb3SMatthew G. Knepley ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 2784580bdb30SBarry Smith if (numcomps) {ierr = PetscArraycpy(b->comps, comps, numcomps);CHKERRQ(ierr);} 2785b67eacb3SMatthew G. Knepley } 2786b67eacb3SMatthew G. Knepley if (numids >= 0 && numids != b->numids) { 2787b67eacb3SMatthew G. Knepley b->numids = numids; 2788b67eacb3SMatthew G. Knepley ierr = PetscFree(b->ids);CHKERRQ(ierr); 2789b67eacb3SMatthew G. Knepley ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 2790580bdb30SBarry Smith if (numids) {ierr = PetscArraycpy(b->ids, ids, numids);CHKERRQ(ierr);} 2791b67eacb3SMatthew G. Knepley } 2792b67eacb3SMatthew G. Knepley b->type = type; 2793b67eacb3SMatthew G. Knepley if (field >= 0) {b->field = field;} 2794b67eacb3SMatthew G. Knepley if (bcFunc) {b->func = bcFunc;} 2795b67eacb3SMatthew G. Knepley if (ctx) {b->ctx = ctx;} 2796b67eacb3SMatthew G. Knepley PetscFunctionReturn(0); 2797b67eacb3SMatthew G. Knepley } 2798b67eacb3SMatthew G. Knepley 279958ebd649SToby Isaac /*@ 280058ebd649SToby Isaac PetscDSGetNumBoundary - Get the number of registered BC 280158ebd649SToby Isaac 280258ebd649SToby Isaac Input Parameters: 280358ebd649SToby Isaac . ds - The PetscDS object 280458ebd649SToby Isaac 280558ebd649SToby Isaac Output Parameters: 280658ebd649SToby Isaac . numBd - The number of BC 280758ebd649SToby Isaac 280858ebd649SToby Isaac Level: intermediate 280958ebd649SToby Isaac 281058ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary() 281158ebd649SToby Isaac @*/ 281258ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd) 281358ebd649SToby Isaac { 281458ebd649SToby Isaac DSBoundary b = ds->boundary; 281558ebd649SToby Isaac 281658ebd649SToby Isaac PetscFunctionBegin; 281758ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 281858ebd649SToby Isaac PetscValidPointer(numBd, 2); 281958ebd649SToby Isaac *numBd = 0; 282058ebd649SToby Isaac while (b) {++(*numBd); b = b->next;} 282158ebd649SToby Isaac PetscFunctionReturn(0); 282258ebd649SToby Isaac } 282358ebd649SToby Isaac 282458ebd649SToby Isaac /*@C 28259a6efb6aSMatthew G. Knepley PetscDSGetBoundary - Gets a boundary condition to the model 282658ebd649SToby Isaac 282758ebd649SToby Isaac Input Parameters: 282858ebd649SToby Isaac + ds - The PetscDS object 282958ebd649SToby Isaac - bd - The BC number 283058ebd649SToby Isaac 283158ebd649SToby Isaac Output Parameters: 28322d47a189SJulian Andrej + type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 283358ebd649SToby Isaac . name - The BC name 283458ebd649SToby Isaac . labelname - The label defining constrained points 283558ebd649SToby Isaac . field - The field to constrain 283658ebd649SToby Isaac . numcomps - The number of constrained field components 283758ebd649SToby Isaac . comps - An array of constrained component numbers 283858ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 283958ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 284058ebd649SToby Isaac . ids - An array of ids for constrained points 284158ebd649SToby Isaac - ctx - An optional user context for bcFunc 284258ebd649SToby Isaac 284358ebd649SToby Isaac Options Database Keys: 284458ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 284558ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 284658ebd649SToby Isaac 284758ebd649SToby Isaac Level: developer 284858ebd649SToby Isaac 284958ebd649SToby Isaac .seealso: PetscDSAddBoundary() 285058ebd649SToby Isaac @*/ 2851a30ec4eaSSatish 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) 285258ebd649SToby Isaac { 285358ebd649SToby Isaac DSBoundary b = ds->boundary; 285458ebd649SToby Isaac PetscInt n = 0; 285558ebd649SToby Isaac 285658ebd649SToby Isaac PetscFunctionBegin; 285758ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 285858ebd649SToby Isaac while (b) { 285958ebd649SToby Isaac if (n == bd) break; 286058ebd649SToby Isaac b = b->next; 286158ebd649SToby Isaac ++n; 286258ebd649SToby Isaac } 286358ebd649SToby Isaac if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 2864f971fd6bSMatthew G. Knepley if (type) { 2865f971fd6bSMatthew G. Knepley PetscValidPointer(type, 3); 2866f971fd6bSMatthew G. Knepley *type = b->type; 286758ebd649SToby Isaac } 286858ebd649SToby Isaac if (name) { 286958ebd649SToby Isaac PetscValidPointer(name, 4); 287058ebd649SToby Isaac *name = b->name; 287158ebd649SToby Isaac } 287258ebd649SToby Isaac if (labelname) { 287358ebd649SToby Isaac PetscValidPointer(labelname, 5); 287458ebd649SToby Isaac *labelname = b->labelname; 287558ebd649SToby Isaac } 287658ebd649SToby Isaac if (field) { 287758ebd649SToby Isaac PetscValidPointer(field, 6); 287858ebd649SToby Isaac *field = b->field; 287958ebd649SToby Isaac } 288058ebd649SToby Isaac if (numcomps) { 288158ebd649SToby Isaac PetscValidPointer(numcomps, 7); 288258ebd649SToby Isaac *numcomps = b->numcomps; 288358ebd649SToby Isaac } 288458ebd649SToby Isaac if (comps) { 288558ebd649SToby Isaac PetscValidPointer(comps, 8); 288658ebd649SToby Isaac *comps = b->comps; 288758ebd649SToby Isaac } 288858ebd649SToby Isaac if (func) { 288958ebd649SToby Isaac PetscValidPointer(func, 9); 289058ebd649SToby Isaac *func = b->func; 289158ebd649SToby Isaac } 289258ebd649SToby Isaac if (numids) { 289358ebd649SToby Isaac PetscValidPointer(numids, 10); 289458ebd649SToby Isaac *numids = b->numids; 289558ebd649SToby Isaac } 289658ebd649SToby Isaac if (ids) { 289758ebd649SToby Isaac PetscValidPointer(ids, 11); 289858ebd649SToby Isaac *ids = b->ids; 289958ebd649SToby Isaac } 290058ebd649SToby Isaac if (ctx) { 290158ebd649SToby Isaac PetscValidPointer(ctx, 12); 290258ebd649SToby Isaac *ctx = b->ctx; 290358ebd649SToby Isaac } 290458ebd649SToby Isaac PetscFunctionReturn(0); 290558ebd649SToby Isaac } 290658ebd649SToby Isaac 29079252d075SMatthew G. Knepley /*@ 29089252d075SMatthew G. Knepley PetscDSCopyBoundary - Copy all boundary condition objects to the new problem 29099252d075SMatthew G. Knepley 29109252d075SMatthew G. Knepley Not collective 29119252d075SMatthew G. Knepley 29129252d075SMatthew G. Knepley Input Parameter: 29139252d075SMatthew G. Knepley . prob - The PetscDS object 29149252d075SMatthew G. Knepley 29159252d075SMatthew G. Knepley Output Parameter: 29169252d075SMatthew G. Knepley . newprob - The PetscDS copy 29179252d075SMatthew G. Knepley 29189252d075SMatthew G. Knepley Level: intermediate 29199252d075SMatthew G. Knepley 29209252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 29219252d075SMatthew G. Knepley @*/ 2922dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB) 2923dff059c6SToby Isaac { 2924dff059c6SToby Isaac DSBoundary b, next, *lastnext; 2925dff059c6SToby Isaac PetscErrorCode ierr; 2926dff059c6SToby Isaac 2927dff059c6SToby Isaac PetscFunctionBegin; 2928dff059c6SToby Isaac PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1); 2929dff059c6SToby Isaac PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2); 2930dff059c6SToby Isaac if (probA == probB) PetscFunctionReturn(0); 2931dff059c6SToby Isaac next = probB->boundary; 2932dff059c6SToby Isaac while (next) { 2933dff059c6SToby Isaac DSBoundary b = next; 2934dff059c6SToby Isaac 2935dff059c6SToby Isaac next = b->next; 2936dff059c6SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 2937dff059c6SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 2938dff059c6SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 2939dff059c6SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 2940dff059c6SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 2941dff059c6SToby Isaac } 2942dff059c6SToby Isaac lastnext = &(probB->boundary); 2943dff059c6SToby Isaac for (b = probA->boundary; b; b = b->next) { 2944dff059c6SToby Isaac DSBoundary bNew; 2945dff059c6SToby Isaac 2946459726d8SSatish Balay ierr = PetscNew(&bNew);CHKERRQ(ierr); 2947dff059c6SToby Isaac bNew->numcomps = b->numcomps; 2948dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr); 2949580bdb30SBarry Smith ierr = PetscArraycpy(bNew->comps, b->comps, bNew->numcomps);CHKERRQ(ierr); 2950dff059c6SToby Isaac bNew->numids = b->numids; 2951dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr); 2952580bdb30SBarry Smith ierr = PetscArraycpy(bNew->ids, b->ids, bNew->numids);CHKERRQ(ierr); 2953dff059c6SToby Isaac ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr); 2954dff059c6SToby Isaac ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr); 2955dff059c6SToby Isaac bNew->ctx = b->ctx; 2956f971fd6bSMatthew G. Knepley bNew->type = b->type; 2957dff059c6SToby Isaac bNew->field = b->field; 2958dff059c6SToby Isaac bNew->func = b->func; 2959dff059c6SToby Isaac 2960dff059c6SToby Isaac *lastnext = bNew; 2961dff059c6SToby Isaac lastnext = &(bNew->next); 2962dff059c6SToby Isaac } 2963dff059c6SToby Isaac PetscFunctionReturn(0); 2964dff059c6SToby Isaac } 2965dff059c6SToby Isaac 29669252d075SMatthew G. Knepley /*@C 29679252d075SMatthew G. Knepley PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout 29689252d075SMatthew G. Knepley 29699252d075SMatthew G. Knepley Not collective 29709252d075SMatthew G. Knepley 29719252d075SMatthew G. Knepley Input Parameter: 29729252d075SMatthew G. Knepley + prob - The PetscDS object 29739252d075SMatthew G. Knepley . numFields - Number of new fields 29749252d075SMatthew G. Knepley - fields - Old field number for each new field 29759252d075SMatthew G. Knepley 29769252d075SMatthew G. Knepley Output Parameter: 29779252d075SMatthew G. Knepley . newprob - The PetscDS copy 29789252d075SMatthew G. Knepley 29799252d075SMatthew G. Knepley Level: intermediate 29809252d075SMatthew G. Knepley 29819252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 29829252d075SMatthew G. Knepley @*/ 29839252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 29849252d075SMatthew G. Knepley { 29859252d075SMatthew G. Knepley PetscInt Nf, Nfn, fn, gn; 29869252d075SMatthew G. Knepley PetscErrorCode ierr; 29879252d075SMatthew G. Knepley 29889252d075SMatthew G. Knepley PetscFunctionBegin; 29899252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 29909252d075SMatthew G. Knepley if (fields) PetscValidPointer(fields, 3); 29919252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 29929252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 29939252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr); 29949252d075SMatthew 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); 29959252d075SMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 29969252d075SMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 29979252d075SMatthew G. Knepley PetscPointFunc obj; 29989252d075SMatthew G. Knepley PetscPointFunc f0, f1; 29999252d075SMatthew G. Knepley PetscBdPointFunc f0Bd, f1Bd; 30009252d075SMatthew G. Knepley PetscRiemannFunc r; 30019252d075SMatthew G. Knepley 3002c52f1e13SMatthew G. Knepley if (f >= Nf) continue; 30039252d075SMatthew G. Knepley ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr); 30049252d075SMatthew G. Knepley ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr); 30059252d075SMatthew G. Knepley ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr); 30069252d075SMatthew G. Knepley ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr); 30079252d075SMatthew G. Knepley ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr); 30089252d075SMatthew G. Knepley ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr); 30099252d075SMatthew G. Knepley ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr); 30109252d075SMatthew G. Knepley ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr); 30119252d075SMatthew G. Knepley for (gn = 0; gn < numFields; ++gn) { 30129252d075SMatthew G. Knepley const PetscInt g = fields ? fields[gn] : gn; 30139252d075SMatthew G. Knepley PetscPointJac g0, g1, g2, g3; 30149252d075SMatthew G. Knepley PetscPointJac g0p, g1p, g2p, g3p; 30159252d075SMatthew G. Knepley PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd; 30169252d075SMatthew G. Knepley 3017c52f1e13SMatthew G. Knepley if (g >= Nf) continue; 30189252d075SMatthew G. Knepley ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr); 30199252d075SMatthew G. Knepley ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr); 30209252d075SMatthew G. Knepley ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr); 30219252d075SMatthew G. Knepley ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr); 30229252d075SMatthew G. Knepley ierr = PetscDSSetJacobianPreconditioner(prob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr); 30239252d075SMatthew G. Knepley ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr); 30249252d075SMatthew G. Knepley } 30259252d075SMatthew G. Knepley } 30269252d075SMatthew G. Knepley PetscFunctionReturn(0); 30279252d075SMatthew G. Knepley } 30289252d075SMatthew G. Knepley 3029da51fcedSMatthew G. Knepley /*@ 3030da51fcedSMatthew G. Knepley PetscDSCopyEquations - Copy all pointwise function pointers to the new problem 3031da51fcedSMatthew G. Knepley 3032da51fcedSMatthew G. Knepley Not collective 3033da51fcedSMatthew G. Knepley 3034da51fcedSMatthew G. Knepley Input Parameter: 3035da51fcedSMatthew G. Knepley . prob - The PetscDS object 3036da51fcedSMatthew G. Knepley 3037da51fcedSMatthew G. Knepley Output Parameter: 3038da51fcedSMatthew G. Knepley . newprob - The PetscDS copy 3039da51fcedSMatthew G. Knepley 3040da51fcedSMatthew G. Knepley Level: intermediate 3041da51fcedSMatthew G. Knepley 30429252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 3043da51fcedSMatthew G. Knepley @*/ 3044da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob) 3045da51fcedSMatthew G. Knepley { 30469252d075SMatthew G. Knepley PetscInt Nf, Ng; 3047da51fcedSMatthew G. Knepley PetscErrorCode ierr; 3048da51fcedSMatthew G. Knepley 3049da51fcedSMatthew G. Knepley PetscFunctionBegin; 3050da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3051da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 3052da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3053da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr); 305413903a91SSatish Balay if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng); 30559252d075SMatthew G. Knepley ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr); 30569252d075SMatthew G. Knepley PetscFunctionReturn(0); 30579252d075SMatthew G. Knepley } 30589252d075SMatthew G. Knepley /*@ 30599252d075SMatthew G. Knepley PetscDSCopyConstants - Copy all constants to the new problem 3060da51fcedSMatthew G. Knepley 30619252d075SMatthew G. Knepley Not collective 30629252d075SMatthew G. Knepley 30639252d075SMatthew G. Knepley Input Parameter: 30649252d075SMatthew G. Knepley . prob - The PetscDS object 30659252d075SMatthew G. Knepley 30669252d075SMatthew G. Knepley Output Parameter: 30679252d075SMatthew G. Knepley . newprob - The PetscDS copy 30689252d075SMatthew G. Knepley 30699252d075SMatthew G. Knepley Level: intermediate 30709252d075SMatthew G. Knepley 30719252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 30729252d075SMatthew G. Knepley @*/ 30739252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob) 30749252d075SMatthew G. Knepley { 30759252d075SMatthew G. Knepley PetscInt Nc; 30769252d075SMatthew G. Knepley const PetscScalar *constants; 30779252d075SMatthew G. Knepley PetscErrorCode ierr; 30789252d075SMatthew G. Knepley 30799252d075SMatthew G. Knepley PetscFunctionBegin; 30809252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30819252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 30829252d075SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr); 30839252d075SMatthew G. Knepley ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr); 3084da51fcedSMatthew G. Knepley PetscFunctionReturn(0); 3085da51fcedSMatthew G. Knepley } 3086da51fcedSMatthew G. Knepley 3087b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob) 3088b1353e8eSMatthew G. Knepley { 3089df3a45bdSMatthew G. Knepley PetscInt dim, Nf, f; 3090b1353e8eSMatthew G. Knepley PetscErrorCode ierr; 3091b1353e8eSMatthew G. Knepley 3092b1353e8eSMatthew G. Knepley PetscFunctionBegin; 3093b1353e8eSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3094b1353e8eSMatthew G. Knepley PetscValidPointer(subprob, 3); 3095b1353e8eSMatthew G. Knepley if (height == 0) {*subprob = prob; PetscFunctionReturn(0);} 3096b1353e8eSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3097df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 3098df3a45bdSMatthew 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); 3099df3a45bdSMatthew G. Knepley if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);} 3100df3a45bdSMatthew G. Knepley if (!prob->subprobs[height-1]) { 3101b1353e8eSMatthew G. Knepley PetscInt cdim; 3102b1353e8eSMatthew G. Knepley 3103df3a45bdSMatthew G. Knepley ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr); 3104b1353e8eSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr); 3105df3a45bdSMatthew G. Knepley ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr); 3106b1353e8eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3107b1353e8eSMatthew G. Knepley PetscFE subfe; 3108b1353e8eSMatthew G. Knepley PetscObject obj; 3109b1353e8eSMatthew G. Knepley PetscClassId id; 3110b1353e8eSMatthew G. Knepley 3111b1353e8eSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 3112b1353e8eSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3113b1353e8eSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);} 3114b1353e8eSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f); 3115df3a45bdSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr); 3116b1353e8eSMatthew G. Knepley } 3117b1353e8eSMatthew G. Knepley } 3118df3a45bdSMatthew G. Knepley *subprob = prob->subprobs[height-1]; 3119b1353e8eSMatthew G. Knepley PetscFunctionReturn(0); 3120b1353e8eSMatthew G. Knepley } 3121b1353e8eSMatthew G. Knepley 3122c7bd5f0bSMatthew G. Knepley PetscErrorCode PetscDSIsFE_Internal(PetscDS ds, PetscInt f, PetscBool *isFE) 3123c7bd5f0bSMatthew G. Knepley { 3124c7bd5f0bSMatthew G. Knepley PetscObject obj; 3125c7bd5f0bSMatthew G. Knepley PetscClassId id; 3126c7bd5f0bSMatthew G. Knepley PetscInt Nf; 3127c7bd5f0bSMatthew G. Knepley PetscErrorCode ierr; 3128c7bd5f0bSMatthew G. Knepley 3129c7bd5f0bSMatthew G. Knepley PetscFunctionBegin; 3130c7bd5f0bSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3131c7bd5f0bSMatthew G. Knepley PetscValidPointer(isFE, 3); 3132c7bd5f0bSMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 3133c7bd5f0bSMatthew G. Knepley if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf); 3134c7bd5f0bSMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr); 3135c7bd5f0bSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3136c7bd5f0bSMatthew G. Knepley if (id == PETSCFE_CLASSID) *isFE = PETSC_TRUE; 3137c7bd5f0bSMatthew G. Knepley else *isFE = PETSC_FALSE; 3138c7bd5f0bSMatthew G. Knepley PetscFunctionReturn(0); 3139c7bd5f0bSMatthew G. Knepley } 3140c7bd5f0bSMatthew G. Knepley 3141bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob) 31422764a2aaSMatthew G. Knepley { 3143931fb3b8SToby Isaac PetscErrorCode ierr; 3144931fb3b8SToby Isaac 31452764a2aaSMatthew G. Knepley PetscFunctionBegin; 3146931fb3b8SToby Isaac ierr = PetscFree(prob->data);CHKERRQ(ierr); 31472764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31482764a2aaSMatthew G. Knepley } 31492764a2aaSMatthew G. Knepley 3150bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob) 31512764a2aaSMatthew G. Knepley { 31522764a2aaSMatthew G. Knepley PetscFunctionBegin; 31532764a2aaSMatthew G. Knepley prob->ops->setfromoptions = NULL; 31542764a2aaSMatthew G. Knepley prob->ops->setup = NULL; 31552764a2aaSMatthew G. Knepley prob->ops->view = NULL; 31562764a2aaSMatthew G. Knepley prob->ops->destroy = PetscDSDestroy_Basic; 31572764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31582764a2aaSMatthew G. Knepley } 31592764a2aaSMatthew G. Knepley 31602764a2aaSMatthew G. Knepley /*MC 31612764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 31622764a2aaSMatthew G. Knepley 31632764a2aaSMatthew G. Knepley Level: intermediate 31642764a2aaSMatthew G. Knepley 31652764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType() 31662764a2aaSMatthew G. Knepley M*/ 31672764a2aaSMatthew G. Knepley 31682764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob) 31692764a2aaSMatthew G. Knepley { 31702764a2aaSMatthew G. Knepley PetscDS_Basic *b; 31712764a2aaSMatthew G. Knepley PetscErrorCode ierr; 31722764a2aaSMatthew G. Knepley 31732764a2aaSMatthew G. Knepley PetscFunctionBegin; 3174931fb3b8SToby Isaac PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 31752764a2aaSMatthew G. Knepley ierr = PetscNewLog(prob, &b);CHKERRQ(ierr); 31762764a2aaSMatthew G. Knepley prob->data = b; 31772764a2aaSMatthew G. Knepley 31782764a2aaSMatthew G. Knepley ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr); 31792764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31802764a2aaSMatthew G. Knepley } 3181