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 } 179f9244615SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " %D-jet", prob->jetDegree[f]);CHKERRQ(ierr); 1807d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 1814727e194SMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 1825d160056SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 1837d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);} 1847d8a60eaSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);} 1855d160056SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 18640967b3bSMatthew G. Knepley 18740967b3bSMatthew G. Knepley for (b = prob->boundary; b; b = b->next) { 18840967b3bSMatthew G. Knepley PetscInt c, i; 18940967b3bSMatthew G. Knepley 19040967b3bSMatthew G. Knepley if (b->field != f) continue; 19140967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 192*45480ffeSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->lname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr); 193*45480ffeSMatthew G. Knepley if (!b->Nc) { 19440967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " all components\n");CHKERRQ(ierr); 19540967b3bSMatthew G. Knepley } else { 19640967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " components: ");CHKERRQ(ierr); 19740967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 198*45480ffeSMatthew G. Knepley for (c = 0; c < b->Nc; ++c) { 19940967b3bSMatthew G. Knepley if (c > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 20040967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->comps[c]);CHKERRQ(ierr); 20140967b3bSMatthew G. Knepley } 20240967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 20340967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 20440967b3bSMatthew G. Knepley } 205*45480ffeSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " values: ");CHKERRQ(ierr); 20640967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 207*45480ffeSMatthew G. Knepley for (i = 0; i < b->Nv; ++i) { 20840967b3bSMatthew G. Knepley if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 209*45480ffeSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->values[i]);CHKERRQ(ierr); 21040967b3bSMatthew G. Knepley } 21140967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 21240967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 213*45480ffeSMatthew G. Knepley ierr = PetscWeakFormView(b->wf, viewer);CHKERRQ(ierr); 21440967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 21540967b3bSMatthew G. Knepley } 2167d8a60eaSMatthew G. Knepley } 21797b6e6e8SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr); 21897b6e6e8SMatthew G. Knepley if (numConstants) { 21997b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr); 22097b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 22157fc01e9SMatthew G. Knepley for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);} 22297b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 22397b6e6e8SMatthew G. Knepley } 2246528b96dSMatthew G. Knepley ierr = PetscWeakFormView(prob->wf, viewer);CHKERRQ(ierr); 2257d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 2267d8a60eaSMatthew G. Knepley PetscFunctionReturn(0); 2277d8a60eaSMatthew G. Knepley } 2287d8a60eaSMatthew G. Knepley 2292764a2aaSMatthew G. Knepley /*@C 230fe2efc57SMark PetscDSViewFromOptions - View from Options 231fe2efc57SMark 232fe2efc57SMark Collective on PetscDS 233fe2efc57SMark 234fe2efc57SMark Input Parameters: 235fe2efc57SMark + A - the PetscDS object 236736c3998SJose E. Roman . obj - Optional object 237736c3998SJose E. Roman - name - command line option 238fe2efc57SMark 239fe2efc57SMark Level: intermediate 240fe2efc57SMark .seealso: PetscDS, PetscDSView, PetscObjectViewFromOptions(), PetscDSCreate() 241fe2efc57SMark @*/ 242fe2efc57SMark PetscErrorCode PetscDSViewFromOptions(PetscDS A,PetscObject obj,const char name[]) 243fe2efc57SMark { 244fe2efc57SMark PetscErrorCode ierr; 245fe2efc57SMark 246fe2efc57SMark PetscFunctionBegin; 247fe2efc57SMark PetscValidHeaderSpecific(A,PETSCDS_CLASSID,1); 248fe2efc57SMark ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr); 249fe2efc57SMark PetscFunctionReturn(0); 250fe2efc57SMark } 251fe2efc57SMark 252fe2efc57SMark /*@C 2532764a2aaSMatthew G. Knepley PetscDSView - Views a PetscDS 2542764a2aaSMatthew G. Knepley 255d083f849SBarry Smith Collective on prob 2562764a2aaSMatthew G. Knepley 2572764a2aaSMatthew G. Knepley Input Parameter: 2582764a2aaSMatthew G. Knepley + prob - the PetscDS object to view 2592764a2aaSMatthew G. Knepley - v - the viewer 2602764a2aaSMatthew G. Knepley 2612764a2aaSMatthew G. Knepley Level: developer 2622764a2aaSMatthew G. Knepley 2632764a2aaSMatthew G. Knepley .seealso PetscDSDestroy() 2642764a2aaSMatthew G. Knepley @*/ 2652764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v) 2662764a2aaSMatthew G. Knepley { 2677d8a60eaSMatthew G. Knepley PetscBool iascii; 2682764a2aaSMatthew G. Knepley PetscErrorCode ierr; 2692764a2aaSMatthew G. Knepley 2702764a2aaSMatthew G. Knepley PetscFunctionBegin; 2712764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2722764a2aaSMatthew G. Knepley if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);} 2737d8a60eaSMatthew G. Knepley else {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);} 2747d8a60eaSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 2757d8a60eaSMatthew G. Knepley if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);} 2762764a2aaSMatthew G. Knepley if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);} 2772764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 2782764a2aaSMatthew G. Knepley } 2792764a2aaSMatthew G. Knepley 2802764a2aaSMatthew G. Knepley /*@ 2812764a2aaSMatthew G. Knepley PetscDSSetFromOptions - sets parameters in a PetscDS from the options database 2822764a2aaSMatthew G. Knepley 283d083f849SBarry Smith Collective on prob 2842764a2aaSMatthew G. Knepley 2852764a2aaSMatthew G. Knepley Input Parameter: 2862764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for 2872764a2aaSMatthew G. Knepley 2882764a2aaSMatthew G. Knepley Options Database: 28955c1f793SMatthew G. Knepley + -petscds_type <type> : Set the DS type 29055c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS 29155c1f793SMatthew G. Knepley . -petscds_jac_pre : Turn formation of a separate Jacobian preconditioner on and off 29255c1f793SMatthew G. Knepley . -bc_<name> <ids> : Specify a list of label ids for a boundary condition 29355c1f793SMatthew G. Knepley - -bc_<name>_comp <comps> : Specify a list of field components to constrain for a boundary condition 2942764a2aaSMatthew G. Knepley 2952764a2aaSMatthew G. Knepley Level: developer 2962764a2aaSMatthew G. Knepley 2972764a2aaSMatthew G. Knepley .seealso PetscDSView() 2982764a2aaSMatthew G. Knepley @*/ 2992764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob) 3002764a2aaSMatthew G. Knepley { 301f1fd5e65SToby Isaac DSBoundary b; 3022764a2aaSMatthew G. Knepley const char *defaultType; 3032764a2aaSMatthew G. Knepley char name[256]; 3042764a2aaSMatthew G. Knepley PetscBool flg; 3052764a2aaSMatthew G. Knepley PetscErrorCode ierr; 3062764a2aaSMatthew G. Knepley 3072764a2aaSMatthew G. Knepley PetscFunctionBegin; 3082764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3092764a2aaSMatthew G. Knepley if (!((PetscObject) prob)->type_name) { 3102764a2aaSMatthew G. Knepley defaultType = PETSCDSBASIC; 3112764a2aaSMatthew G. Knepley } else { 3122764a2aaSMatthew G. Knepley defaultType = ((PetscObject) prob)->type_name; 3132764a2aaSMatthew G. Knepley } 3140f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 3152764a2aaSMatthew G. Knepley 3162764a2aaSMatthew G. Knepley ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr); 317f1fd5e65SToby Isaac for (b = prob->boundary; b; b = b->next) { 318f1fd5e65SToby Isaac char optname[1024]; 319f1fd5e65SToby Isaac PetscInt ids[1024], len = 1024; 320f1fd5e65SToby Isaac PetscBool flg; 321f1fd5e65SToby Isaac 322f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr); 323f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 324f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr); 325f1fd5e65SToby Isaac if (flg) { 326*45480ffeSMatthew G. Knepley b->Nv = len; 327*45480ffeSMatthew G. Knepley ierr = PetscFree(b->values);CHKERRQ(ierr); 328*45480ffeSMatthew G. Knepley ierr = PetscMalloc1(len, &b->values);CHKERRQ(ierr); 329*45480ffeSMatthew G. Knepley ierr = PetscArraycpy(b->values, ids, len);CHKERRQ(ierr); 330*45480ffeSMatthew G. Knepley ierr = PetscWeakFormRewriteKeys(b->wf, b->label, len, b->values);CHKERRQ(ierr); 331f1fd5e65SToby Isaac } 332e7b0402cSSander Arens len = 1024; 333f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr); 334f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 335f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr); 336f1fd5e65SToby Isaac if (flg) { 337*45480ffeSMatthew G. Knepley b->Nc = len; 338f1fd5e65SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 339f1fd5e65SToby Isaac ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr); 340580bdb30SBarry Smith ierr = PetscArraycpy(b->comps, ids, len);CHKERRQ(ierr); 341f1fd5e65SToby Isaac } 342f1fd5e65SToby Isaac } 3432764a2aaSMatthew G. Knepley ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr); 3442764a2aaSMatthew G. Knepley if (flg) { 3452764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, name);CHKERRQ(ierr); 3462764a2aaSMatthew G. Knepley } else if (!((PetscObject) prob)->type_name) { 3472764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr); 3482764a2aaSMatthew G. Knepley } 34955c1f793SMatthew G. Knepley ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr); 3502764a2aaSMatthew G. Knepley if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);} 3512764a2aaSMatthew G. Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 3520633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr); 3532764a2aaSMatthew G. Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 3545d160056SMatthew G. Knepley if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);} 3552764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 3562764a2aaSMatthew G. Knepley } 3572764a2aaSMatthew G. Knepley 3582764a2aaSMatthew G. Knepley /*@C 3592764a2aaSMatthew G. Knepley PetscDSSetUp - Construct data structures for the PetscDS 3602764a2aaSMatthew G. Knepley 361d083f849SBarry Smith Collective on prob 3622764a2aaSMatthew G. Knepley 3632764a2aaSMatthew G. Knepley Input Parameter: 3642764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup 3652764a2aaSMatthew G. Knepley 3662764a2aaSMatthew G. Knepley Level: developer 3672764a2aaSMatthew G. Knepley 3682764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy() 3692764a2aaSMatthew G. Knepley @*/ 3702764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob) 3712764a2aaSMatthew G. Knepley { 3722764a2aaSMatthew G. Knepley const PetscInt Nf = prob->Nf; 373f9244615SMatthew G. Knepley PetscBool hasH = PETSC_FALSE; 3744bee2e38SMatthew G. Knepley PetscInt dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f; 3752764a2aaSMatthew G. Knepley PetscErrorCode ierr; 3762764a2aaSMatthew G. Knepley 3772764a2aaSMatthew G. Knepley PetscFunctionBegin; 3782764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3792764a2aaSMatthew G. Knepley if (prob->setup) PetscFunctionReturn(0); 3802764a2aaSMatthew G. Knepley /* Calculate sizes */ 3812764a2aaSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 382d1506c7cSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr); 383f744cafaSSander Arens prob->totDim = prob->totComp = 0; 38447e57110SSander Arens ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr); 385f744cafaSSander Arens ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr); 386ef0bb6c7SMatthew G. Knepley ierr = PetscMalloc2(Nf,&prob->T,Nf,&prob->Tf);CHKERRQ(ierr); 3872764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3889de99aefSMatthew G. Knepley PetscObject obj; 3899de99aefSMatthew G. Knepley PetscClassId id; 390665f567fSMatthew G. Knepley PetscQuadrature q = NULL; 3919de99aefSMatthew G. Knepley PetscInt Nq = 0, Nb, Nc; 3922764a2aaSMatthew G. Knepley 3939de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 394f9244615SMatthew G. Knepley if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE; 395665f567fSMatthew G. Knepley if (!obj) { 396665f567fSMatthew G. Knepley /* Empty mesh */ 397665f567fSMatthew G. Knepley Nb = Nc = 0; 398665f567fSMatthew G. Knepley prob->T[f] = prob->Tf[f] = NULL; 399665f567fSMatthew G. Knepley } else { 4009de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 4019de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 4029de99aefSMatthew G. Knepley PetscFE fe = (PetscFE) obj; 4039de99aefSMatthew G. Knepley 4042764a2aaSMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr); 4052764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 4062764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 407f9244615SMatthew G. Knepley ierr = PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f]);CHKERRQ(ierr); 408f9244615SMatthew G. Knepley ierr = PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f]);CHKERRQ(ierr); 4099de99aefSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 4109de99aefSMatthew G. Knepley PetscFV fv = (PetscFV) obj; 4119de99aefSMatthew G. Knepley 4129de99aefSMatthew G. Knepley ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr); 4139de99aefSMatthew G. Knepley ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr); 4149c3cf19fSMatthew G. Knepley Nb = Nc; 415ef0bb6c7SMatthew G. Knepley ierr = PetscFVGetCellTabulation(fv, &prob->T[f]);CHKERRQ(ierr); 4164d0b9603SSander Arens /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */ 417abac5ca0SMatthew G. Knepley } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f); 418665f567fSMatthew G. Knepley } 41947e57110SSander Arens prob->Nc[f] = Nc; 42047e57110SSander Arens prob->Nb[f] = Nb; 421194d53e6SMatthew G. Knepley prob->off[f+1] = Nc + prob->off[f]; 422194d53e6SMatthew G. Knepley prob->offDer[f+1] = Nc*dim + prob->offDer[f]; 423a6b92713SMatthew G. Knepley if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);} 4242764a2aaSMatthew G. Knepley NqMax = PetscMax(NqMax, Nq); 4254bee2e38SMatthew G. Knepley NbMax = PetscMax(NbMax, Nb); 4262764a2aaSMatthew G. Knepley NcMax = PetscMax(NcMax, Nc); 4279c3cf19fSMatthew G. Knepley prob->totDim += Nb; 4282764a2aaSMatthew G. Knepley prob->totComp += Nc; 42994a5e212SMatthew G. Knepley /* There are two faces for all fields but the cohesive field on a hybrid cell */ 43094a5e212SMatthew G. Knepley if (prob->isHybrid && (f < Nf-1)) prob->totDim += Nb; 4312764a2aaSMatthew G. Knepley } 4322764a2aaSMatthew G. Knepley /* Allocate works space */ 43394a5e212SMatthew G. Knepley if (prob->isHybrid) NsMax = 2; 434f9244615SMatthew G. Knepley ierr = PetscMalloc3(NsMax*prob->totComp,&prob->u,NsMax*prob->totComp,&prob->u_t,NsMax*prob->totComp*dimEmbed + (hasH ? NsMax*prob->totComp*dimEmbed*dimEmbed : 0),&prob->u_x);CHKERRQ(ierr); 4354bee2e38SMatthew 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); 43627f02ce8SMatthew G. Knepley ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dimEmbed,&prob->f1, 43727f02ce8SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g1, 43827f02ce8SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed*dimEmbed,&prob->g3);CHKERRQ(ierr); 4392764a2aaSMatthew G. Knepley if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);} 4402764a2aaSMatthew G. Knepley prob->setup = PETSC_TRUE; 4412764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4422764a2aaSMatthew G. Knepley } 4432764a2aaSMatthew G. Knepley 4442764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob) 4452764a2aaSMatthew G. Knepley { 4462764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4472764a2aaSMatthew G. Knepley 4482764a2aaSMatthew G. Knepley PetscFunctionBegin; 44947e57110SSander Arens ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr); 450f744cafaSSander Arens ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr); 451ef0bb6c7SMatthew G. Knepley ierr = PetscFree2(prob->T,prob->Tf);CHKERRQ(ierr); 4524bee2e38SMatthew G. Knepley ierr = PetscFree3(prob->u,prob->u_t,prob->u_x);CHKERRQ(ierr); 4534bee2e38SMatthew G. Knepley ierr = PetscFree5(prob->x,prob->basisReal, prob->basisDerReal,prob->testReal,prob->testDerReal);CHKERRQ(ierr); 4542764a2aaSMatthew G. Knepley ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr); 4552764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4562764a2aaSMatthew G. Knepley } 4572764a2aaSMatthew G. Knepley 4582764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew) 4592764a2aaSMatthew G. Knepley { 460f744cafaSSander Arens PetscObject *tmpd; 46134aa8a36SMatthew G. Knepley PetscBool *tmpi; 462f9244615SMatthew G. Knepley PetscInt *tmpk; 4636528b96dSMatthew G. Knepley PetscPointFunc *tmpup; 464f2cacb80SMatthew G. Knepley PetscSimplePointFunc *tmpexactSol, *tmpexactSol_t; 465f2cacb80SMatthew G. Knepley void **tmpexactCtx, **tmpexactCtx_t; 4660c2f2876SMatthew G. Knepley void **tmpctx; 46734aa8a36SMatthew G. Knepley PetscInt Nf = prob->Nf, f; 4682764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4692764a2aaSMatthew G. Knepley 4702764a2aaSMatthew G. Knepley PetscFunctionBegin; 4712764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 4722764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 4732764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr); 474f9244615SMatthew G. Knepley ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpk);CHKERRQ(ierr); 475f9244615SMatthew G. Knepley for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; tmpk[f] = prob->jetDegree[f];} 476f9244615SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpk[f] = 1;} 477f9244615SMatthew G. Knepley ierr = PetscFree3(prob->disc, prob->implicit, prob->jetDegree);CHKERRQ(ierr); 4786528b96dSMatthew G. Knepley ierr = PetscWeakFormSetNumFields(prob->wf, NfNew);CHKERRQ(ierr); 4792764a2aaSMatthew G. Knepley prob->Nf = NfNew; 4802764a2aaSMatthew G. Knepley prob->disc = tmpd; 481249df284SMatthew G. Knepley prob->implicit = tmpi; 482f9244615SMatthew G. Knepley prob->jetDegree = tmpk; 4836528b96dSMatthew G. Knepley ierr = PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx);CHKERRQ(ierr); 48432d2bbc9SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f]; 4850c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f]; 48632d2bbc9SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL; 4870c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL; 4886528b96dSMatthew G. Knepley ierr = PetscFree2(prob->update, prob->ctx);CHKERRQ(ierr); 48932d2bbc9SMatthew G. Knepley prob->update = tmpup; 4900c2f2876SMatthew G. Knepley prob->ctx = tmpctx; 4916528b96dSMatthew G. Knepley ierr = PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t);CHKERRQ(ierr); 492c371a6d1SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f]; 49395cbbfd3SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f]; 494f2cacb80SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f]; 495f2cacb80SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f]; 496c371a6d1SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL; 49795cbbfd3SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL; 498f2cacb80SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL; 499f2cacb80SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL; 5006528b96dSMatthew G. Knepley ierr = PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t);CHKERRQ(ierr); 501c371a6d1SMatthew G. Knepley prob->exactSol = tmpexactSol; 50295cbbfd3SMatthew G. Knepley prob->exactCtx = tmpexactCtx; 503f2cacb80SMatthew G. Knepley prob->exactSol_t = tmpexactSol_t; 504f2cacb80SMatthew G. Knepley prob->exactCtx_t = tmpexactCtx_t; 5052764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5062764a2aaSMatthew G. Knepley } 5072764a2aaSMatthew G. Knepley 5082764a2aaSMatthew G. Knepley /*@ 5092764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 5102764a2aaSMatthew G. Knepley 511d083f849SBarry Smith Collective on prob 5122764a2aaSMatthew G. Knepley 5132764a2aaSMatthew G. Knepley Input Parameter: 5142764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 5152764a2aaSMatthew G. Knepley 5162764a2aaSMatthew G. Knepley Level: developer 5172764a2aaSMatthew G. Knepley 5182764a2aaSMatthew G. Knepley .seealso PetscDSView() 5192764a2aaSMatthew G. Knepley @*/ 5206528b96dSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *ds) 5212764a2aaSMatthew G. Knepley { 5222764a2aaSMatthew G. Knepley PetscInt f; 5232764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5242764a2aaSMatthew G. Knepley 5252764a2aaSMatthew G. Knepley PetscFunctionBegin; 5266528b96dSMatthew G. Knepley if (!*ds) PetscFunctionReturn(0); 5276528b96dSMatthew G. Knepley PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1); 5282764a2aaSMatthew G. Knepley 5296528b96dSMatthew G. Knepley if (--((PetscObject)(*ds))->refct > 0) {*ds = NULL; PetscFunctionReturn(0);} 5306528b96dSMatthew G. Knepley ((PetscObject) (*ds))->refct = 0; 5316528b96dSMatthew G. Knepley if ((*ds)->subprobs) { 532df3a45bdSMatthew G. Knepley PetscInt dim, d; 533df3a45bdSMatthew G. Knepley 5346528b96dSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(*ds, &dim);CHKERRQ(ierr); 5356528b96dSMatthew G. Knepley for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*ds)->subprobs[d]);CHKERRQ(ierr);} 536df3a45bdSMatthew G. Knepley } 5376528b96dSMatthew G. Knepley ierr = PetscFree((*ds)->subprobs);CHKERRQ(ierr); 5386528b96dSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(*ds);CHKERRQ(ierr); 5396528b96dSMatthew G. Knepley for (f = 0; f < (*ds)->Nf; ++f) { 5406528b96dSMatthew G. Knepley ierr = PetscObjectDereference((*ds)->disc[f]);CHKERRQ(ierr); 5412764a2aaSMatthew G. Knepley } 5426528b96dSMatthew G. Knepley ierr = PetscFree3((*ds)->disc, (*ds)->implicit, (*ds)->jetDegree);CHKERRQ(ierr); 5436528b96dSMatthew G. Knepley ierr = PetscWeakFormDestroy(&(*ds)->wf);CHKERRQ(ierr); 5446528b96dSMatthew G. Knepley ierr = PetscFree2((*ds)->update,(*ds)->ctx);CHKERRQ(ierr); 5456528b96dSMatthew G. Knepley ierr = PetscFree4((*ds)->exactSol,(*ds)->exactCtx,(*ds)->exactSol_t,(*ds)->exactCtx_t);CHKERRQ(ierr); 5466528b96dSMatthew G. Knepley if ((*ds)->ops->destroy) {ierr = (*(*ds)->ops->destroy)(*ds);CHKERRQ(ierr);} 547*45480ffeSMatthew G. Knepley ierr = PetscDSDestroyBoundary(*ds);CHKERRQ(ierr); 5486528b96dSMatthew G. Knepley ierr = PetscFree((*ds)->constants);CHKERRQ(ierr); 5496528b96dSMatthew G. Knepley ierr = PetscHeaderDestroy(ds);CHKERRQ(ierr); 5502764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5512764a2aaSMatthew G. Knepley } 5522764a2aaSMatthew G. Knepley 5532764a2aaSMatthew G. Knepley /*@ 5542764a2aaSMatthew G. Knepley PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType(). 5552764a2aaSMatthew G. Knepley 556d083f849SBarry Smith Collective 5572764a2aaSMatthew G. Knepley 5582764a2aaSMatthew G. Knepley Input Parameter: 5592764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object 5602764a2aaSMatthew G. Knepley 5612764a2aaSMatthew G. Knepley Output Parameter: 5626528b96dSMatthew G. Knepley . ds - The PetscDS object 5632764a2aaSMatthew G. Knepley 5642764a2aaSMatthew G. Knepley Level: beginner 5652764a2aaSMatthew G. Knepley 5662764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC 5672764a2aaSMatthew G. Knepley @*/ 5686528b96dSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds) 5692764a2aaSMatthew G. Knepley { 5702764a2aaSMatthew G. Knepley PetscDS p; 5712764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5722764a2aaSMatthew G. Knepley 5732764a2aaSMatthew G. Knepley PetscFunctionBegin; 5746528b96dSMatthew G. Knepley PetscValidPointer(ds, 2); 5756528b96dSMatthew G. Knepley *ds = NULL; 5762764a2aaSMatthew G. Knepley ierr = PetscDSInitializePackage();CHKERRQ(ierr); 5772764a2aaSMatthew G. Knepley 57873107ff1SLisandro Dalcin ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr); 5792764a2aaSMatthew G. Knepley 5802764a2aaSMatthew G. Knepley p->Nf = 0; 5812764a2aaSMatthew G. Knepley p->setup = PETSC_FALSE; 58297b6e6e8SMatthew G. Knepley p->numConstants = 0; 58397b6e6e8SMatthew G. Knepley p->constants = NULL; 584a859676bSMatthew G. Knepley p->dimEmbed = -1; 58555c1f793SMatthew G. Knepley p->useJacPre = PETSC_TRUE; 5866528b96dSMatthew G. Knepley ierr = PetscWeakFormCreate(comm, &p->wf);CHKERRQ(ierr); 5872764a2aaSMatthew G. Knepley 5886528b96dSMatthew G. Knepley *ds = p; 5892764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5902764a2aaSMatthew G. Knepley } 5912764a2aaSMatthew G. Knepley 592bc4ae4beSMatthew G. Knepley /*@ 593bc4ae4beSMatthew G. Knepley PetscDSGetNumFields - Returns the number of fields in the DS 594bc4ae4beSMatthew G. Knepley 595bc4ae4beSMatthew G. Knepley Not collective 596bc4ae4beSMatthew G. Knepley 597bc4ae4beSMatthew G. Knepley Input Parameter: 598bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 599bc4ae4beSMatthew G. Knepley 600bc4ae4beSMatthew G. Knepley Output Parameter: 601bc4ae4beSMatthew G. Knepley . Nf - The number of fields 602bc4ae4beSMatthew G. Knepley 603bc4ae4beSMatthew G. Knepley Level: beginner 604bc4ae4beSMatthew G. Knepley 605bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate() 606bc4ae4beSMatthew G. Knepley @*/ 6072764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) 6082764a2aaSMatthew G. Knepley { 6092764a2aaSMatthew G. Knepley PetscFunctionBegin; 6102764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6112764a2aaSMatthew G. Knepley PetscValidPointer(Nf, 2); 6122764a2aaSMatthew G. Knepley *Nf = prob->Nf; 6132764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6142764a2aaSMatthew G. Knepley } 6152764a2aaSMatthew G. Knepley 616bc4ae4beSMatthew G. Knepley /*@ 617a859676bSMatthew G. Knepley PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations 618bc4ae4beSMatthew G. Knepley 619bc4ae4beSMatthew G. Knepley Not collective 620bc4ae4beSMatthew G. Knepley 621bc4ae4beSMatthew G. Knepley Input Parameter: 622bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 623bc4ae4beSMatthew G. Knepley 624bc4ae4beSMatthew G. Knepley Output Parameter: 625bc4ae4beSMatthew G. Knepley . dim - The spatial dimension 626bc4ae4beSMatthew G. Knepley 627bc4ae4beSMatthew G. Knepley Level: beginner 628bc4ae4beSMatthew G. Knepley 629a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate() 630bc4ae4beSMatthew G. Knepley @*/ 6312764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) 6322764a2aaSMatthew G. Knepley { 6332764a2aaSMatthew G. Knepley PetscErrorCode ierr; 6342764a2aaSMatthew G. Knepley 6352764a2aaSMatthew G. Knepley PetscFunctionBegin; 6362764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6372764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 6382764a2aaSMatthew G. Knepley *dim = 0; 6399de99aefSMatthew G. Knepley if (prob->Nf) { 6409de99aefSMatthew G. Knepley PetscObject obj; 6419de99aefSMatthew G. Knepley PetscClassId id; 6429de99aefSMatthew G. Knepley 6439de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 644665f567fSMatthew G. Knepley if (obj) { 6459de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 6469de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);} 6479de99aefSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);} 6489de99aefSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 6499de99aefSMatthew G. Knepley } 650665f567fSMatthew G. Knepley } 6512764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6522764a2aaSMatthew G. Knepley } 6532764a2aaSMatthew G. Knepley 654bc4ae4beSMatthew G. Knepley /*@ 655a859676bSMatthew G. Knepley PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 656a859676bSMatthew G. Knepley 657a859676bSMatthew G. Knepley Not collective 658a859676bSMatthew G. Knepley 659a859676bSMatthew G. Knepley Input Parameter: 660a859676bSMatthew G. Knepley . prob - The PetscDS object 661a859676bSMatthew G. Knepley 662a859676bSMatthew G. Knepley Output Parameter: 663a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension 664a859676bSMatthew G. Knepley 665a859676bSMatthew G. Knepley Level: beginner 666a859676bSMatthew G. Knepley 667a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 668a859676bSMatthew G. Knepley @*/ 669a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed) 670a859676bSMatthew G. Knepley { 671a859676bSMatthew G. Knepley PetscFunctionBegin; 672a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 673a859676bSMatthew G. Knepley PetscValidPointer(dimEmbed, 2); 674a859676bSMatthew G. Knepley if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS"); 675a859676bSMatthew G. Knepley *dimEmbed = prob->dimEmbed; 676a859676bSMatthew G. Knepley PetscFunctionReturn(0); 677a859676bSMatthew G. Knepley } 678a859676bSMatthew G. Knepley 679a859676bSMatthew G. Knepley /*@ 680a859676bSMatthew G. Knepley PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 681a859676bSMatthew G. Knepley 682d083f849SBarry Smith Logically collective on prob 683a859676bSMatthew G. Knepley 684a859676bSMatthew G. Knepley Input Parameters: 685a859676bSMatthew G. Knepley + prob - The PetscDS object 686a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension 687a859676bSMatthew G. Knepley 688a859676bSMatthew G. Knepley Level: beginner 689a859676bSMatthew G. Knepley 690a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 691a859676bSMatthew G. Knepley @*/ 692a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed) 693a859676bSMatthew G. Knepley { 694a859676bSMatthew G. Knepley PetscFunctionBegin; 695a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 696ebfe4b0dSMatthew G. Knepley if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed); 697a859676bSMatthew G. Knepley prob->dimEmbed = dimEmbed; 698a859676bSMatthew G. Knepley PetscFunctionReturn(0); 699a859676bSMatthew G. Knepley } 700a859676bSMatthew G. Knepley 701a859676bSMatthew G. Knepley /*@ 7028edf6225SMatthew G. Knepley PetscDSGetHybrid - Returns the flag for a hybrid (cohesive) cell 7038edf6225SMatthew G. Knepley 7048edf6225SMatthew G. Knepley Not collective 7058edf6225SMatthew G. Knepley 7068edf6225SMatthew G. Knepley Input Parameter: 7078edf6225SMatthew G. Knepley . prob - The PetscDS object 7088edf6225SMatthew G. Knepley 7098edf6225SMatthew G. Knepley Output Parameter: 7108edf6225SMatthew G. Knepley . isHybrid - The flag 7118edf6225SMatthew G. Knepley 7128edf6225SMatthew G. Knepley Level: developer 7138edf6225SMatthew G. Knepley 7148edf6225SMatthew G. Knepley .seealso: PetscDSSetHybrid(), PetscDSCreate() 7158edf6225SMatthew G. Knepley @*/ 7168edf6225SMatthew G. Knepley PetscErrorCode PetscDSGetHybrid(PetscDS prob, PetscBool *isHybrid) 7178edf6225SMatthew G. Knepley { 7188edf6225SMatthew G. Knepley PetscFunctionBegin; 7198edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7208edf6225SMatthew G. Knepley PetscValidPointer(isHybrid, 2); 7218edf6225SMatthew G. Knepley *isHybrid = prob->isHybrid; 7228edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7238edf6225SMatthew G. Knepley } 7248edf6225SMatthew G. Knepley 7258edf6225SMatthew G. Knepley /*@ 7268edf6225SMatthew G. Knepley PetscDSSetHybrid - Set the flag for a hybrid (cohesive) cell 7278edf6225SMatthew G. Knepley 7288edf6225SMatthew G. Knepley Not collective 7298edf6225SMatthew G. Knepley 7308edf6225SMatthew G. Knepley Input Parameters: 7318edf6225SMatthew G. Knepley + prob - The PetscDS object 7328edf6225SMatthew G. Knepley - isHybrid - The flag 7338edf6225SMatthew G. Knepley 7348edf6225SMatthew G. Knepley Level: developer 7358edf6225SMatthew G. Knepley 7368edf6225SMatthew G. Knepley .seealso: PetscDSGetHybrid(), PetscDSCreate() 7378edf6225SMatthew G. Knepley @*/ 7388edf6225SMatthew G. Knepley PetscErrorCode PetscDSSetHybrid(PetscDS prob, PetscBool isHybrid) 7398edf6225SMatthew G. Knepley { 7408edf6225SMatthew G. Knepley PetscFunctionBegin; 7418edf6225SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7428edf6225SMatthew G. Knepley prob->isHybrid = isHybrid; 7438edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7448edf6225SMatthew G. Knepley } 7458edf6225SMatthew G. Knepley 7468edf6225SMatthew G. Knepley /*@ 747bc4ae4beSMatthew G. Knepley PetscDSGetTotalDimension - Returns the total size of the approximation space for this system 748bc4ae4beSMatthew G. Knepley 749bc4ae4beSMatthew G. Knepley Not collective 750bc4ae4beSMatthew G. Knepley 751bc4ae4beSMatthew G. Knepley Input Parameter: 752bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 753bc4ae4beSMatthew G. Knepley 754bc4ae4beSMatthew G. Knepley Output Parameter: 755bc4ae4beSMatthew G. Knepley . dim - The total problem dimension 756bc4ae4beSMatthew G. Knepley 757bc4ae4beSMatthew G. Knepley Level: beginner 758bc4ae4beSMatthew G. Knepley 759bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 760bc4ae4beSMatthew G. Knepley @*/ 7612764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) 7622764a2aaSMatthew G. Knepley { 7632764a2aaSMatthew G. Knepley PetscErrorCode ierr; 7642764a2aaSMatthew G. Knepley 7652764a2aaSMatthew G. Knepley PetscFunctionBegin; 7662764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7672764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 7682764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 7692764a2aaSMatthew G. Knepley *dim = prob->totDim; 7702764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 7712764a2aaSMatthew G. Knepley } 7722764a2aaSMatthew G. Knepley 773bc4ae4beSMatthew G. Knepley /*@ 774bc4ae4beSMatthew G. Knepley PetscDSGetTotalComponents - Returns the total number of components in this system 775bc4ae4beSMatthew G. Knepley 776bc4ae4beSMatthew G. Knepley Not collective 777bc4ae4beSMatthew G. Knepley 778bc4ae4beSMatthew G. Knepley Input Parameter: 779bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 780bc4ae4beSMatthew G. Knepley 781bc4ae4beSMatthew G. Knepley Output Parameter: 782bc4ae4beSMatthew G. Knepley . dim - The total number of components 783bc4ae4beSMatthew G. Knepley 784bc4ae4beSMatthew G. Knepley Level: beginner 785bc4ae4beSMatthew G. Knepley 786bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 787bc4ae4beSMatthew G. Knepley @*/ 7882764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) 7892764a2aaSMatthew G. Knepley { 7902764a2aaSMatthew G. Knepley PetscErrorCode ierr; 7912764a2aaSMatthew G. Knepley 7922764a2aaSMatthew G. Knepley PetscFunctionBegin; 7932764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 7942764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 7952764a2aaSMatthew G. Knepley PetscValidPointer(Nc, 2); 7962764a2aaSMatthew G. Knepley *Nc = prob->totComp; 7972764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 7982764a2aaSMatthew G. Knepley } 7992764a2aaSMatthew G. Knepley 800bc4ae4beSMatthew G. Knepley /*@ 801bc4ae4beSMatthew G. Knepley PetscDSGetDiscretization - Returns the discretization object for the given field 802bc4ae4beSMatthew G. Knepley 803bc4ae4beSMatthew G. Knepley Not collective 804bc4ae4beSMatthew G. Knepley 805bc4ae4beSMatthew G. Knepley Input Parameters: 806bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 807bc4ae4beSMatthew G. Knepley - f - The field number 808bc4ae4beSMatthew G. Knepley 809bc4ae4beSMatthew G. Knepley Output Parameter: 810bc4ae4beSMatthew G. Knepley . disc - The discretization object 811bc4ae4beSMatthew G. Knepley 812bc4ae4beSMatthew G. Knepley Level: beginner 813bc4ae4beSMatthew G. Knepley 814f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 815bc4ae4beSMatthew G. Knepley @*/ 8162764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 8172764a2aaSMatthew G. Knepley { 8186528b96dSMatthew G. Knepley PetscFunctionBeginHot; 8192764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8202764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 8212764a2aaSMatthew G. Knepley if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf); 8222764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 8232764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8242764a2aaSMatthew G. Knepley } 8252764a2aaSMatthew G. Knepley 826bc4ae4beSMatthew G. Knepley /*@ 827bc4ae4beSMatthew G. Knepley PetscDSSetDiscretization - Sets the discretization object for the given field 828bc4ae4beSMatthew G. Knepley 829bc4ae4beSMatthew G. Knepley Not collective 830bc4ae4beSMatthew G. Knepley 831bc4ae4beSMatthew G. Knepley Input Parameters: 832bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 833bc4ae4beSMatthew G. Knepley . f - The field number 834bc4ae4beSMatthew G. Knepley - disc - The discretization object 835bc4ae4beSMatthew G. Knepley 836bc4ae4beSMatthew G. Knepley Level: beginner 837bc4ae4beSMatthew G. Knepley 838bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 839bc4ae4beSMatthew G. Knepley @*/ 8402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 8412764a2aaSMatthew G. Knepley { 8422764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8432764a2aaSMatthew G. Knepley 8442764a2aaSMatthew G. Knepley PetscFunctionBegin; 8452764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 846665f567fSMatthew G. Knepley if (disc) PetscValidPointer(disc, 3); 8472764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 8482764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 849c10f2116SMatthew G. Knepley ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr); 8502764a2aaSMatthew G. Knepley prob->disc[f] = disc; 8512764a2aaSMatthew G. Knepley ierr = PetscObjectReference(disc);CHKERRQ(ierr); 852665f567fSMatthew G. Knepley if (disc) { 853249df284SMatthew G. Knepley PetscClassId id; 854249df284SMatthew G. Knepley 855249df284SMatthew G. Knepley ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr); 8561cf84007SMatthew G. Knepley if (id == PETSCFE_CLASSID) { 8571cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr); 8581cf84007SMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 8591cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr); 860a6cbbb48SMatthew G. Knepley } 861f9244615SMatthew G. Knepley ierr = PetscDSSetJetDegree(prob, f, 1);CHKERRQ(ierr); 862249df284SMatthew G. Knepley } 8632764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8642764a2aaSMatthew G. Knepley } 8652764a2aaSMatthew G. Knepley 866bc4ae4beSMatthew G. Knepley /*@ 8676528b96dSMatthew G. Knepley PetscDSGetWeakForm - Returns the weak form object 8686528b96dSMatthew G. Knepley 8696528b96dSMatthew G. Knepley Not collective 8706528b96dSMatthew G. Knepley 8716528b96dSMatthew G. Knepley Input Parameter: 8726528b96dSMatthew G. Knepley . ds - The PetscDS object 8736528b96dSMatthew G. Knepley 8746528b96dSMatthew G. Knepley Output Parameter: 8756528b96dSMatthew G. Knepley . wf - The weak form object 8766528b96dSMatthew G. Knepley 8776528b96dSMatthew G. Knepley Level: beginner 8786528b96dSMatthew G. Knepley 8796528b96dSMatthew G. Knepley .seealso: PetscDSSetWeakForm(), PetscDSGetNumFields(), PetscDSCreate() 8806528b96dSMatthew G. Knepley @*/ 8816528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf) 8826528b96dSMatthew G. Knepley { 8836528b96dSMatthew G. Knepley PetscFunctionBegin; 8846528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 8856528b96dSMatthew G. Knepley PetscValidPointer(wf, 2); 8866528b96dSMatthew G. Knepley *wf = ds->wf; 8876528b96dSMatthew G. Knepley PetscFunctionReturn(0); 8886528b96dSMatthew G. Knepley } 8896528b96dSMatthew G. Knepley 8906528b96dSMatthew G. Knepley /*@ 8916528b96dSMatthew G. Knepley PetscDSSetWeakForm - Sets the weak form object 8926528b96dSMatthew G. Knepley 8936528b96dSMatthew G. Knepley Not collective 8946528b96dSMatthew G. Knepley 8956528b96dSMatthew G. Knepley Input Parameters: 8966528b96dSMatthew G. Knepley + ds - The PetscDS object 8976528b96dSMatthew G. Knepley - wf - The weak form object 8986528b96dSMatthew G. Knepley 8996528b96dSMatthew G. Knepley Level: beginner 9006528b96dSMatthew G. Knepley 9016528b96dSMatthew G. Knepley .seealso: PetscDSGetWeakForm(), PetscDSGetNumFields(), PetscDSCreate() 9026528b96dSMatthew G. Knepley @*/ 9036528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf) 9046528b96dSMatthew G. Knepley { 9056528b96dSMatthew G. Knepley PetscErrorCode ierr; 9066528b96dSMatthew G. Knepley 9076528b96dSMatthew G. Knepley PetscFunctionBegin; 9086528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 9096528b96dSMatthew G. Knepley PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2); 9106528b96dSMatthew G. Knepley ierr = PetscObjectDereference((PetscObject) ds->wf);CHKERRQ(ierr); 9116528b96dSMatthew G. Knepley ds->wf = wf; 9126528b96dSMatthew G. Knepley ierr = PetscObjectReference((PetscObject) wf);CHKERRQ(ierr); 9136528b96dSMatthew G. Knepley ierr = PetscWeakFormSetNumFields(wf, ds->Nf);CHKERRQ(ierr); 9146528b96dSMatthew G. Knepley PetscFunctionReturn(0); 9156528b96dSMatthew G. Knepley } 9166528b96dSMatthew G. Knepley 9176528b96dSMatthew G. Knepley /*@ 918bc4ae4beSMatthew G. Knepley PetscDSAddDiscretization - Adds a discretization object 919bc4ae4beSMatthew G. Knepley 920bc4ae4beSMatthew G. Knepley Not collective 921bc4ae4beSMatthew G. Knepley 922bc4ae4beSMatthew G. Knepley Input Parameters: 923bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 924bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object 925bc4ae4beSMatthew G. Knepley 926bc4ae4beSMatthew G. Knepley Level: beginner 927bc4ae4beSMatthew G. Knepley 928bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 929bc4ae4beSMatthew G. Knepley @*/ 9302764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) 9312764a2aaSMatthew G. Knepley { 9322764a2aaSMatthew G. Knepley PetscErrorCode ierr; 9332764a2aaSMatthew G. Knepley 9342764a2aaSMatthew G. Knepley PetscFunctionBegin; 9352764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr); 9362764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9372764a2aaSMatthew G. Knepley } 9382764a2aaSMatthew G. Knepley 939249df284SMatthew G. Knepley /*@ 940083401c6SMatthew G. Knepley PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS 941083401c6SMatthew G. Knepley 942083401c6SMatthew G. Knepley Not collective 943083401c6SMatthew G. Knepley 944083401c6SMatthew G. Knepley Input Parameter: 945083401c6SMatthew G. Knepley . prob - The PetscDS object 946083401c6SMatthew G. Knepley 947083401c6SMatthew G. Knepley Output Parameter: 948083401c6SMatthew G. Knepley . q - The quadrature object 949083401c6SMatthew G. Knepley 950083401c6SMatthew G. Knepley Level: intermediate 951083401c6SMatthew G. Knepley 952083401c6SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 953083401c6SMatthew G. Knepley @*/ 954083401c6SMatthew G. Knepley PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q) 955083401c6SMatthew G. Knepley { 956083401c6SMatthew G. Knepley PetscObject obj; 957083401c6SMatthew G. Knepley PetscClassId id; 958083401c6SMatthew G. Knepley PetscErrorCode ierr; 959083401c6SMatthew G. Knepley 960083401c6SMatthew G. Knepley PetscFunctionBegin; 961083401c6SMatthew G. Knepley *q = NULL; 962083401c6SMatthew G. Knepley if (!prob->Nf) PetscFunctionReturn(0); 963083401c6SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 964083401c6SMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 965083401c6SMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetQuadrature((PetscFE) obj, q);CHKERRQ(ierr);} 966083401c6SMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetQuadrature((PetscFV) obj, q);CHKERRQ(ierr);} 967083401c6SMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 968083401c6SMatthew G. Knepley PetscFunctionReturn(0); 969083401c6SMatthew G. Knepley } 970083401c6SMatthew G. Knepley 971083401c6SMatthew G. Knepley /*@ 972249df284SMatthew G. Knepley PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX 973249df284SMatthew G. Knepley 974249df284SMatthew G. Knepley Not collective 975249df284SMatthew G. Knepley 976249df284SMatthew G. Knepley Input Parameters: 977249df284SMatthew G. Knepley + prob - The PetscDS object 978249df284SMatthew G. Knepley - f - The field number 979249df284SMatthew G. Knepley 980249df284SMatthew G. Knepley Output Parameter: 981249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field 982249df284SMatthew G. Knepley 983249df284SMatthew G. Knepley Level: developer 984249df284SMatthew G. Knepley 985f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 986249df284SMatthew G. Knepley @*/ 987249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit) 988249df284SMatthew G. Knepley { 989249df284SMatthew G. Knepley PetscFunctionBegin; 990249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 991249df284SMatthew G. Knepley PetscValidPointer(implicit, 3); 992249df284SMatthew 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); 993249df284SMatthew G. Knepley *implicit = prob->implicit[f]; 994249df284SMatthew G. Knepley PetscFunctionReturn(0); 995249df284SMatthew G. Knepley } 996249df284SMatthew G. Knepley 997249df284SMatthew G. Knepley /*@ 998249df284SMatthew G. Knepley PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX 999249df284SMatthew G. Knepley 1000249df284SMatthew G. Knepley Not collective 1001249df284SMatthew G. Knepley 1002249df284SMatthew G. Knepley Input Parameters: 1003249df284SMatthew G. Knepley + prob - The PetscDS object 1004249df284SMatthew G. Knepley . f - The field number 1005249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field 1006249df284SMatthew G. Knepley 1007249df284SMatthew G. Knepley Level: developer 1008249df284SMatthew G. Knepley 1009f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 1010249df284SMatthew G. Knepley @*/ 1011249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit) 1012249df284SMatthew G. Knepley { 1013249df284SMatthew G. Knepley PetscFunctionBegin; 1014249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1015249df284SMatthew 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); 1016249df284SMatthew G. Knepley prob->implicit[f] = implicit; 1017249df284SMatthew G. Knepley PetscFunctionReturn(0); 1018249df284SMatthew G. Knepley } 1019249df284SMatthew G. Knepley 1020f9244615SMatthew G. Knepley /*@ 1021f9244615SMatthew G. Knepley PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate. 1022f9244615SMatthew G. Knepley 1023f9244615SMatthew G. Knepley Not collective 1024f9244615SMatthew G. Knepley 1025f9244615SMatthew G. Knepley Input Parameters: 1026f9244615SMatthew G. Knepley + ds - The PetscDS object 1027f9244615SMatthew G. Knepley - f - The field number 1028f9244615SMatthew G. Knepley 1029f9244615SMatthew G. Knepley Output Parameter: 1030f9244615SMatthew G. Knepley . k - The highest derivative we need to tabulate 1031f9244615SMatthew G. Knepley 1032f9244615SMatthew G. Knepley Level: developer 1033f9244615SMatthew G. Knepley 1034f9244615SMatthew G. Knepley .seealso: PetscDSSetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 1035f9244615SMatthew G. Knepley @*/ 1036f9244615SMatthew G. Knepley PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k) 1037f9244615SMatthew G. Knepley { 1038f9244615SMatthew G. Knepley PetscFunctionBegin; 1039f9244615SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1040f9244615SMatthew G. Knepley PetscValidPointer(k, 3); 1041f9244615SMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 1042f9244615SMatthew G. Knepley *k = ds->jetDegree[f]; 1043f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1044f9244615SMatthew G. Knepley } 1045f9244615SMatthew G. Knepley 1046f9244615SMatthew G. Knepley /*@ 1047f9244615SMatthew G. Knepley PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate. 1048f9244615SMatthew G. Knepley 1049f9244615SMatthew G. Knepley Not collective 1050f9244615SMatthew G. Knepley 1051f9244615SMatthew G. Knepley Input Parameters: 1052f9244615SMatthew G. Knepley + ds - The PetscDS object 1053f9244615SMatthew G. Knepley . f - The field number 1054f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate 1055f9244615SMatthew G. Knepley 1056f9244615SMatthew G. Knepley Level: developer 1057f9244615SMatthew G. Knepley 1058f9244615SMatthew G. Knepley .seealso: PetscDSGetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 1059f9244615SMatthew G. Knepley @*/ 1060f9244615SMatthew G. Knepley PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k) 1061f9244615SMatthew G. Knepley { 1062f9244615SMatthew G. Knepley PetscFunctionBegin; 1063f9244615SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1064f9244615SMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 1065f9244615SMatthew G. Knepley ds->jetDegree[f] = k; 1066f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1067f9244615SMatthew G. Knepley } 1068f9244615SMatthew G. Knepley 10696528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS ds, PetscInt f, 107030b9ff8bSMatthew G. Knepley void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1071194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1072194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 107397b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 10742764a2aaSMatthew G. Knepley { 10756528b96dSMatthew G. Knepley PetscPointFunc *tmp; 10766528b96dSMatthew G. Knepley PetscInt n; 10776528b96dSMatthew G. Knepley PetscErrorCode ierr; 10786528b96dSMatthew G. Knepley 10792764a2aaSMatthew G. Knepley PetscFunctionBegin; 10806528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 10816528b96dSMatthew G. Knepley PetscValidPointer(obj, 3); 10826528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 10836528b96dSMatthew G. Knepley ierr = PetscWeakFormGetObjective(ds->wf, NULL, 0, f, &n, &tmp);CHKERRQ(ierr); 10846528b96dSMatthew G. Knepley *obj = tmp ? tmp[0] : NULL; 10852764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10862764a2aaSMatthew G. Knepley } 10872764a2aaSMatthew G. Knepley 10886528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS ds, PetscInt f, 108930b9ff8bSMatthew G. Knepley void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1090194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1091194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 109297b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 10932764a2aaSMatthew G. Knepley { 10942764a2aaSMatthew G. Knepley PetscErrorCode ierr; 10952764a2aaSMatthew G. Knepley 10962764a2aaSMatthew G. Knepley PetscFunctionBegin; 10976528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 10986528b96dSMatthew G. Knepley if (obj) PetscValidFunction(obj, 3); 10992764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 11006528b96dSMatthew G. Knepley ierr = PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, obj);CHKERRQ(ierr); 11012764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11022764a2aaSMatthew G. Knepley } 11032764a2aaSMatthew G. Knepley 1104194d53e6SMatthew G. Knepley /*@C 1105194d53e6SMatthew G. Knepley PetscDSGetResidual - Get the pointwise residual function for a given test field 1106194d53e6SMatthew G. Knepley 1107194d53e6SMatthew G. Knepley Not collective 1108194d53e6SMatthew G. Knepley 1109194d53e6SMatthew G. Knepley Input Parameters: 11106528b96dSMatthew G. Knepley + ds - The PetscDS 1111194d53e6SMatthew G. Knepley - f - The test field number 1112194d53e6SMatthew G. Knepley 1113194d53e6SMatthew G. Knepley Output Parameters: 1114194d53e6SMatthew G. Knepley + f0 - integrand for the test function term 1115194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1116194d53e6SMatthew G. Knepley 1117194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1118194d53e6SMatthew G. Knepley 1119194d53e6SMatthew 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) 1120194d53e6SMatthew G. Knepley 1121194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1122194d53e6SMatthew G. Knepley 112330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1124194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1125194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 112630b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1127194d53e6SMatthew G. Knepley 1128194d53e6SMatthew G. Knepley + dim - the spatial dimension 1129194d53e6SMatthew G. Knepley . Nf - the number of fields 1130194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1131194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1132194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1133194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1134194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1135194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1136194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1137194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1138194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1139194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1140194d53e6SMatthew G. Knepley . t - current time 1141194d53e6SMatthew G. Knepley . x - coordinates of the current point 114297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 114397b6e6e8SMatthew G. Knepley . constants - constant parameters 1144194d53e6SMatthew G. Knepley - f0 - output values at the current point 1145194d53e6SMatthew G. Knepley 1146194d53e6SMatthew G. Knepley Level: intermediate 1147194d53e6SMatthew G. Knepley 1148194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual() 1149194d53e6SMatthew G. Knepley @*/ 11506528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS ds, PetscInt f, 115130b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1152194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1153194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 115497b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 115530b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1156194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1157194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 115897b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 11592764a2aaSMatthew G. Knepley { 11606528b96dSMatthew G. Knepley PetscPointFunc *tmp0, *tmp1; 11616528b96dSMatthew G. Knepley PetscInt n0, n1; 11626528b96dSMatthew G. Knepley PetscErrorCode ierr; 11636528b96dSMatthew G. Knepley 11642764a2aaSMatthew G. Knepley PetscFunctionBegin; 11656528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 11666528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 11676528b96dSMatthew G. Knepley ierr = PetscWeakFormGetResidual(ds->wf, NULL, 0, f, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr); 11686528b96dSMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 11696528b96dSMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 11702764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11712764a2aaSMatthew G. Knepley } 11722764a2aaSMatthew G. Knepley 1173194d53e6SMatthew G. Knepley /*@C 1174194d53e6SMatthew G. Knepley PetscDSSetResidual - Set the pointwise residual function for a given test field 1175194d53e6SMatthew G. Knepley 1176194d53e6SMatthew G. Knepley Not collective 1177194d53e6SMatthew G. Knepley 1178194d53e6SMatthew G. Knepley Input Parameters: 11796528b96dSMatthew G. Knepley + ds - The PetscDS 1180194d53e6SMatthew G. Knepley . f - The test field number 1181194d53e6SMatthew G. Knepley . f0 - integrand for the test function term 1182194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1183194d53e6SMatthew G. Knepley 1184194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1185194d53e6SMatthew G. Knepley 1186194d53e6SMatthew 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) 1187194d53e6SMatthew G. Knepley 1188194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1189194d53e6SMatthew G. Knepley 119030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1191194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1192194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 119330b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1194194d53e6SMatthew G. Knepley 1195194d53e6SMatthew G. Knepley + dim - the spatial dimension 1196194d53e6SMatthew G. Knepley . Nf - the number of fields 1197194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1198194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1199194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1200194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1201194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1202194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1203194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1204194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1205194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1206194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1207194d53e6SMatthew G. Knepley . t - current time 1208194d53e6SMatthew G. Knepley . x - coordinates of the current point 120997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 121097b6e6e8SMatthew G. Knepley . constants - constant parameters 1211194d53e6SMatthew G. Knepley - f0 - output values at the current point 1212194d53e6SMatthew G. Knepley 1213194d53e6SMatthew G. Knepley Level: intermediate 1214194d53e6SMatthew G. Knepley 1215194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual() 1216194d53e6SMatthew G. Knepley @*/ 12176528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS ds, PetscInt f, 121830b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1219194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1220194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 122197b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 122230b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1223194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1224194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 122597b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 12262764a2aaSMatthew G. Knepley { 12272764a2aaSMatthew G. Knepley PetscErrorCode ierr; 12282764a2aaSMatthew G. Knepley 12292764a2aaSMatthew G. Knepley PetscFunctionBegin; 12306528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1231f866a1d0SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1232f866a1d0SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 12332764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 12346528b96dSMatthew G. Knepley ierr = PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, f0, 0, f1);CHKERRQ(ierr); 12352764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 12362764a2aaSMatthew G. Knepley } 12372764a2aaSMatthew G. Knepley 12383e75805dSMatthew G. Knepley /*@C 12393e75805dSMatthew G. Knepley PetscDSHasJacobian - Signals that Jacobian functions have been set 12403e75805dSMatthew G. Knepley 12413e75805dSMatthew G. Knepley Not collective 12423e75805dSMatthew G. Knepley 12433e75805dSMatthew G. Knepley Input Parameter: 12443e75805dSMatthew G. Knepley . prob - The PetscDS 12453e75805dSMatthew G. Knepley 12463e75805dSMatthew G. Knepley Output Parameter: 12473e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set 12483e75805dSMatthew G. Knepley 12493e75805dSMatthew G. Knepley Level: intermediate 12503e75805dSMatthew G. Knepley 12513e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 12523e75805dSMatthew G. Knepley @*/ 12536528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac) 12543e75805dSMatthew G. Knepley { 12556528b96dSMatthew G. Knepley PetscErrorCode ierr; 12563e75805dSMatthew G. Knepley 12573e75805dSMatthew G. Knepley PetscFunctionBegin; 12586528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 12596528b96dSMatthew G. Knepley ierr = PetscWeakFormHasJacobian(ds->wf, hasJac);CHKERRQ(ierr); 12603e75805dSMatthew G. Knepley PetscFunctionReturn(0); 12613e75805dSMatthew G. Knepley } 12623e75805dSMatthew G. Knepley 1263194d53e6SMatthew G. Knepley /*@C 1264194d53e6SMatthew G. Knepley PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field 1265194d53e6SMatthew G. Knepley 1266194d53e6SMatthew G. Knepley Not collective 1267194d53e6SMatthew G. Knepley 1268194d53e6SMatthew G. Knepley Input Parameters: 12696528b96dSMatthew G. Knepley + ds - The PetscDS 1270194d53e6SMatthew G. Knepley . f - The test field number 1271194d53e6SMatthew G. Knepley - g - The field number 1272194d53e6SMatthew G. Knepley 1273194d53e6SMatthew G. Knepley Output Parameters: 1274194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1275194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1276194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1277194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1278194d53e6SMatthew G. Knepley 1279194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1280194d53e6SMatthew G. Knepley 1281194d53e6SMatthew 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 1282194d53e6SMatthew G. Knepley 1283194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1284194d53e6SMatthew G. Knepley 128530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1286194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1287194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 128830b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1289194d53e6SMatthew G. Knepley 1290194d53e6SMatthew G. Knepley + dim - the spatial dimension 1291194d53e6SMatthew G. Knepley . Nf - the number of fields 1292194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1293194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1294194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1295194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1296194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1297194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1298194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1299194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1300194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1301194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1302194d53e6SMatthew G. Knepley . t - current time 13032aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1304194d53e6SMatthew G. Knepley . x - coordinates of the current point 130597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 130697b6e6e8SMatthew G. Knepley . constants - constant parameters 1307194d53e6SMatthew G. Knepley - g0 - output values at the current point 1308194d53e6SMatthew G. Knepley 1309194d53e6SMatthew G. Knepley Level: intermediate 1310194d53e6SMatthew G. Knepley 1311194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1312194d53e6SMatthew G. Knepley @*/ 13136528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS ds, PetscInt f, PetscInt g, 131430b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1315194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1316194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 131797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 131830b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1319194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1320194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 132197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 132230b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1323194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1324194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 132597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 132630b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1327194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1328194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 132997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 13302764a2aaSMatthew G. Knepley { 13316528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 13326528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 13336528b96dSMatthew G. Knepley PetscErrorCode ierr; 13346528b96dSMatthew G. Knepley 13352764a2aaSMatthew G. Knepley PetscFunctionBegin; 13366528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 13376528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 13386528b96dSMatthew G. Knepley if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf); 13396528b96dSMatthew G. Knepley ierr = PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 13406528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 13416528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 13426528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 13436528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 13442764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 13452764a2aaSMatthew G. Knepley } 13462764a2aaSMatthew G. Knepley 1347194d53e6SMatthew G. Knepley /*@C 1348194d53e6SMatthew G. Knepley PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields 1349194d53e6SMatthew G. Knepley 1350194d53e6SMatthew G. Knepley Not collective 1351194d53e6SMatthew G. Knepley 1352194d53e6SMatthew G. Knepley Input Parameters: 13536528b96dSMatthew G. Knepley + ds - The PetscDS 1354194d53e6SMatthew G. Knepley . f - The test field number 1355194d53e6SMatthew G. Knepley . g - The field number 1356194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1357194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1358194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1359194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1360194d53e6SMatthew G. Knepley 1361194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1362194d53e6SMatthew G. Knepley 1363194d53e6SMatthew 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 1364194d53e6SMatthew G. Knepley 1365194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1366194d53e6SMatthew G. Knepley 136730b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1368194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1369194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 137030b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1371194d53e6SMatthew G. Knepley 1372194d53e6SMatthew G. Knepley + dim - the spatial dimension 1373194d53e6SMatthew G. Knepley . Nf - the number of fields 1374194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1375194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1376194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1377194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1378194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1379194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1380194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1381194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1382194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1383194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1384194d53e6SMatthew G. Knepley . t - current time 13852aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1386194d53e6SMatthew G. Knepley . x - coordinates of the current point 138797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 138897b6e6e8SMatthew G. Knepley . constants - constant parameters 1389194d53e6SMatthew G. Knepley - g0 - output values at the current point 1390194d53e6SMatthew G. Knepley 1391194d53e6SMatthew G. Knepley Level: intermediate 1392194d53e6SMatthew G. Knepley 1393194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1394194d53e6SMatthew G. Knepley @*/ 13956528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS ds, PetscInt f, PetscInt g, 139630b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1397194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1398194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 139997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 140030b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1401194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1402194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 140397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 140430b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1405194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1406194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 140797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 140830b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1409194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1410194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 141197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 14122764a2aaSMatthew G. Knepley { 14132764a2aaSMatthew G. Knepley PetscErrorCode ierr; 14142764a2aaSMatthew G. Knepley 14152764a2aaSMatthew G. Knepley PetscFunctionBegin; 14166528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14172764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 14182764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 14192764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 14202764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 14212764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 14222764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 14236528b96dSMatthew G. Knepley ierr = PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 14242764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 14252764a2aaSMatthew G. Knepley } 14262764a2aaSMatthew G. Knepley 1427475e0ac9SMatthew G. Knepley /*@C 142855c1f793SMatthew G. Knepley PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner 142955c1f793SMatthew G. Knepley 143055c1f793SMatthew G. Knepley Not collective 143155c1f793SMatthew G. Knepley 143255c1f793SMatthew G. Knepley Input Parameters: 143355c1f793SMatthew G. Knepley + prob - The PetscDS 143455c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner 143555c1f793SMatthew G. Knepley 143655c1f793SMatthew G. Knepley Level: intermediate 143755c1f793SMatthew G. Knepley 143855c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 143955c1f793SMatthew G. Knepley @*/ 144055c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre) 144155c1f793SMatthew G. Knepley { 144255c1f793SMatthew G. Knepley PetscFunctionBegin; 144355c1f793SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 144455c1f793SMatthew G. Knepley prob->useJacPre = useJacPre; 144555c1f793SMatthew G. Knepley PetscFunctionReturn(0); 144655c1f793SMatthew G. Knepley } 144755c1f793SMatthew G. Knepley 144855c1f793SMatthew G. Knepley /*@C 1449475e0ac9SMatthew G. Knepley PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set 1450475e0ac9SMatthew G. Knepley 1451475e0ac9SMatthew G. Knepley Not collective 1452475e0ac9SMatthew G. Knepley 1453475e0ac9SMatthew G. Knepley Input Parameter: 1454475e0ac9SMatthew G. Knepley . prob - The PetscDS 1455475e0ac9SMatthew G. Knepley 1456475e0ac9SMatthew G. Knepley Output Parameter: 1457475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set 1458475e0ac9SMatthew G. Knepley 1459475e0ac9SMatthew G. Knepley Level: intermediate 1460475e0ac9SMatthew G. Knepley 1461475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1462475e0ac9SMatthew G. Knepley @*/ 14636528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre) 1464475e0ac9SMatthew G. Knepley { 14656528b96dSMatthew G. Knepley PetscErrorCode ierr; 1466475e0ac9SMatthew G. Knepley 1467475e0ac9SMatthew G. Knepley PetscFunctionBegin; 14686528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1469475e0ac9SMatthew G. Knepley *hasJacPre = PETSC_FALSE; 14706528b96dSMatthew G. Knepley if (!ds->useJacPre) PetscFunctionReturn(0); 14716528b96dSMatthew G. Knepley ierr = PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre);CHKERRQ(ierr); 1472475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1473475e0ac9SMatthew G. Knepley } 1474475e0ac9SMatthew G. Knepley 1475475e0ac9SMatthew G. Knepley /*@C 1476475e0ac9SMatthew 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. 1477475e0ac9SMatthew G. Knepley 1478475e0ac9SMatthew G. Knepley Not collective 1479475e0ac9SMatthew G. Knepley 1480475e0ac9SMatthew G. Knepley Input Parameters: 14816528b96dSMatthew G. Knepley + ds - The PetscDS 1482475e0ac9SMatthew G. Knepley . f - The test field number 1483475e0ac9SMatthew G. Knepley - g - The field number 1484475e0ac9SMatthew G. Knepley 1485475e0ac9SMatthew G. Knepley Output Parameters: 1486475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term 1487475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1488475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1489475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1490475e0ac9SMatthew G. Knepley 1491475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1492475e0ac9SMatthew G. Knepley 1493475e0ac9SMatthew 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 1494475e0ac9SMatthew G. Knepley 1495475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1496475e0ac9SMatthew G. Knepley 1497475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1498475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1499475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1500475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1501475e0ac9SMatthew G. Knepley 1502475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1503475e0ac9SMatthew G. Knepley . Nf - the number of fields 1504475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1505475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1506475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1507475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1508475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1509475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1510475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1511475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1512475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1513475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1514475e0ac9SMatthew G. Knepley . t - current time 1515475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1516475e0ac9SMatthew G. Knepley . x - coordinates of the current point 151797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 151897b6e6e8SMatthew G. Knepley . constants - constant parameters 1519475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1520475e0ac9SMatthew G. Knepley 1521475e0ac9SMatthew G. Knepley Level: intermediate 1522475e0ac9SMatthew G. Knepley 1523475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1524475e0ac9SMatthew G. Knepley @*/ 15256528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, 1526475e0ac9SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1527475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1528475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 152997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1530475e0ac9SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1531475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1532475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 153397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1534475e0ac9SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1535475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1536475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 153797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1538475e0ac9SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1539475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1540475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 154197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1542475e0ac9SMatthew G. Knepley { 15436528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 15446528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 15456528b96dSMatthew G. Knepley PetscErrorCode ierr; 15466528b96dSMatthew G. Knepley 1547475e0ac9SMatthew G. Knepley PetscFunctionBegin; 15486528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 15496528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 15506528b96dSMatthew G. Knepley if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf); 15516528b96dSMatthew G. Knepley ierr = PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 15526528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 15536528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 15546528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 15556528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 1556475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1557475e0ac9SMatthew G. Knepley } 1558475e0ac9SMatthew G. Knepley 1559475e0ac9SMatthew G. Knepley /*@C 1560475e0ac9SMatthew 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. 1561475e0ac9SMatthew G. Knepley 1562475e0ac9SMatthew G. Knepley Not collective 1563475e0ac9SMatthew G. Knepley 1564475e0ac9SMatthew G. Knepley Input Parameters: 15656528b96dSMatthew G. Knepley + ds - The PetscDS 1566475e0ac9SMatthew G. Knepley . f - The test field number 1567475e0ac9SMatthew G. Knepley . g - The field number 1568475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term 1569475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1570475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1571475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1572475e0ac9SMatthew G. Knepley 1573475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1574475e0ac9SMatthew G. Knepley 1575475e0ac9SMatthew 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 1576475e0ac9SMatthew G. Knepley 1577475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1578475e0ac9SMatthew G. Knepley 1579475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1580475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1581475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1582475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1583475e0ac9SMatthew G. Knepley 1584475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1585475e0ac9SMatthew G. Knepley . Nf - the number of fields 1586475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1587475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1588475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1589475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1590475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1591475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1592475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1593475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1594475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1595475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1596475e0ac9SMatthew G. Knepley . t - current time 1597475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1598475e0ac9SMatthew G. Knepley . x - coordinates of the current point 159997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 160097b6e6e8SMatthew G. Knepley . constants - constant parameters 1601475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1602475e0ac9SMatthew G. Knepley 1603475e0ac9SMatthew G. Knepley Level: intermediate 1604475e0ac9SMatthew G. Knepley 1605475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian() 1606475e0ac9SMatthew G. Knepley @*/ 16076528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, 1608475e0ac9SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1609475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1610475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 161197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1612475e0ac9SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1613475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1614475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 161597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1616475e0ac9SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1617475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1618475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 161997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1620475e0ac9SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1621475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1622475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 162397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1624475e0ac9SMatthew G. Knepley { 1625475e0ac9SMatthew G. Knepley PetscErrorCode ierr; 1626475e0ac9SMatthew G. Knepley 1627475e0ac9SMatthew G. Knepley PetscFunctionBegin; 16286528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1629475e0ac9SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1630475e0ac9SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1631475e0ac9SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1632475e0ac9SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1633475e0ac9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1634475e0ac9SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 16356528b96dSMatthew G. Knepley ierr = PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 1636475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1637475e0ac9SMatthew G. Knepley } 1638475e0ac9SMatthew G. Knepley 1639b7e05686SMatthew G. Knepley /*@C 1640b7e05686SMatthew G. Knepley PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set 1641b7e05686SMatthew G. Knepley 1642b7e05686SMatthew G. Knepley Not collective 1643b7e05686SMatthew G. Knepley 1644b7e05686SMatthew G. Knepley Input Parameter: 16456528b96dSMatthew G. Knepley . ds - The PetscDS 1646b7e05686SMatthew G. Knepley 1647b7e05686SMatthew G. Knepley Output Parameter: 1648b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set 1649b7e05686SMatthew G. Knepley 1650b7e05686SMatthew G. Knepley Level: intermediate 1651b7e05686SMatthew G. Knepley 1652b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian() 1653b7e05686SMatthew G. Knepley @*/ 16546528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac) 1655b7e05686SMatthew G. Knepley { 16566528b96dSMatthew G. Knepley PetscErrorCode ierr; 1657b7e05686SMatthew G. Knepley 1658b7e05686SMatthew G. Knepley PetscFunctionBegin; 16596528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 16606528b96dSMatthew G. Knepley ierr = PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac);CHKERRQ(ierr); 1661b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1662b7e05686SMatthew G. Knepley } 1663b7e05686SMatthew G. Knepley 1664b7e05686SMatthew G. Knepley /*@C 1665b7e05686SMatthew G. Knepley PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field 1666b7e05686SMatthew G. Knepley 1667b7e05686SMatthew G. Knepley Not collective 1668b7e05686SMatthew G. Knepley 1669b7e05686SMatthew G. Knepley Input Parameters: 16706528b96dSMatthew G. Knepley + ds - The PetscDS 1671b7e05686SMatthew G. Knepley . f - The test field number 1672b7e05686SMatthew G. Knepley - g - The field number 1673b7e05686SMatthew G. Knepley 1674b7e05686SMatthew G. Knepley Output Parameters: 1675b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term 1676b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1677b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1678b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1679b7e05686SMatthew G. Knepley 1680b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1681b7e05686SMatthew G. Knepley 1682b7e05686SMatthew 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 1683b7e05686SMatthew G. Knepley 1684b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1685b7e05686SMatthew G. Knepley 1686b7e05686SMatthew G. Knepley $ 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[], 1689b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1690b7e05686SMatthew G. Knepley 1691b7e05686SMatthew G. Knepley + dim - the spatial dimension 1692b7e05686SMatthew G. Knepley . Nf - the number of fields 1693b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1694b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1695b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1696b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1697b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1698b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1699b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1700b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1701b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1702b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1703b7e05686SMatthew G. Knepley . t - current time 1704b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1705b7e05686SMatthew G. Knepley . x - coordinates of the current point 170697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 170797b6e6e8SMatthew G. Knepley . constants - constant parameters 1708b7e05686SMatthew G. Knepley - g0 - output values at the current point 1709b7e05686SMatthew G. Knepley 1710b7e05686SMatthew G. Knepley Level: intermediate 1711b7e05686SMatthew G. Knepley 1712b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1713b7e05686SMatthew G. Knepley @*/ 17146528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g, 1715b7e05686SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1716b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1717b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 171897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1719b7e05686SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1720b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1721b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 172297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1723b7e05686SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1724b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1725b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 172697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1727b7e05686SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1728b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1729b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 173097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1731b7e05686SMatthew G. Knepley { 17326528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 17336528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 17346528b96dSMatthew G. Knepley PetscErrorCode ierr; 17356528b96dSMatthew G. Knepley 1736b7e05686SMatthew G. Knepley PetscFunctionBegin; 17376528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 17386528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 17396528b96dSMatthew G. Knepley if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf); 17406528b96dSMatthew G. Knepley ierr = PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 17416528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 17426528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 17436528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 17446528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 1745b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1746b7e05686SMatthew G. Knepley } 1747b7e05686SMatthew G. Knepley 1748b7e05686SMatthew G. Knepley /*@C 1749b7e05686SMatthew G. Knepley PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields 1750b7e05686SMatthew G. Knepley 1751b7e05686SMatthew G. Knepley Not collective 1752b7e05686SMatthew G. Knepley 1753b7e05686SMatthew G. Knepley Input Parameters: 17546528b96dSMatthew G. Knepley + ds - The PetscDS 1755b7e05686SMatthew G. Knepley . f - The test field number 1756b7e05686SMatthew G. Knepley . g - The field number 1757b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term 1758b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1759b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1760b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1761b7e05686SMatthew G. Knepley 1762b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1763b7e05686SMatthew G. Knepley 1764b7e05686SMatthew 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 1765b7e05686SMatthew G. Knepley 1766b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1767b7e05686SMatthew G. Knepley 1768b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1769b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1770b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1771b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1772b7e05686SMatthew G. Knepley 1773b7e05686SMatthew G. Knepley + dim - the spatial dimension 1774b7e05686SMatthew G. Knepley . Nf - the number of fields 1775b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1776b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1777b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1778b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1779b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1780b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1781b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1782b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1783b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1784b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1785b7e05686SMatthew G. Knepley . t - current time 1786b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1787b7e05686SMatthew G. Knepley . x - coordinates of the current point 178897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 178997b6e6e8SMatthew G. Knepley . constants - constant parameters 1790b7e05686SMatthew G. Knepley - g0 - output values at the current point 1791b7e05686SMatthew G. Knepley 1792b7e05686SMatthew G. Knepley Level: intermediate 1793b7e05686SMatthew G. Knepley 1794b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1795b7e05686SMatthew G. Knepley @*/ 17966528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g, 1797b7e05686SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1798b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1799b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 180097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1801b7e05686SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1802b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1803b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 180497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1805b7e05686SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1806b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1807b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 180897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1809b7e05686SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1810b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1811b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 181297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1813b7e05686SMatthew G. Knepley { 1814b7e05686SMatthew G. Knepley PetscErrorCode ierr; 1815b7e05686SMatthew G. Knepley 1816b7e05686SMatthew G. Knepley PetscFunctionBegin; 18176528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1818b7e05686SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1819b7e05686SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1820b7e05686SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1821b7e05686SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1822b7e05686SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1823b7e05686SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 18246528b96dSMatthew G. Knepley ierr = PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 1825b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1826b7e05686SMatthew G. Knepley } 1827b7e05686SMatthew G. Knepley 18280c2f2876SMatthew G. Knepley /*@C 18290c2f2876SMatthew G. Knepley PetscDSGetRiemannSolver - Returns the Riemann solver for the given field 18300c2f2876SMatthew G. Knepley 18310c2f2876SMatthew G. Knepley Not collective 18320c2f2876SMatthew G. Knepley 18330c2f2876SMatthew G. Knepley Input Arguments: 18346528b96dSMatthew G. Knepley + ds - The PetscDS object 18350c2f2876SMatthew G. Knepley - f - The field number 18360c2f2876SMatthew G. Knepley 18370c2f2876SMatthew G. Knepley Output Argument: 18380c2f2876SMatthew G. Knepley . r - Riemann solver 18390c2f2876SMatthew G. Knepley 18400c2f2876SMatthew G. Knepley Calling sequence for r: 18410c2f2876SMatthew G. Knepley 18425db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 18430c2f2876SMatthew G. Knepley 18445db36cf9SMatthew G. Knepley + dim - The spatial dimension 18455db36cf9SMatthew G. Knepley . Nf - The number of fields 18465db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 18470c2f2876SMatthew G. Knepley . n - The normal vector to the interface 18480c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 18490c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 18500c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 185197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 185297b6e6e8SMatthew G. Knepley . constants - constant parameters 18530c2f2876SMatthew G. Knepley - ctx - optional user context 18540c2f2876SMatthew G. Knepley 18550c2f2876SMatthew G. Knepley Level: intermediate 18560c2f2876SMatthew G. Knepley 18570c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver() 18580c2f2876SMatthew G. Knepley @*/ 18596528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS ds, PetscInt f, 186097b6e6e8SMatthew 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)) 18610c2f2876SMatthew G. Knepley { 18626528b96dSMatthew G. Knepley PetscRiemannFunc *tmp; 18636528b96dSMatthew G. Knepley PetscInt n; 18646528b96dSMatthew G. Knepley PetscErrorCode ierr; 18656528b96dSMatthew G. Knepley 18660c2f2876SMatthew G. Knepley PetscFunctionBegin; 18676528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 18680c2f2876SMatthew G. Knepley PetscValidPointer(r, 3); 18696528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 18706528b96dSMatthew G. Knepley ierr = PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, &n, &tmp);CHKERRQ(ierr); 18716528b96dSMatthew G. Knepley *r = tmp ? tmp[0] : NULL; 18720c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 18730c2f2876SMatthew G. Knepley } 18740c2f2876SMatthew G. Knepley 18750c2f2876SMatthew G. Knepley /*@C 18760c2f2876SMatthew G. Knepley PetscDSSetRiemannSolver - Sets the Riemann solver for the given field 18770c2f2876SMatthew G. Knepley 18780c2f2876SMatthew G. Knepley Not collective 18790c2f2876SMatthew G. Knepley 18800c2f2876SMatthew G. Knepley Input Arguments: 18816528b96dSMatthew G. Knepley + ds - The PetscDS object 18820c2f2876SMatthew G. Knepley . f - The field number 18830c2f2876SMatthew G. Knepley - r - Riemann solver 18840c2f2876SMatthew G. Knepley 18850c2f2876SMatthew G. Knepley Calling sequence for r: 18860c2f2876SMatthew G. Knepley 18875db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 18880c2f2876SMatthew G. Knepley 18895db36cf9SMatthew G. Knepley + dim - The spatial dimension 18905db36cf9SMatthew G. Knepley . Nf - The number of fields 18915db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 18920c2f2876SMatthew G. Knepley . n - The normal vector to the interface 18930c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 18940c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 18950c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 189697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 189797b6e6e8SMatthew G. Knepley . constants - constant parameters 18980c2f2876SMatthew G. Knepley - ctx - optional user context 18990c2f2876SMatthew G. Knepley 19000c2f2876SMatthew G. Knepley Level: intermediate 19010c2f2876SMatthew G. Knepley 19020c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver() 19030c2f2876SMatthew G. Knepley @*/ 19046528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS ds, PetscInt f, 190597b6e6e8SMatthew 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)) 19060c2f2876SMatthew G. Knepley { 19070c2f2876SMatthew G. Knepley PetscErrorCode ierr; 19080c2f2876SMatthew G. Knepley 19090c2f2876SMatthew G. Knepley PetscFunctionBegin; 19106528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1911de716cbcSToby Isaac if (r) PetscValidFunction(r, 3); 19120c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 19136528b96dSMatthew G. Knepley ierr = PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, r);CHKERRQ(ierr); 19140c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19150c2f2876SMatthew G. Knepley } 19160c2f2876SMatthew G. Knepley 191732d2bbc9SMatthew G. Knepley /*@C 191832d2bbc9SMatthew G. Knepley PetscDSGetUpdate - Get the pointwise update function for a given field 191932d2bbc9SMatthew G. Knepley 192032d2bbc9SMatthew G. Knepley Not collective 192132d2bbc9SMatthew G. Knepley 192232d2bbc9SMatthew G. Knepley Input Parameters: 19236528b96dSMatthew G. Knepley + ds - The PetscDS 192432d2bbc9SMatthew G. Knepley - f - The field number 192532d2bbc9SMatthew G. Knepley 192632d2bbc9SMatthew G. Knepley Output Parameters: 1927a2b725a8SWilliam Gropp . update - update function 192832d2bbc9SMatthew G. Knepley 192932d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 193032d2bbc9SMatthew G. Knepley 193132d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 193232d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 193332d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 193432d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 193532d2bbc9SMatthew G. Knepley 193632d2bbc9SMatthew G. Knepley + dim - the spatial dimension 193732d2bbc9SMatthew G. Knepley . Nf - the number of fields 193832d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 193932d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 194032d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 194132d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 194232d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 194332d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 194432d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 194532d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 194632d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 194732d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 194832d2bbc9SMatthew G. Knepley . t - current time 194932d2bbc9SMatthew G. Knepley . x - coordinates of the current point 195032d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point 195132d2bbc9SMatthew G. Knepley 195232d2bbc9SMatthew G. Knepley Level: intermediate 195332d2bbc9SMatthew G. Knepley 195432d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual() 195532d2bbc9SMatthew G. Knepley @*/ 19566528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS ds, PetscInt f, 195732d2bbc9SMatthew G. Knepley void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 195832d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 195932d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 19603fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 196132d2bbc9SMatthew G. Knepley { 196232d2bbc9SMatthew G. Knepley PetscFunctionBegin; 19636528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 19646528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 19656528b96dSMatthew G. Knepley if (update) {PetscValidPointer(update, 3); *update = ds->update[f];} 196632d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 196732d2bbc9SMatthew G. Knepley } 196832d2bbc9SMatthew G. Knepley 196932d2bbc9SMatthew G. Knepley /*@C 19703fa77dffSMatthew G. Knepley PetscDSSetUpdate - Set the pointwise update function for a given field 197132d2bbc9SMatthew G. Knepley 197232d2bbc9SMatthew G. Knepley Not collective 197332d2bbc9SMatthew G. Knepley 197432d2bbc9SMatthew G. Knepley Input Parameters: 19756528b96dSMatthew G. Knepley + ds - The PetscDS 197632d2bbc9SMatthew G. Knepley . f - The field number 197732d2bbc9SMatthew G. Knepley - update - update function 197832d2bbc9SMatthew G. Knepley 197932d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 198032d2bbc9SMatthew G. Knepley 198132d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 198232d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 198332d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 198432d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 198532d2bbc9SMatthew G. Knepley 198632d2bbc9SMatthew G. Knepley + dim - the spatial dimension 198732d2bbc9SMatthew G. Knepley . Nf - the number of fields 198832d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 198932d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 199032d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 199132d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 199232d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 199332d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 199432d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 199532d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 199632d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 199732d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 199832d2bbc9SMatthew G. Knepley . t - current time 199932d2bbc9SMatthew G. Knepley . x - coordinates of the current point 200032d2bbc9SMatthew G. Knepley - uNew - new field values at the current point 200132d2bbc9SMatthew G. Knepley 200232d2bbc9SMatthew G. Knepley Level: intermediate 200332d2bbc9SMatthew G. Knepley 200432d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual() 200532d2bbc9SMatthew G. Knepley @*/ 20066528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS ds, PetscInt f, 200732d2bbc9SMatthew G. Knepley void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 200832d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 200932d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 20103fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 201132d2bbc9SMatthew G. Knepley { 201232d2bbc9SMatthew G. Knepley PetscErrorCode ierr; 201332d2bbc9SMatthew G. Knepley 201432d2bbc9SMatthew G. Knepley PetscFunctionBegin; 20156528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 201632d2bbc9SMatthew G. Knepley if (update) PetscValidFunction(update, 3); 201732d2bbc9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 20186528b96dSMatthew G. Knepley ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr); 20196528b96dSMatthew G. Knepley ds->update[f] = update; 202032d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 202132d2bbc9SMatthew G. Knepley } 202232d2bbc9SMatthew G. Knepley 20236528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void **ctx) 20240c2f2876SMatthew G. Knepley { 20250c2f2876SMatthew G. Knepley PetscFunctionBegin; 20266528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 20276528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 20280c2f2876SMatthew G. Knepley PetscValidPointer(ctx, 3); 20296528b96dSMatthew G. Knepley *ctx = ds->ctx[f]; 20300c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 20310c2f2876SMatthew G. Knepley } 20320c2f2876SMatthew G. Knepley 20336528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx) 20340c2f2876SMatthew G. Knepley { 20350c2f2876SMatthew G. Knepley PetscErrorCode ierr; 20360c2f2876SMatthew G. Knepley 20370c2f2876SMatthew G. Knepley PetscFunctionBegin; 20386528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 20390c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 20406528b96dSMatthew G. Knepley ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr); 20416528b96dSMatthew G. Knepley ds->ctx[f] = ctx; 20420c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 20430c2f2876SMatthew G. Knepley } 20440c2f2876SMatthew G. Knepley 2045194d53e6SMatthew G. Knepley /*@C 2046194d53e6SMatthew G. Knepley PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field 2047194d53e6SMatthew G. Knepley 2048194d53e6SMatthew G. Knepley Not collective 2049194d53e6SMatthew G. Knepley 2050194d53e6SMatthew G. Knepley Input Parameters: 20516528b96dSMatthew G. Knepley + ds - The PetscDS 2052194d53e6SMatthew G. Knepley - f - The test field number 2053194d53e6SMatthew G. Knepley 2054194d53e6SMatthew G. Knepley Output Parameters: 2055194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term 2056194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2057194d53e6SMatthew G. Knepley 2058194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2059194d53e6SMatthew G. Knepley 2060194d53e6SMatthew 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 2061194d53e6SMatthew G. Knepley 2062194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2063194d53e6SMatthew G. Knepley 206430b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2065194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2066194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 206730b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2068194d53e6SMatthew G. Knepley 2069194d53e6SMatthew G. Knepley + dim - the spatial dimension 2070194d53e6SMatthew G. Knepley . Nf - the number of fields 2071194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2072194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2073194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2074194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2075194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2076194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2077194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2078194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2079194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2080194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2081194d53e6SMatthew G. Knepley . t - current time 2082194d53e6SMatthew G. Knepley . x - coordinates of the current point 2083194d53e6SMatthew G. Knepley . n - unit normal at the current point 208497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 208597b6e6e8SMatthew G. Knepley . constants - constant parameters 2086194d53e6SMatthew G. Knepley - f0 - output values at the current point 2087194d53e6SMatthew G. Knepley 2088194d53e6SMatthew G. Knepley Level: intermediate 2089194d53e6SMatthew G. Knepley 2090194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual() 2091194d53e6SMatthew G. Knepley @*/ 20926528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS ds, PetscInt f, 209330b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2094194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2095194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 209697b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 209730b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2098194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2099194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 210097b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 21012764a2aaSMatthew G. Knepley { 21026528b96dSMatthew G. Knepley PetscBdPointFunc *tmp0, *tmp1; 21036528b96dSMatthew G. Knepley PetscInt n0, n1; 21046528b96dSMatthew G. Knepley PetscErrorCode ierr; 21056528b96dSMatthew G. Knepley 21062764a2aaSMatthew G. Knepley PetscFunctionBegin; 21076528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 21086528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 21096528b96dSMatthew G. Knepley ierr = PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr); 21106528b96dSMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 21116528b96dSMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 21122764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21132764a2aaSMatthew G. Knepley } 21142764a2aaSMatthew G. Knepley 2115194d53e6SMatthew G. Knepley /*@C 2116194d53e6SMatthew G. Knepley PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field 2117194d53e6SMatthew G. Knepley 2118194d53e6SMatthew G. Knepley Not collective 2119194d53e6SMatthew G. Knepley 2120194d53e6SMatthew G. Knepley Input Parameters: 21216528b96dSMatthew G. Knepley + ds - The PetscDS 2122194d53e6SMatthew G. Knepley . f - The test field number 2123194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term 2124194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2125194d53e6SMatthew G. Knepley 2126194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2127194d53e6SMatthew G. Knepley 2128194d53e6SMatthew 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 2129194d53e6SMatthew G. Knepley 2130194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2131194d53e6SMatthew G. Knepley 213230b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2133194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2134194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 213530b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2136194d53e6SMatthew G. Knepley 2137194d53e6SMatthew G. Knepley + dim - the spatial dimension 2138194d53e6SMatthew G. Knepley . Nf - the number of fields 2139194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2140194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2141194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2142194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2143194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2144194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2145194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2146194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2147194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2148194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2149194d53e6SMatthew G. Knepley . t - current time 2150194d53e6SMatthew G. Knepley . x - coordinates of the current point 2151194d53e6SMatthew G. Knepley . n - unit normal at the current point 215297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 215397b6e6e8SMatthew G. Knepley . constants - constant parameters 2154194d53e6SMatthew G. Knepley - f0 - output values at the current point 2155194d53e6SMatthew G. Knepley 2156194d53e6SMatthew G. Knepley Level: intermediate 2157194d53e6SMatthew G. Knepley 2158194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual() 2159194d53e6SMatthew G. Knepley @*/ 21606528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS ds, PetscInt f, 216130b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2162194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2163194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 216497b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 216530b9ff8bSMatthew G. Knepley void (*f1)(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[], 216897b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 21692764a2aaSMatthew G. Knepley { 21702764a2aaSMatthew G. Knepley PetscErrorCode ierr; 21712764a2aaSMatthew G. Knepley 21722764a2aaSMatthew G. Knepley PetscFunctionBegin; 21736528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 21742764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 21756528b96dSMatthew G. Knepley ierr = PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, f0, 0, f1);CHKERRQ(ierr); 21762764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21772764a2aaSMatthew G. Knepley } 21782764a2aaSMatthew G. Knepley 217927f02ce8SMatthew G. Knepley /*@ 218027f02ce8SMatthew G. Knepley PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set 218127f02ce8SMatthew G. Knepley 218227f02ce8SMatthew G. Knepley Not collective 218327f02ce8SMatthew G. Knepley 218427f02ce8SMatthew G. Knepley Input Parameter: 21856528b96dSMatthew G. Knepley . ds - The PetscDS 218627f02ce8SMatthew G. Knepley 218727f02ce8SMatthew G. Knepley Output Parameter: 218827f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set 218927f02ce8SMatthew G. Knepley 219027f02ce8SMatthew G. Knepley Level: intermediate 219127f02ce8SMatthew G. Knepley 219227f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian() 219327f02ce8SMatthew G. Knepley @*/ 21946528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac) 219527f02ce8SMatthew G. Knepley { 21966528b96dSMatthew G. Knepley PetscErrorCode ierr; 219727f02ce8SMatthew G. Knepley 219827f02ce8SMatthew G. Knepley PetscFunctionBegin; 21996528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 22006528b96dSMatthew G. Knepley PetscValidBoolPointer(hasBdJac, 2); 22016528b96dSMatthew G. Knepley ierr = PetscWeakFormHasBdJacobian(ds->wf, hasBdJac);CHKERRQ(ierr); 220227f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 220327f02ce8SMatthew G. Knepley } 220427f02ce8SMatthew G. Knepley 2205194d53e6SMatthew G. Knepley /*@C 2206194d53e6SMatthew G. Knepley PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field 2207194d53e6SMatthew G. Knepley 2208194d53e6SMatthew G. Knepley Not collective 2209194d53e6SMatthew G. Knepley 2210194d53e6SMatthew G. Knepley Input Parameters: 22116528b96dSMatthew G. Knepley + ds - The PetscDS 2212194d53e6SMatthew G. Knepley . f - The test field number 2213194d53e6SMatthew G. Knepley - g - The field number 2214194d53e6SMatthew G. Knepley 2215194d53e6SMatthew G. Knepley Output Parameters: 2216194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 2217194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2218194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2219194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2220194d53e6SMatthew G. Knepley 2221194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2222194d53e6SMatthew G. Knepley 2223194d53e6SMatthew 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 2224194d53e6SMatthew G. Knepley 2225194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2226194d53e6SMatthew G. Knepley 222730b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2228194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2229194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 223030b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2231194d53e6SMatthew G. Knepley 2232194d53e6SMatthew G. Knepley + dim - the spatial dimension 2233194d53e6SMatthew G. Knepley . Nf - the number of fields 2234194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2235194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2236194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2237194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2238194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2239194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2240194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2241194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2242194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2243194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2244194d53e6SMatthew G. Knepley . t - current time 22452aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2246194d53e6SMatthew G. Knepley . x - coordinates of the current point 2247194d53e6SMatthew G. Knepley . n - normal at the current point 224897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 224997b6e6e8SMatthew G. Knepley . constants - constant parameters 2250194d53e6SMatthew G. Knepley - g0 - output values at the current point 2251194d53e6SMatthew G. Knepley 2252194d53e6SMatthew G. Knepley Level: intermediate 2253194d53e6SMatthew G. Knepley 2254194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian() 2255194d53e6SMatthew G. Knepley @*/ 22566528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS ds, PetscInt f, PetscInt g, 225730b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2258194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2259194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 226097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 226130b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2262194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2263194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 226497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 226530b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2266194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2267194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 226897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 226930b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2270194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2271194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 227297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 22732764a2aaSMatthew G. Knepley { 22746528b96dSMatthew G. Knepley PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3; 22756528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 22766528b96dSMatthew G. Knepley PetscErrorCode ierr; 22776528b96dSMatthew G. Knepley 22782764a2aaSMatthew G. Knepley PetscFunctionBegin; 22796528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 22806528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 22816528b96dSMatthew G. Knepley if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf); 22826528b96dSMatthew G. Knepley ierr = PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 22836528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 22846528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 22856528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 22866528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 22872764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22882764a2aaSMatthew G. Knepley } 22892764a2aaSMatthew G. Knepley 2290194d53e6SMatthew G. Knepley /*@C 2291194d53e6SMatthew G. Knepley PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field 2292194d53e6SMatthew G. Knepley 2293194d53e6SMatthew G. Knepley Not collective 2294194d53e6SMatthew G. Knepley 2295194d53e6SMatthew G. Knepley Input Parameters: 22966528b96dSMatthew G. Knepley + ds - The PetscDS 2297194d53e6SMatthew G. Knepley . f - The test field number 2298194d53e6SMatthew G. Knepley . g - The field number 2299194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 2300194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2301194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2302194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2303194d53e6SMatthew G. Knepley 2304194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2305194d53e6SMatthew G. Knepley 2306194d53e6SMatthew 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 2307194d53e6SMatthew G. Knepley 2308194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2309194d53e6SMatthew G. Knepley 231030b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2311194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2312194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 231330b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2314194d53e6SMatthew G. Knepley 2315194d53e6SMatthew G. Knepley + dim - the spatial dimension 2316194d53e6SMatthew G. Knepley . Nf - the number of fields 2317194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2318194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2319194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2320194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2321194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2322194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2323194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2324194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2325194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2326194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2327194d53e6SMatthew G. Knepley . t - current time 23282aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2329194d53e6SMatthew G. Knepley . x - coordinates of the current point 2330194d53e6SMatthew G. Knepley . n - normal at the current point 233197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 233297b6e6e8SMatthew G. Knepley . constants - constant parameters 2333194d53e6SMatthew G. Knepley - g0 - output values at the current point 2334194d53e6SMatthew G. Knepley 2335194d53e6SMatthew G. Knepley Level: intermediate 2336194d53e6SMatthew G. Knepley 2337194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian() 2338194d53e6SMatthew G. Knepley @*/ 23396528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS ds, PetscInt f, PetscInt g, 234030b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2341194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2342194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 234397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 234430b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2345194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2346194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 234797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 234830b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2349194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2350194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 235197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 235230b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2353194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2354194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 235597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 23562764a2aaSMatthew G. Knepley { 23572764a2aaSMatthew G. Knepley PetscErrorCode ierr; 23582764a2aaSMatthew G. Knepley 23592764a2aaSMatthew G. Knepley PetscFunctionBegin; 23606528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 23612764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 23622764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 23632764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 23642764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 23652764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 23662764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 23676528b96dSMatthew G. Knepley ierr = PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 23682764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 23692764a2aaSMatthew G. Knepley } 23702764a2aaSMatthew G. Knepley 237127f02ce8SMatthew G. Knepley /*@ 237227f02ce8SMatthew G. Knepley PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set 237327f02ce8SMatthew G. Knepley 237427f02ce8SMatthew G. Knepley Not collective 237527f02ce8SMatthew G. Knepley 237627f02ce8SMatthew G. Knepley Input Parameter: 23776528b96dSMatthew G. Knepley . ds - The PetscDS 237827f02ce8SMatthew G. Knepley 237927f02ce8SMatthew G. Knepley Output Parameter: 238027f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set 238127f02ce8SMatthew G. Knepley 238227f02ce8SMatthew G. Knepley Level: intermediate 238327f02ce8SMatthew G. Knepley 238427f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian() 238527f02ce8SMatthew G. Knepley @*/ 23866528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre) 238727f02ce8SMatthew G. Knepley { 23886528b96dSMatthew G. Knepley PetscErrorCode ierr; 238927f02ce8SMatthew G. Knepley 239027f02ce8SMatthew G. Knepley PetscFunctionBegin; 23916528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 23926528b96dSMatthew G. Knepley PetscValidBoolPointer(hasBdJacPre, 2); 23936528b96dSMatthew G. Knepley ierr = PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre);CHKERRQ(ierr); 239427f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 239527f02ce8SMatthew G. Knepley } 239627f02ce8SMatthew G. Knepley 239727f02ce8SMatthew G. Knepley /*@C 239827f02ce8SMatthew G. Knepley PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field 239927f02ce8SMatthew G. Knepley 240027f02ce8SMatthew G. Knepley Not collective 240127f02ce8SMatthew G. Knepley 240227f02ce8SMatthew G. Knepley Input Parameters: 24036528b96dSMatthew G. Knepley + ds - The PetscDS 240427f02ce8SMatthew G. Knepley . f - The test field number 240527f02ce8SMatthew G. Knepley - g - The field number 240627f02ce8SMatthew G. Knepley 240727f02ce8SMatthew G. Knepley Output Parameters: 240827f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term 240927f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 241027f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 241127f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 241227f02ce8SMatthew G. Knepley 241327f02ce8SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 241427f02ce8SMatthew G. Knepley 241527f02ce8SMatthew 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 241627f02ce8SMatthew G. Knepley 241727f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 241827f02ce8SMatthew G. Knepley 241927f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 242027f02ce8SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 242127f02ce8SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 242227f02ce8SMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 242327f02ce8SMatthew G. Knepley 242427f02ce8SMatthew G. Knepley + dim - the spatial dimension 242527f02ce8SMatthew G. Knepley . Nf - the number of fields 242627f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 242727f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 242827f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 242927f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 243027f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 243127f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 243227f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 243327f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 243427f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 243527f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 243627f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 243727f02ce8SMatthew G. Knepley . t - current time 243827f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 243927f02ce8SMatthew G. Knepley . x - coordinates of the current point 244027f02ce8SMatthew G. Knepley . n - normal at the current point 244127f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 244227f02ce8SMatthew G. Knepley . constants - constant parameters 244327f02ce8SMatthew G. Knepley - g0 - output values at the current point 244427f02ce8SMatthew G. Knepley 244527f02ce8SMatthew G. Knepley This is not yet available in Fortran. 244627f02ce8SMatthew G. Knepley 244727f02ce8SMatthew G. Knepley Level: intermediate 244827f02ce8SMatthew G. Knepley 244927f02ce8SMatthew G. Knepley .seealso: PetscDSSetBdJacobianPreconditioner() 245027f02ce8SMatthew G. Knepley @*/ 24516528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, 245227f02ce8SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 245327f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 245427f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 245527f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 245627f02ce8SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 245727f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 245827f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 245927f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 246027f02ce8SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 246127f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 246227f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 246327f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 246427f02ce8SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 246527f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 246627f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 246727f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 246827f02ce8SMatthew G. Knepley { 24696528b96dSMatthew G. Knepley PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3; 24706528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 24716528b96dSMatthew G. Knepley PetscErrorCode ierr; 24726528b96dSMatthew G. Knepley 247327f02ce8SMatthew G. Knepley PetscFunctionBegin; 24746528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 24756528b96dSMatthew G. Knepley if ((f < 0) || (f >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, ds->Nf); 24766528b96dSMatthew G. Knepley if ((g < 0) || (g >= ds->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, ds->Nf); 24776528b96dSMatthew G. Knepley ierr = PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 24786528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 24796528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 24806528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 24816528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 248227f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 248327f02ce8SMatthew G. Knepley } 248427f02ce8SMatthew G. Knepley 248527f02ce8SMatthew G. Knepley /*@C 248627f02ce8SMatthew G. Knepley PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field 248727f02ce8SMatthew G. Knepley 248827f02ce8SMatthew G. Knepley Not collective 248927f02ce8SMatthew G. Knepley 249027f02ce8SMatthew G. Knepley Input Parameters: 24916528b96dSMatthew G. Knepley + ds - The PetscDS 249227f02ce8SMatthew G. Knepley . f - The test field number 249327f02ce8SMatthew G. Knepley . g - The field number 249427f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term 249527f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 249627f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 249727f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 249827f02ce8SMatthew G. Knepley 249927f02ce8SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 250027f02ce8SMatthew G. Knepley 250127f02ce8SMatthew 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 250227f02ce8SMatthew G. Knepley 250327f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 250427f02ce8SMatthew G. Knepley 250527f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 250627f02ce8SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 250727f02ce8SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 250827f02ce8SMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 250927f02ce8SMatthew G. Knepley 251027f02ce8SMatthew G. Knepley + dim - the spatial dimension 251127f02ce8SMatthew G. Knepley . Nf - the number of fields 251227f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 251327f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 251427f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 251527f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 251627f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 251727f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 251827f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 251927f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 252027f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 252127f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 252227f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 252327f02ce8SMatthew G. Knepley . t - current time 252427f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 252527f02ce8SMatthew G. Knepley . x - coordinates of the current point 252627f02ce8SMatthew G. Knepley . n - normal at the current point 252727f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 252827f02ce8SMatthew G. Knepley . constants - constant parameters 252927f02ce8SMatthew G. Knepley - g0 - output values at the current point 253027f02ce8SMatthew G. Knepley 253127f02ce8SMatthew G. Knepley This is not yet available in Fortran. 253227f02ce8SMatthew G. Knepley 253327f02ce8SMatthew G. Knepley Level: intermediate 253427f02ce8SMatthew G. Knepley 253527f02ce8SMatthew G. Knepley .seealso: PetscDSGetBdJacobianPreconditioner() 253627f02ce8SMatthew G. Knepley @*/ 25376528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, 253827f02ce8SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 253927f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 254027f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 254127f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 254227f02ce8SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 254327f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 254427f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 254527f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 254627f02ce8SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 254727f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 254827f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 254927f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 255027f02ce8SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 255127f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 255227f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 255327f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 255427f02ce8SMatthew G. Knepley { 255527f02ce8SMatthew G. Knepley PetscErrorCode ierr; 255627f02ce8SMatthew G. Knepley 255727f02ce8SMatthew G. Knepley PetscFunctionBegin; 25586528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 255927f02ce8SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 256027f02ce8SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 256127f02ce8SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 256227f02ce8SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 256327f02ce8SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 256427f02ce8SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 25656528b96dSMatthew G. Knepley ierr = PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 256627f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 256727f02ce8SMatthew G. Knepley } 256827f02ce8SMatthew G. Knepley 25690d3e9b51SMatthew G. Knepley /*@C 2570c371a6d1SMatthew G. Knepley PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field 2571c371a6d1SMatthew G. Knepley 2572c371a6d1SMatthew G. Knepley Not collective 2573c371a6d1SMatthew G. Knepley 2574c371a6d1SMatthew G. Knepley Input Parameters: 2575c371a6d1SMatthew G. Knepley + prob - The PetscDS 2576c371a6d1SMatthew G. Knepley - f - The test field number 2577c371a6d1SMatthew G. Knepley 2578c371a6d1SMatthew G. Knepley Output Parameter: 257995cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field 258095cbbfd3SMatthew G. Knepley - exactCtx - exact solution context 2581c371a6d1SMatthew G. Knepley 2582c371a6d1SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2583c371a6d1SMatthew G. Knepley 2584c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2585c371a6d1SMatthew G. Knepley 2586c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2587c371a6d1SMatthew G. Knepley . t - current time 2588c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2589c371a6d1SMatthew G. Knepley . Nc - the number of field components 2590c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2591c371a6d1SMatthew G. Knepley - ctx - a user context 2592c371a6d1SMatthew G. Knepley 2593c371a6d1SMatthew G. Knepley Level: intermediate 2594c371a6d1SMatthew G. Knepley 2595f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolution(), PetscDSGetExactSolutionTimeDerivative() 2596c371a6d1SMatthew G. Knepley @*/ 259795cbbfd3SMatthew 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) 2598c371a6d1SMatthew G. Knepley { 2599c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2600c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2601c371a6d1SMatthew 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); 2602c371a6d1SMatthew G. Knepley if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];} 260395cbbfd3SMatthew G. Knepley if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];} 2604c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2605c371a6d1SMatthew G. Knepley } 2606c371a6d1SMatthew G. Knepley 2607c371a6d1SMatthew G. Knepley /*@C 2608578a5ef5SMatthew Knepley PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field 2609c371a6d1SMatthew G. Knepley 2610c371a6d1SMatthew G. Knepley Not collective 2611c371a6d1SMatthew G. Knepley 2612c371a6d1SMatthew G. Knepley Input Parameters: 2613c371a6d1SMatthew G. Knepley + prob - The PetscDS 2614c371a6d1SMatthew G. Knepley . f - The test field number 261595cbbfd3SMatthew G. Knepley . sol - solution function for the test fields 261695cbbfd3SMatthew G. Knepley - ctx - solution context or NULL 2617c371a6d1SMatthew G. Knepley 2618c371a6d1SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2619c371a6d1SMatthew G. Knepley 2620c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2621c371a6d1SMatthew G. Knepley 2622c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2623c371a6d1SMatthew G. Knepley . t - current time 2624c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2625c371a6d1SMatthew G. Knepley . Nc - the number of field components 2626c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2627c371a6d1SMatthew G. Knepley - ctx - a user context 2628c371a6d1SMatthew G. Knepley 2629c371a6d1SMatthew G. Knepley Level: intermediate 2630c371a6d1SMatthew G. Knepley 2631c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution() 2632c371a6d1SMatthew G. Knepley @*/ 263395cbbfd3SMatthew 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) 2634c371a6d1SMatthew G. Knepley { 2635c371a6d1SMatthew G. Knepley PetscErrorCode ierr; 2636c371a6d1SMatthew G. Knepley 2637c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2638c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2639c371a6d1SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 2640c371a6d1SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 2641c371a6d1SMatthew G. Knepley if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;} 264295cbbfd3SMatthew G. Knepley if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;} 2643c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2644c371a6d1SMatthew G. Knepley } 2645c371a6d1SMatthew G. Knepley 26465638fd0eSMatthew G. Knepley /*@C 2647f2cacb80SMatthew G. Knepley PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field 2648f2cacb80SMatthew G. Knepley 2649f2cacb80SMatthew G. Knepley Not collective 2650f2cacb80SMatthew G. Knepley 2651f2cacb80SMatthew G. Knepley Input Parameters: 2652f2cacb80SMatthew G. Knepley + prob - The PetscDS 2653f2cacb80SMatthew G. Knepley - f - The test field number 2654f2cacb80SMatthew G. Knepley 2655f2cacb80SMatthew G. Knepley Output Parameter: 2656f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field 2657f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context 2658f2cacb80SMatthew G. Knepley 2659f2cacb80SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2660f2cacb80SMatthew G. Knepley 2661f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2662f2cacb80SMatthew G. Knepley 2663f2cacb80SMatthew G. Knepley + dim - the spatial dimension 2664f2cacb80SMatthew G. Knepley . t - current time 2665f2cacb80SMatthew G. Knepley . x - coordinates of the current point 2666f2cacb80SMatthew G. Knepley . Nc - the number of field components 2667f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point 2668f2cacb80SMatthew G. Knepley - ctx - a user context 2669f2cacb80SMatthew G. Knepley 2670f2cacb80SMatthew G. Knepley Level: intermediate 2671f2cacb80SMatthew G. Knepley 2672f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolutionTimeDerivative(), PetscDSGetExactSolution() 2673f2cacb80SMatthew G. Knepley @*/ 2674f2cacb80SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void **ctx) 2675f2cacb80SMatthew G. Knepley { 2676f2cacb80SMatthew G. Knepley PetscFunctionBegin; 2677f2cacb80SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2678f2cacb80SMatthew 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); 2679f2cacb80SMatthew G. Knepley if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol_t[f];} 2680f2cacb80SMatthew G. Knepley if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx_t[f];} 2681f2cacb80SMatthew G. Knepley PetscFunctionReturn(0); 2682f2cacb80SMatthew G. Knepley } 2683f2cacb80SMatthew G. Knepley 2684f2cacb80SMatthew G. Knepley /*@C 2685f2cacb80SMatthew G. Knepley PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field 2686f2cacb80SMatthew G. Knepley 2687f2cacb80SMatthew G. Knepley Not collective 2688f2cacb80SMatthew G. Knepley 2689f2cacb80SMatthew G. Knepley Input Parameters: 2690f2cacb80SMatthew G. Knepley + prob - The PetscDS 2691f2cacb80SMatthew G. Knepley . f - The test field number 2692f2cacb80SMatthew G. Knepley . sol - time derivative of the solution function for the test fields 2693f2cacb80SMatthew G. Knepley - ctx - time derivative of the solution context or NULL 2694f2cacb80SMatthew G. Knepley 2695f2cacb80SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2696f2cacb80SMatthew G. Knepley 2697f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2698f2cacb80SMatthew G. Knepley 2699f2cacb80SMatthew G. Knepley + dim - the spatial dimension 2700f2cacb80SMatthew G. Knepley . t - current time 2701f2cacb80SMatthew G. Knepley . x - coordinates of the current point 2702f2cacb80SMatthew G. Knepley . Nc - the number of field components 2703f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point 2704f2cacb80SMatthew G. Knepley - ctx - a user context 2705f2cacb80SMatthew G. Knepley 2706f2cacb80SMatthew G. Knepley Level: intermediate 2707f2cacb80SMatthew G. Knepley 2708f2cacb80SMatthew G. Knepley .seealso: PetscDSGetExactSolutionTimeDerivative(), PetscDSSetExactSolution() 2709f2cacb80SMatthew G. Knepley @*/ 2710f2cacb80SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolutionTimeDerivative(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx), void *ctx) 2711f2cacb80SMatthew G. Knepley { 2712f2cacb80SMatthew G. Knepley PetscErrorCode ierr; 2713f2cacb80SMatthew G. Knepley 2714f2cacb80SMatthew G. Knepley PetscFunctionBegin; 2715f2cacb80SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2716f2cacb80SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 2717f2cacb80SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 2718f2cacb80SMatthew G. Knepley if (sol) {PetscValidFunction(sol, 3); prob->exactSol_t[f] = sol;} 2719f2cacb80SMatthew G. Knepley if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx_t[f] = ctx;} 2720f2cacb80SMatthew G. Knepley PetscFunctionReturn(0); 2721f2cacb80SMatthew G. Knepley } 2722f2cacb80SMatthew G. Knepley 2723f2cacb80SMatthew G. Knepley /*@C 272497b6e6e8SMatthew G. Knepley PetscDSGetConstants - Returns the array of constants passed to point functions 272597b6e6e8SMatthew G. Knepley 272697b6e6e8SMatthew G. Knepley Not collective 272797b6e6e8SMatthew G. Knepley 272897b6e6e8SMatthew G. Knepley Input Parameter: 272997b6e6e8SMatthew G. Knepley . prob - The PetscDS object 273097b6e6e8SMatthew G. Knepley 273197b6e6e8SMatthew G. Knepley Output Parameters: 273297b6e6e8SMatthew G. Knepley + numConstants - The number of constants 273397b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 273497b6e6e8SMatthew G. Knepley 273597b6e6e8SMatthew G. Knepley Level: intermediate 273697b6e6e8SMatthew G. Knepley 273797b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate() 273897b6e6e8SMatthew G. Knepley @*/ 273997b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[]) 274097b6e6e8SMatthew G. Knepley { 274197b6e6e8SMatthew G. Knepley PetscFunctionBegin; 274297b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 274397b6e6e8SMatthew G. Knepley if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;} 274497b6e6e8SMatthew G. Knepley if (constants) {PetscValidPointer(constants, 3); *constants = prob->constants;} 274597b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 274697b6e6e8SMatthew G. Knepley } 274797b6e6e8SMatthew G. Knepley 27480d3e9b51SMatthew G. Knepley /*@C 274997b6e6e8SMatthew G. Knepley PetscDSSetConstants - Set the array of constants passed to point functions 275097b6e6e8SMatthew G. Knepley 275197b6e6e8SMatthew G. Knepley Not collective 275297b6e6e8SMatthew G. Knepley 275397b6e6e8SMatthew G. Knepley Input Parameters: 275497b6e6e8SMatthew G. Knepley + prob - The PetscDS object 275597b6e6e8SMatthew G. Knepley . numConstants - The number of constants 275697b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 275797b6e6e8SMatthew G. Knepley 275897b6e6e8SMatthew G. Knepley Level: intermediate 275997b6e6e8SMatthew G. Knepley 276097b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate() 276197b6e6e8SMatthew G. Knepley @*/ 276297b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[]) 276397b6e6e8SMatthew G. Knepley { 276497b6e6e8SMatthew G. Knepley PetscErrorCode ierr; 276597b6e6e8SMatthew G. Knepley 276697b6e6e8SMatthew G. Knepley PetscFunctionBegin; 276797b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 276897b6e6e8SMatthew G. Knepley if (numConstants != prob->numConstants) { 276997b6e6e8SMatthew G. Knepley ierr = PetscFree(prob->constants);CHKERRQ(ierr); 277097b6e6e8SMatthew G. Knepley prob->numConstants = numConstants; 277197b6e6e8SMatthew G. Knepley if (prob->numConstants) { 277297b6e6e8SMatthew G. Knepley ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr); 277320be0f5bSMatthew G. Knepley } else { 277420be0f5bSMatthew G. Knepley prob->constants = NULL; 277520be0f5bSMatthew G. Knepley } 277620be0f5bSMatthew G. Knepley } 277720be0f5bSMatthew G. Knepley if (prob->numConstants) { 277820be0f5bSMatthew G. Knepley PetscValidPointer(constants, 3); 2779580bdb30SBarry Smith ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr); 278097b6e6e8SMatthew G. Knepley } 278197b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 278297b6e6e8SMatthew G. Knepley } 278397b6e6e8SMatthew G. Knepley 27844cd1e086SMatthew G. Knepley /*@ 27854cd1e086SMatthew G. Knepley PetscDSGetFieldIndex - Returns the index of the given field 27864cd1e086SMatthew G. Knepley 27874cd1e086SMatthew G. Knepley Not collective 27884cd1e086SMatthew G. Knepley 27894cd1e086SMatthew G. Knepley Input Parameters: 27904cd1e086SMatthew G. Knepley + prob - The PetscDS object 27914cd1e086SMatthew G. Knepley - disc - The discretization object 27924cd1e086SMatthew G. Knepley 27934cd1e086SMatthew G. Knepley Output Parameter: 27944cd1e086SMatthew G. Knepley . f - The field number 27954cd1e086SMatthew G. Knepley 27964cd1e086SMatthew G. Knepley Level: beginner 27974cd1e086SMatthew G. Knepley 2798f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 27994cd1e086SMatthew G. Knepley @*/ 28004cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f) 28014cd1e086SMatthew G. Knepley { 28024cd1e086SMatthew G. Knepley PetscInt g; 28034cd1e086SMatthew G. Knepley 28044cd1e086SMatthew G. Knepley PetscFunctionBegin; 28054cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 28064cd1e086SMatthew G. Knepley PetscValidPointer(f, 3); 28074cd1e086SMatthew G. Knepley *f = -1; 28084cd1e086SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;} 28094cd1e086SMatthew G. Knepley if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS."); 28104cd1e086SMatthew G. Knepley *f = g; 28114cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 28124cd1e086SMatthew G. Knepley } 28134cd1e086SMatthew G. Knepley 28144cd1e086SMatthew G. Knepley /*@ 28154cd1e086SMatthew G. Knepley PetscDSGetFieldSize - Returns the size of the given field in the full space basis 28164cd1e086SMatthew G. Knepley 28174cd1e086SMatthew G. Knepley Not collective 28184cd1e086SMatthew G. Knepley 28194cd1e086SMatthew G. Knepley Input Parameters: 28204cd1e086SMatthew G. Knepley + prob - The PetscDS object 28214cd1e086SMatthew G. Knepley - f - The field number 28224cd1e086SMatthew G. Knepley 28234cd1e086SMatthew G. Knepley Output Parameter: 28244cd1e086SMatthew G. Knepley . size - The size 28254cd1e086SMatthew G. Knepley 28264cd1e086SMatthew G. Knepley Level: beginner 28274cd1e086SMatthew G. Knepley 2828f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate() 28294cd1e086SMatthew G. Knepley @*/ 28304cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size) 28314cd1e086SMatthew G. Knepley { 28322166fd64SMatthew G. Knepley PetscErrorCode ierr; 28332166fd64SMatthew G. Knepley 28344cd1e086SMatthew G. Knepley PetscFunctionBegin; 28354cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 28364cd1e086SMatthew G. Knepley PetscValidPointer(size, 3); 28374cd1e086SMatthew 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); 28382166fd64SMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2839d4742ddaSMatthew G. Knepley *size = prob->Nb[f]; 28404cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 28414cd1e086SMatthew G. Knepley } 28424cd1e086SMatthew G. Knepley 2843bc4ae4beSMatthew G. Knepley /*@ 2844bc4ae4beSMatthew G. Knepley PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis 2845bc4ae4beSMatthew G. Knepley 2846bc4ae4beSMatthew G. Knepley Not collective 2847bc4ae4beSMatthew G. Knepley 2848bc4ae4beSMatthew G. Knepley Input Parameters: 2849bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 2850bc4ae4beSMatthew G. Knepley - f - The field number 2851bc4ae4beSMatthew G. Knepley 2852bc4ae4beSMatthew G. Knepley Output Parameter: 2853bc4ae4beSMatthew G. Knepley . off - The offset 2854bc4ae4beSMatthew G. Knepley 2855bc4ae4beSMatthew G. Knepley Level: beginner 2856bc4ae4beSMatthew G. Knepley 2857f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate() 2858bc4ae4beSMatthew G. Knepley @*/ 28592764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 28602764a2aaSMatthew G. Knepley { 28614cd1e086SMatthew G. Knepley PetscInt size, g; 28622764a2aaSMatthew G. Knepley PetscErrorCode ierr; 28632764a2aaSMatthew G. Knepley 28642764a2aaSMatthew G. Knepley PetscFunctionBegin; 28652764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 28662764a2aaSMatthew G. Knepley PetscValidPointer(off, 3); 28672764a2aaSMatthew 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); 28682764a2aaSMatthew G. Knepley *off = 0; 28692764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 28704cd1e086SMatthew G. Knepley ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr); 28714cd1e086SMatthew G. Knepley *off += size; 28722764a2aaSMatthew G. Knepley } 28732764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 28742764a2aaSMatthew G. Knepley } 28752764a2aaSMatthew G. Knepley 2876bc4ae4beSMatthew G. Knepley /*@ 287747e57110SSander Arens PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point 2878bc4ae4beSMatthew G. Knepley 2879bc4ae4beSMatthew G. Knepley Not collective 2880bc4ae4beSMatthew G. Knepley 288147e57110SSander Arens Input Parameter: 288247e57110SSander Arens . prob - The PetscDS object 2883bc4ae4beSMatthew G. Knepley 2884bc4ae4beSMatthew G. Knepley Output Parameter: 288547e57110SSander Arens . dimensions - The number of dimensions 2886bc4ae4beSMatthew G. Knepley 2887bc4ae4beSMatthew G. Knepley Level: beginner 2888bc4ae4beSMatthew G. Knepley 288947e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 2890bc4ae4beSMatthew G. Knepley @*/ 289147e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[]) 28922764a2aaSMatthew G. Knepley { 28932764a2aaSMatthew G. Knepley PetscErrorCode ierr; 28942764a2aaSMatthew G. Knepley 28952764a2aaSMatthew G. Knepley PetscFunctionBegin; 28962764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 289747e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 289847e57110SSander Arens PetscValidPointer(dimensions, 2); 289947e57110SSander Arens *dimensions = prob->Nb; 290047e57110SSander Arens PetscFunctionReturn(0); 29016ce16762SMatthew G. Knepley } 290247e57110SSander Arens 290347e57110SSander Arens /*@ 290447e57110SSander Arens PetscDSGetComponents - Returns the number of components for each field on an evaluation point 290547e57110SSander Arens 290647e57110SSander Arens Not collective 290747e57110SSander Arens 290847e57110SSander Arens Input Parameter: 290947e57110SSander Arens . prob - The PetscDS object 291047e57110SSander Arens 291147e57110SSander Arens Output Parameter: 291247e57110SSander Arens . components - The number of components 291347e57110SSander Arens 291447e57110SSander Arens Level: beginner 291547e57110SSander Arens 291647e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 291747e57110SSander Arens @*/ 291847e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[]) 291947e57110SSander Arens { 292047e57110SSander Arens PetscErrorCode ierr; 292147e57110SSander Arens 292247e57110SSander Arens PetscFunctionBegin; 292347e57110SSander Arens PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 292447e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 292547e57110SSander Arens PetscValidPointer(components, 2); 292647e57110SSander Arens *components = prob->Nc; 29276ce16762SMatthew G. Knepley PetscFunctionReturn(0); 29286ce16762SMatthew G. Knepley } 29296ce16762SMatthew G. Knepley 29306ce16762SMatthew G. Knepley /*@ 29316ce16762SMatthew G. Knepley PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point 29326ce16762SMatthew G. Knepley 29336ce16762SMatthew G. Knepley Not collective 29346ce16762SMatthew G. Knepley 29356ce16762SMatthew G. Knepley Input Parameters: 29366ce16762SMatthew G. Knepley + prob - The PetscDS object 29376ce16762SMatthew G. Knepley - f - The field number 29386ce16762SMatthew G. Knepley 29396ce16762SMatthew G. Knepley Output Parameter: 29406ce16762SMatthew G. Knepley . off - The offset 29416ce16762SMatthew G. Knepley 29426ce16762SMatthew G. Knepley Level: beginner 29436ce16762SMatthew G. Knepley 2944f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 29456ce16762SMatthew G. Knepley @*/ 29466ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off) 29476ce16762SMatthew G. Knepley { 29486ce16762SMatthew G. Knepley PetscFunctionBegin; 29496ce16762SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 29506ce16762SMatthew G. Knepley PetscValidPointer(off, 3); 29516ce16762SMatthew 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); 295247e57110SSander Arens *off = prob->off[f]; 29532764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 29542764a2aaSMatthew G. Knepley } 29552764a2aaSMatthew G. Knepley 2956194d53e6SMatthew G. Knepley /*@ 2957194d53e6SMatthew G. Knepley PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point 2958194d53e6SMatthew G. Knepley 2959194d53e6SMatthew G. Knepley Not collective 2960194d53e6SMatthew G. Knepley 2961194d53e6SMatthew G. Knepley Input Parameter: 2962194d53e6SMatthew G. Knepley . prob - The PetscDS object 2963194d53e6SMatthew G. Knepley 2964194d53e6SMatthew G. Knepley Output Parameter: 2965194d53e6SMatthew G. Knepley . offsets - The offsets 2966194d53e6SMatthew G. Knepley 2967194d53e6SMatthew G. Knepley Level: beginner 2968194d53e6SMatthew G. Knepley 2969f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2970194d53e6SMatthew G. Knepley @*/ 2971194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[]) 2972194d53e6SMatthew G. Knepley { 2973194d53e6SMatthew G. Knepley PetscFunctionBegin; 2974194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2975194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2976194d53e6SMatthew G. Knepley *offsets = prob->off; 2977194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2978194d53e6SMatthew G. Knepley } 2979194d53e6SMatthew G. Knepley 2980194d53e6SMatthew G. Knepley /*@ 2981194d53e6SMatthew G. Knepley PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point 2982194d53e6SMatthew G. Knepley 2983194d53e6SMatthew G. Knepley Not collective 2984194d53e6SMatthew G. Knepley 2985194d53e6SMatthew G. Knepley Input Parameter: 2986194d53e6SMatthew G. Knepley . prob - The PetscDS object 2987194d53e6SMatthew G. Knepley 2988194d53e6SMatthew G. Knepley Output Parameter: 2989194d53e6SMatthew G. Knepley . offsets - The offsets 2990194d53e6SMatthew G. Knepley 2991194d53e6SMatthew G. Knepley Level: beginner 2992194d53e6SMatthew G. Knepley 2993f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2994194d53e6SMatthew G. Knepley @*/ 2995194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[]) 2996194d53e6SMatthew G. Knepley { 2997194d53e6SMatthew G. Knepley PetscFunctionBegin; 2998194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2999194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 3000194d53e6SMatthew G. Knepley *offsets = prob->offDer; 3001194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 3002194d53e6SMatthew G. Knepley } 3003194d53e6SMatthew G. Knepley 300468c9edb9SMatthew G. Knepley /*@C 300568c9edb9SMatthew G. Knepley PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization 300668c9edb9SMatthew G. Knepley 300768c9edb9SMatthew G. Knepley Not collective 300868c9edb9SMatthew G. Knepley 300968c9edb9SMatthew G. Knepley Input Parameter: 301068c9edb9SMatthew G. Knepley . prob - The PetscDS object 301168c9edb9SMatthew G. Knepley 3012ef0bb6c7SMatthew G. Knepley Output Parameter: 3013ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field 301468c9edb9SMatthew G. Knepley 301568c9edb9SMatthew G. Knepley Level: intermediate 301668c9edb9SMatthew G. Knepley 3017f744cafaSSander Arens .seealso: PetscDSCreate() 301868c9edb9SMatthew G. Knepley @*/ 3019ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[]) 30202764a2aaSMatthew G. Knepley { 30212764a2aaSMatthew G. Knepley PetscErrorCode ierr; 30222764a2aaSMatthew G. Knepley 30232764a2aaSMatthew G. Knepley PetscFunctionBegin; 30242764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3025ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 2); 30262764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 3027ef0bb6c7SMatthew G. Knepley *T = prob->T; 30282764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30292764a2aaSMatthew G. Knepley } 30302764a2aaSMatthew G. Knepley 303168c9edb9SMatthew G. Knepley /*@C 30324d0b9603SSander Arens PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces 303368c9edb9SMatthew G. Knepley 303468c9edb9SMatthew G. Knepley Not collective 303568c9edb9SMatthew G. Knepley 303668c9edb9SMatthew G. Knepley Input Parameter: 303768c9edb9SMatthew G. Knepley . prob - The PetscDS object 303868c9edb9SMatthew G. Knepley 3039ef0bb6c7SMatthew G. Knepley Output Parameter: 304019815104SMartin Diehl . Tf - The basis function and derviative tabulation on each local face at quadrature points for each and field 304168c9edb9SMatthew G. Knepley 304268c9edb9SMatthew G. Knepley Level: intermediate 304368c9edb9SMatthew G. Knepley 304468c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate() 304568c9edb9SMatthew G. Knepley @*/ 3046ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[]) 30472764a2aaSMatthew G. Knepley { 30482764a2aaSMatthew G. Knepley PetscErrorCode ierr; 30492764a2aaSMatthew G. Knepley 30502764a2aaSMatthew G. Knepley PetscFunctionBegin; 30512764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3052ef0bb6c7SMatthew G. Knepley PetscValidPointer(Tf, 2); 30532764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 3054ef0bb6c7SMatthew G. Knepley *Tf = prob->Tf; 30552764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30562764a2aaSMatthew G. Knepley } 30572764a2aaSMatthew G. Knepley 30582764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) 30592764a2aaSMatthew G. Knepley { 30602764a2aaSMatthew G. Knepley PetscErrorCode ierr; 30612764a2aaSMatthew G. Knepley 30622764a2aaSMatthew G. Knepley PetscFunctionBegin; 30632764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30642764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 30652764a2aaSMatthew G. Knepley if (u) {PetscValidPointer(u, 2); *u = prob->u;} 30662764a2aaSMatthew G. Knepley if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;} 30672764a2aaSMatthew G. Knepley if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;} 30682764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30692764a2aaSMatthew G. Knepley } 30702764a2aaSMatthew G. Knepley 30712764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) 30722764a2aaSMatthew G. Knepley { 30732764a2aaSMatthew G. Knepley PetscErrorCode ierr; 30742764a2aaSMatthew G. Knepley 30752764a2aaSMatthew G. Knepley PetscFunctionBegin; 30762764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30772764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 30782764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;} 30792764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;} 30802764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;} 30812764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;} 30822764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;} 30832764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;} 30842764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30852764a2aaSMatthew G. Knepley } 30862764a2aaSMatthew G. Knepley 30874bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal) 30882764a2aaSMatthew G. Knepley { 30892764a2aaSMatthew G. Knepley PetscErrorCode ierr; 30902764a2aaSMatthew G. Knepley 30912764a2aaSMatthew G. Knepley PetscFunctionBegin; 30922764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30932764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 30942764a2aaSMatthew G. Knepley if (x) {PetscValidPointer(x, 2); *x = prob->x;} 30954bee2e38SMatthew G. Knepley if (basisReal) {PetscValidPointer(basisReal, 3); *basisReal = prob->basisReal;} 30967506b574SStefano Zampini if (basisDerReal) {PetscValidPointer(basisDerReal, 4); *basisDerReal = prob->basisDerReal;} 30977506b574SStefano Zampini if (testReal) {PetscValidPointer(testReal, 5); *testReal = prob->testReal;} 30987506b574SStefano Zampini if (testDerReal) {PetscValidPointer(testDerReal, 6); *testDerReal = prob->testDerReal;} 30992764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31002764a2aaSMatthew G. Knepley } 31012764a2aaSMatthew G. Knepley 310258ebd649SToby Isaac /*@C 310356cf3b9cSMatthew G. Knepley PetscDSAddBoundary - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performaed, using the kernels from PetscDSSetBdResidual(). 310458ebd649SToby Isaac 3105783e2ec8SMatthew G. Knepley Collective on ds 3106783e2ec8SMatthew G. Knepley 310758ebd649SToby Isaac Input Parameters: 310858ebd649SToby Isaac + ds - The PetscDS object 31092d47a189SJulian Andrej . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 311058ebd649SToby Isaac . name - The BC name 3111*45480ffeSMatthew G. Knepley . label - The label defining constrained points 3112*45480ffeSMatthew G. Knepley . Nv - The number of DMLabel values for constrained points 3113*45480ffeSMatthew G. Knepley . values - An array of label values for constrained points 311458ebd649SToby Isaac . field - The field to constrain 3115*45480ffeSMatthew G. Knepley . Nc - The number of constrained field components (0 will constrain all fields) 311658ebd649SToby Isaac . comps - An array of constrained component numbers 311758ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 311856cf3b9cSMatthew G. Knepley . bcFunc_t - A pointwise function giving the time derviative of the boundary values, or NULL 311958ebd649SToby Isaac - ctx - An optional user context for bcFunc 312058ebd649SToby Isaac 3121*45480ffeSMatthew G. Knepley Output Parameters: 3122*45480ffeSMatthew G. Knepley - bd - The boundary number 3123*45480ffeSMatthew G. Knepley 312458ebd649SToby Isaac Options Database Keys: 312558ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 312658ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 312758ebd649SToby Isaac 312856cf3b9cSMatthew G. Knepley Note: 312956cf3b9cSMatthew G. Knepley Both bcFunc abd bcFunc_t will depend on the boundary condition type. If the type if DM_BC_ESSENTIAL, Then the calling sequence is: 313056cf3b9cSMatthew G. Knepley 313156cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[]) 313256cf3b9cSMatthew G. Knepley 313356cf3b9cSMatthew G. Knepley If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is: 313456cf3b9cSMatthew G. Knepley 313556cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux, 313656cf3b9cSMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 313756cf3b9cSMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 313856cf3b9cSMatthew G. Knepley $ PetscReal time, const PetscReal x[], PetscScalar bcval[]) 313956cf3b9cSMatthew G. Knepley 314056cf3b9cSMatthew G. Knepley + dim - the spatial dimension 314156cf3b9cSMatthew G. Knepley . Nf - the number of fields 314256cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 314356cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 314456cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point 314556cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 314656cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 314756cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 314856cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 314956cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point 315056cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 315156cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 315256cf3b9cSMatthew G. Knepley . t - current time 315356cf3b9cSMatthew G. Knepley . x - coordinates of the current point 315456cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters 315556cf3b9cSMatthew G. Knepley . constants - constant parameters 315656cf3b9cSMatthew G. Knepley - bcval - output values at the current point 315756cf3b9cSMatthew G. Knepley 315858ebd649SToby Isaac Level: developer 315958ebd649SToby Isaac 3160*45480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundaryByName(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual() 316158ebd649SToby Isaac @*/ 3162*45480ffeSMatthew G. Knepley PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], DMLabel label, PetscInt Nv, const PetscInt values[], PetscInt field, PetscInt Nc, const PetscInt comps[], void (*bcFunc)(void), void (*bcFunc_t)(void), void *ctx, PetscInt *bd) 316358ebd649SToby Isaac { 3164*45480ffeSMatthew G. Knepley DSBoundary head = ds->boundary, b; 3165*45480ffeSMatthew G. Knepley PetscInt n = 0; 3166*45480ffeSMatthew G. Knepley const char *lname; 316758ebd649SToby Isaac PetscErrorCode ierr; 316858ebd649SToby Isaac 316958ebd649SToby Isaac PetscFunctionBegin; 317058ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3171783e2ec8SMatthew G. Knepley PetscValidLogicalCollectiveEnum(ds, type, 2); 3172*45480ffeSMatthew G. Knepley PetscValidCharPointer(name, 3); 3173*45480ffeSMatthew G. Knepley PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4); 3174*45480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nv, 5); 3175*45480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, field, 7); 3176*45480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nc, 8); 317758ebd649SToby Isaac ierr = PetscNew(&b);CHKERRQ(ierr); 317858ebd649SToby Isaac ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 3179*45480ffeSMatthew G. Knepley ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr); 3180*45480ffeSMatthew G. Knepley ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr); 3181*45480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr); 3182*45480ffeSMatthew G. Knepley if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);} 3183*45480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr); 3184*45480ffeSMatthew G. Knepley if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);} 3185*45480ffeSMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) label, &lname);CHKERRQ(ierr); 3186*45480ffeSMatthew G. Knepley ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr); 3187f971fd6bSMatthew G. Knepley b->type = type; 3188*45480ffeSMatthew G. Knepley b->label = label; 3189*45480ffeSMatthew G. Knepley b->Nv = Nv; 319058ebd649SToby Isaac b->field = field; 3191*45480ffeSMatthew G. Knepley b->Nc = Nc; 319258ebd649SToby Isaac b->func = bcFunc; 319356cf3b9cSMatthew G. Knepley b->func_t = bcFunc_t; 319458ebd649SToby Isaac b->ctx = ctx; 3195*45480ffeSMatthew G. Knepley b->next = NULL; 3196*45480ffeSMatthew G. Knepley /* Append to linked list so that we can preserve the order */ 3197*45480ffeSMatthew G. Knepley if (!head) ds->boundary = b; 3198*45480ffeSMatthew G. Knepley while (head) { 3199*45480ffeSMatthew G. Knepley if (!head->next) { 3200*45480ffeSMatthew G. Knepley head->next = b; 3201*45480ffeSMatthew G. Knepley head = b; 3202*45480ffeSMatthew G. Knepley } 3203*45480ffeSMatthew G. Knepley head = head->next; 3204*45480ffeSMatthew G. Knepley ++n; 3205*45480ffeSMatthew G. Knepley } 3206*45480ffeSMatthew G. Knepley if (bd) {PetscValidIntPointer(bd, 12); *bd = n;} 3207*45480ffeSMatthew G. Knepley PetscFunctionReturn(0); 3208*45480ffeSMatthew G. Knepley } 3209*45480ffeSMatthew G. Knepley 3210*45480ffeSMatthew G. Knepley /*@C 3211*45480ffeSMatthew G. Knepley PetscDSAddBoundaryByName - Add a boundary condition to the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performaed, using the kernels from PetscDSSetBdResidual(). 3212*45480ffeSMatthew G. Knepley 3213*45480ffeSMatthew G. Knepley Collective on ds 3214*45480ffeSMatthew G. Knepley 3215*45480ffeSMatthew G. Knepley Input Parameters: 3216*45480ffeSMatthew G. Knepley + ds - The PetscDS object 3217*45480ffeSMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 3218*45480ffeSMatthew G. Knepley . name - The BC name 3219*45480ffeSMatthew G. Knepley . lname - The naem of the label defining constrained points 3220*45480ffeSMatthew G. Knepley . Nv - The number of DMLabel values for constrained points 3221*45480ffeSMatthew G. Knepley . values - An array of label values for constrained points 3222*45480ffeSMatthew G. Knepley . field - The field to constrain 3223*45480ffeSMatthew G. Knepley . Nc - The number of constrained field components (0 will constrain all fields) 3224*45480ffeSMatthew G. Knepley . comps - An array of constrained component numbers 3225*45480ffeSMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 3226*45480ffeSMatthew G. Knepley . bcFunc_t - A pointwise function giving the time derviative of the boundary values, or NULL 3227*45480ffeSMatthew G. Knepley - ctx - An optional user context for bcFunc 3228*45480ffeSMatthew G. Knepley 3229*45480ffeSMatthew G. Knepley Output Parameters: 3230*45480ffeSMatthew G. Knepley - bd - The boundary number 3231*45480ffeSMatthew G. Knepley 3232*45480ffeSMatthew G. Knepley Options Database Keys: 3233*45480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids 3234*45480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components 3235*45480ffeSMatthew G. Knepley 3236*45480ffeSMatthew G. Knepley Note: 3237*45480ffeSMatthew G. Knepley This function should only be used with DMForest currently, since labels cannot be defined before the underlygin Plex is built. 3238*45480ffeSMatthew G. Knepley 3239*45480ffeSMatthew G. Knepley Both bcFunc abd bcFunc_t will depend on the boundary condition type. If the type if DM_BC_ESSENTIAL, Then the calling sequence is: 3240*45480ffeSMatthew G. Knepley 3241*45480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[]) 3242*45480ffeSMatthew G. Knepley 3243*45480ffeSMatthew G. Knepley If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is: 3244*45480ffeSMatthew G. Knepley 3245*45480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux, 3246*45480ffeSMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 3247*45480ffeSMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 3248*45480ffeSMatthew G. Knepley $ PetscReal time, const PetscReal x[], PetscScalar bcval[]) 3249*45480ffeSMatthew G. Knepley 3250*45480ffeSMatthew G. Knepley + dim - the spatial dimension 3251*45480ffeSMatthew G. Knepley . Nf - the number of fields 3252*45480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 3253*45480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 3254*45480ffeSMatthew G. Knepley . u - each field evaluated at the current point 3255*45480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 3256*45480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 3257*45480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 3258*45480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 3259*45480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point 3260*45480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 3261*45480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 3262*45480ffeSMatthew G. Knepley . t - current time 3263*45480ffeSMatthew G. Knepley . x - coordinates of the current point 3264*45480ffeSMatthew G. Knepley . numConstants - number of constant parameters 3265*45480ffeSMatthew G. Knepley . constants - constant parameters 3266*45480ffeSMatthew G. Knepley - bcval - output values at the current point 3267*45480ffeSMatthew G. Knepley 3268*45480ffeSMatthew G. Knepley Level: developer 3269*45480ffeSMatthew G. Knepley 3270*45480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual() 3271*45480ffeSMatthew G. Knepley @*/ 3272*45480ffeSMatthew G. Knepley PetscErrorCode PetscDSAddBoundaryByName(PetscDS ds, DMBoundaryConditionType type, const char name[], const char lname[], PetscInt Nv, const PetscInt values[], PetscInt field, PetscInt Nc, const PetscInt comps[], void (*bcFunc)(void), void (*bcFunc_t)(void), void *ctx, PetscInt *bd) 3273*45480ffeSMatthew G. Knepley { 3274*45480ffeSMatthew G. Knepley DSBoundary head = ds->boundary, b; 3275*45480ffeSMatthew G. Knepley PetscInt n = 0; 3276*45480ffeSMatthew G. Knepley PetscErrorCode ierr; 3277*45480ffeSMatthew G. Knepley 3278*45480ffeSMatthew G. Knepley PetscFunctionBegin; 3279*45480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3280*45480ffeSMatthew G. Knepley PetscValidLogicalCollectiveEnum(ds, type, 2); 3281*45480ffeSMatthew G. Knepley PetscValidCharPointer(name, 3); 3282*45480ffeSMatthew G. Knepley PetscValidCharPointer(lname, 4); 3283*45480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nv, 5); 3284*45480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, field, 7); 3285*45480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nc, 8); 3286*45480ffeSMatthew G. Knepley ierr = PetscNew(&b);CHKERRQ(ierr); 3287*45480ffeSMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 3288*45480ffeSMatthew G. Knepley ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr); 3289*45480ffeSMatthew G. Knepley ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr); 3290*45480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr); 3291*45480ffeSMatthew G. Knepley if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);} 3292*45480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr); 3293*45480ffeSMatthew G. Knepley if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);} 3294*45480ffeSMatthew G. Knepley ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr); 3295*45480ffeSMatthew G. Knepley b->type = type; 3296*45480ffeSMatthew G. Knepley b->label = NULL; 3297*45480ffeSMatthew G. Knepley b->Nv = Nv; 3298*45480ffeSMatthew G. Knepley b->field = field; 3299*45480ffeSMatthew G. Knepley b->Nc = Nc; 3300*45480ffeSMatthew G. Knepley b->func = bcFunc; 3301*45480ffeSMatthew G. Knepley b->func_t = bcFunc_t; 3302*45480ffeSMatthew G. Knepley b->ctx = ctx; 3303*45480ffeSMatthew G. Knepley b->next = NULL; 3304*45480ffeSMatthew G. Knepley /* Append to linked list so that we can preserve the order */ 3305*45480ffeSMatthew G. Knepley if (!head) ds->boundary = b; 3306*45480ffeSMatthew G. Knepley while (head) { 3307*45480ffeSMatthew G. Knepley if (!head->next) { 3308*45480ffeSMatthew G. Knepley head->next = b; 3309*45480ffeSMatthew G. Knepley head = b; 3310*45480ffeSMatthew G. Knepley } 3311*45480ffeSMatthew G. Knepley head = head->next; 3312*45480ffeSMatthew G. Knepley ++n; 3313*45480ffeSMatthew G. Knepley } 3314*45480ffeSMatthew G. Knepley if (bd) {PetscValidIntPointer(bd, 12); *bd = n;} 331558ebd649SToby Isaac PetscFunctionReturn(0); 331658ebd649SToby Isaac } 331758ebd649SToby Isaac 3318b67eacb3SMatthew G. Knepley /*@C 331956cf3b9cSMatthew G. Knepley PetscDSUpdateBoundary - Change a boundary condition for the model. The pointwise functions are used to provide boundary values for essential boundary conditions. In FEM, they are acting upon by dual basis functionals to generate FEM coefficients which are fixed. Natural boundary conditions signal to PETSc that boundary integrals should be performaed, using the kernels from PetscDSSetBdResidual(). 3320b67eacb3SMatthew G. Knepley 3321b67eacb3SMatthew G. Knepley Input Parameters: 3322b67eacb3SMatthew G. Knepley + ds - The PetscDS object 3323b67eacb3SMatthew G. Knepley . bd - The boundary condition number 3324b67eacb3SMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 3325b67eacb3SMatthew G. Knepley . name - The BC name 3326*45480ffeSMatthew G. Knepley . label - The label defining constrained points 3327*45480ffeSMatthew G. Knepley . Nv - The number of DMLabel ids for constrained points 3328*45480ffeSMatthew G. Knepley . values - An array of ids for constrained points 3329b67eacb3SMatthew G. Knepley . field - The field to constrain 3330*45480ffeSMatthew G. Knepley . Nc - The number of constrained field components 3331b67eacb3SMatthew G. Knepley . comps - An array of constrained component numbers 3332b67eacb3SMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 333356cf3b9cSMatthew G. Knepley . bcFunc_t - A pointwise function giving the time derviative of the boundary values, or NULL 3334b67eacb3SMatthew G. Knepley - ctx - An optional user context for bcFunc 3335b67eacb3SMatthew G. Knepley 333656cf3b9cSMatthew G. Knepley Note: 333756cf3b9cSMatthew G. Knepley The boundary condition number is the order in which it was registered. The user can get the number of boundary conditions from PetscDSGetNumBoundary(). See PetscDSAddBoundary() for a description of the calling sequences for the callbacks. 33389a6efb6aSMatthew G. Knepley 3339b67eacb3SMatthew G. Knepley Level: developer 3340b67eacb3SMatthew G. Knepley 33419a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary() 3342b67eacb3SMatthew G. Knepley @*/ 3343*45480ffeSMatthew G. Knepley PetscErrorCode PetscDSUpdateBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType type, const char name[], DMLabel label, PetscInt Nv, const PetscInt values[], PetscInt field, PetscInt Nc, const PetscInt comps[], void (*bcFunc)(void), void (*bcFunc_t)(void), void *ctx) 3344b67eacb3SMatthew G. Knepley { 3345b67eacb3SMatthew G. Knepley DSBoundary b = ds->boundary; 3346b67eacb3SMatthew G. Knepley PetscInt n = 0; 3347b67eacb3SMatthew G. Knepley PetscErrorCode ierr; 3348b67eacb3SMatthew G. Knepley 3349b67eacb3SMatthew G. Knepley PetscFunctionBegin; 3350b67eacb3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3351b67eacb3SMatthew G. Knepley while (b) { 3352b67eacb3SMatthew G. Knepley if (n == bd) break; 3353b67eacb3SMatthew G. Knepley b = b->next; 3354b67eacb3SMatthew G. Knepley ++n; 3355b67eacb3SMatthew G. Knepley } 3356b67eacb3SMatthew G. Knepley if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 3357b67eacb3SMatthew G. Knepley if (name) { 3358b67eacb3SMatthew G. Knepley ierr = PetscFree(b->name);CHKERRQ(ierr); 3359b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 3360b67eacb3SMatthew G. Knepley } 3361b67eacb3SMatthew G. Knepley b->type = type; 3362*45480ffeSMatthew G. Knepley if (label) { 3363*45480ffeSMatthew G. Knepley const char *name; 3364*45480ffeSMatthew G. Knepley 3365*45480ffeSMatthew G. Knepley b->label = label; 3366*45480ffeSMatthew G. Knepley ierr = PetscFree(b->lname);CHKERRQ(ierr); 3367*45480ffeSMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) label, &name);CHKERRQ(ierr); 3368*45480ffeSMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->lname);CHKERRQ(ierr); 3369*45480ffeSMatthew G. Knepley } 3370*45480ffeSMatthew G. Knepley if (Nv >= 0) { 3371*45480ffeSMatthew G. Knepley b->Nv = Nv; 3372*45480ffeSMatthew G. Knepley ierr = PetscFree(b->values);CHKERRQ(ierr); 3373*45480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr); 3374*45480ffeSMatthew G. Knepley if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);} 3375*45480ffeSMatthew G. Knepley } 3376*45480ffeSMatthew G. Knepley if (field >= 0) b->field = field; 3377*45480ffeSMatthew G. Knepley if (Nc >= 0) { 3378*45480ffeSMatthew G. Knepley b->Nc = Nc; 3379*45480ffeSMatthew G. Knepley ierr = PetscFree(b->comps);CHKERRQ(ierr); 3380*45480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr); 3381*45480ffeSMatthew G. Knepley if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);} 3382*45480ffeSMatthew G. Knepley } 3383*45480ffeSMatthew G. Knepley if (bcFunc) b->func = bcFunc; 3384*45480ffeSMatthew G. Knepley if (bcFunc_t) b->func_t = bcFunc_t; 3385*45480ffeSMatthew G. Knepley if (ctx) b->ctx = ctx; 3386b67eacb3SMatthew G. Knepley PetscFunctionReturn(0); 3387b67eacb3SMatthew G. Knepley } 3388b67eacb3SMatthew G. Knepley 338958ebd649SToby Isaac /*@ 339058ebd649SToby Isaac PetscDSGetNumBoundary - Get the number of registered BC 339158ebd649SToby Isaac 339258ebd649SToby Isaac Input Parameters: 339358ebd649SToby Isaac . ds - The PetscDS object 339458ebd649SToby Isaac 339558ebd649SToby Isaac Output Parameters: 339658ebd649SToby Isaac . numBd - The number of BC 339758ebd649SToby Isaac 339858ebd649SToby Isaac Level: intermediate 339958ebd649SToby Isaac 340058ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary() 340158ebd649SToby Isaac @*/ 340258ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd) 340358ebd649SToby Isaac { 340458ebd649SToby Isaac DSBoundary b = ds->boundary; 340558ebd649SToby Isaac 340658ebd649SToby Isaac PetscFunctionBegin; 340758ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 340858ebd649SToby Isaac PetscValidPointer(numBd, 2); 340958ebd649SToby Isaac *numBd = 0; 341058ebd649SToby Isaac while (b) {++(*numBd); b = b->next;} 341158ebd649SToby Isaac PetscFunctionReturn(0); 341258ebd649SToby Isaac } 341358ebd649SToby Isaac 341458ebd649SToby Isaac /*@C 34159a6efb6aSMatthew G. Knepley PetscDSGetBoundary - Gets a boundary condition to the model 341658ebd649SToby Isaac 341758ebd649SToby Isaac Input Parameters: 341858ebd649SToby Isaac + ds - The PetscDS object 341958ebd649SToby Isaac - bd - The BC number 342058ebd649SToby Isaac 342158ebd649SToby Isaac Output Parameters: 3422*45480ffeSMatthew G. Knepley + wf - The PetscWeakForm holding the pointwise functions 3423*45480ffeSMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 342458ebd649SToby Isaac . name - The BC name 3425*45480ffeSMatthew G. Knepley . label - The label defining constrained points 3426*45480ffeSMatthew G. Knepley . Nv - The number of DMLabel ids for constrained points 3427*45480ffeSMatthew G. Knepley . values - An array of ids for constrained points 342858ebd649SToby Isaac . field - The field to constrain 3429*45480ffeSMatthew G. Knepley . Nc - The number of constrained field components 343058ebd649SToby Isaac . comps - An array of constrained component numbers 343158ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 343256cf3b9cSMatthew G. Knepley . bcFunc_t - A pointwise function giving the time derviative of the boundary values 343358ebd649SToby Isaac - ctx - An optional user context for bcFunc 343458ebd649SToby Isaac 343558ebd649SToby Isaac Options Database Keys: 343658ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 343758ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 343858ebd649SToby Isaac 343958ebd649SToby Isaac Level: developer 344058ebd649SToby Isaac 344158ebd649SToby Isaac .seealso: PetscDSAddBoundary() 344258ebd649SToby Isaac @*/ 3443*45480ffeSMatthew G. Knepley PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, PetscWeakForm *wf, DMBoundaryConditionType *type, const char *name[], DMLabel *label, PetscInt *Nv, const PetscInt *values[], PetscInt *field, PetscInt *Nc, const PetscInt *comps[], void (**func)(void), void (**func_t)(void), void **ctx) 344458ebd649SToby Isaac { 344558ebd649SToby Isaac DSBoundary b = ds->boundary; 344658ebd649SToby Isaac PetscInt n = 0; 344758ebd649SToby Isaac 344858ebd649SToby Isaac PetscFunctionBegin; 344958ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 345058ebd649SToby Isaac while (b) { 345158ebd649SToby Isaac if (n == bd) break; 345258ebd649SToby Isaac b = b->next; 345358ebd649SToby Isaac ++n; 345458ebd649SToby Isaac } 345558ebd649SToby Isaac if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 3456*45480ffeSMatthew G. Knepley if (wf) { 3457*45480ffeSMatthew G. Knepley PetscValidPointer(wf, 3); 3458*45480ffeSMatthew G. Knepley *wf = b->wf; 3459*45480ffeSMatthew G. Knepley } 3460f971fd6bSMatthew G. Knepley if (type) { 3461*45480ffeSMatthew G. Knepley PetscValidPointer(type, 4); 3462f971fd6bSMatthew G. Knepley *type = b->type; 346358ebd649SToby Isaac } 346458ebd649SToby Isaac if (name) { 3465*45480ffeSMatthew G. Knepley PetscValidPointer(name, 5); 346658ebd649SToby Isaac *name = b->name; 346758ebd649SToby Isaac } 3468*45480ffeSMatthew G. Knepley if (label) { 3469*45480ffeSMatthew G. Knepley PetscValidPointer(label, 6); 3470*45480ffeSMatthew G. Knepley *label = b->label; 3471*45480ffeSMatthew G. Knepley } 3472*45480ffeSMatthew G. Knepley if (Nv) { 3473*45480ffeSMatthew G. Knepley PetscValidIntPointer(Nv, 7); 3474*45480ffeSMatthew G. Knepley *Nv = b->Nv; 3475*45480ffeSMatthew G. Knepley } 3476*45480ffeSMatthew G. Knepley if (values) { 3477*45480ffeSMatthew G. Knepley PetscValidPointer(values, 8); 3478*45480ffeSMatthew G. Knepley *values = b->values; 347958ebd649SToby Isaac } 348058ebd649SToby Isaac if (field) { 3481*45480ffeSMatthew G. Knepley PetscValidIntPointer(field, 9); 348258ebd649SToby Isaac *field = b->field; 348358ebd649SToby Isaac } 3484*45480ffeSMatthew G. Knepley if (Nc) { 3485*45480ffeSMatthew G. Knepley PetscValidIntPointer(Nc, 10); 3486*45480ffeSMatthew G. Knepley *Nc = b->Nc; 348758ebd649SToby Isaac } 348858ebd649SToby Isaac if (comps) { 3489*45480ffeSMatthew G. Knepley PetscValidPointer(comps, 11); 349058ebd649SToby Isaac *comps = b->comps; 349158ebd649SToby Isaac } 349258ebd649SToby Isaac if (func) { 3493*45480ffeSMatthew G. Knepley PetscValidPointer(func, 12); 349458ebd649SToby Isaac *func = b->func; 349558ebd649SToby Isaac } 349656cf3b9cSMatthew G. Knepley if (func_t) { 3497*45480ffeSMatthew G. Knepley PetscValidPointer(func_t, 13); 349856cf3b9cSMatthew G. Knepley *func_t = b->func_t; 349956cf3b9cSMatthew G. Knepley } 350058ebd649SToby Isaac if (ctx) { 3501*45480ffeSMatthew G. Knepley PetscValidPointer(ctx, 14); 350258ebd649SToby Isaac *ctx = b->ctx; 350358ebd649SToby Isaac } 350458ebd649SToby Isaac PetscFunctionReturn(0); 350558ebd649SToby Isaac } 350658ebd649SToby Isaac 3507*45480ffeSMatthew G. Knepley static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew) 3508*45480ffeSMatthew G. Knepley { 3509*45480ffeSMatthew G. Knepley PetscErrorCode ierr; 3510*45480ffeSMatthew G. Knepley 3511*45480ffeSMatthew G. Knepley PetscFunctionBegin; 3512*45480ffeSMatthew G. Knepley ierr = PetscNew(bNew);CHKERRQ(ierr); 3513*45480ffeSMatthew G. Knepley ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf);CHKERRQ(ierr); 3514*45480ffeSMatthew G. Knepley ierr = PetscWeakFormCopy(b->wf, (*bNew)->wf);CHKERRQ(ierr); 3515*45480ffeSMatthew G. Knepley ierr = PetscStrallocpy(b->name,(char **) &((*bNew)->name));CHKERRQ(ierr); 3516*45480ffeSMatthew G. Knepley ierr = PetscStrallocpy(b->lname,(char **) &((*bNew)->lname));CHKERRQ(ierr); 3517*45480ffeSMatthew G. Knepley (*bNew)->type = b->type; 3518*45480ffeSMatthew G. Knepley (*bNew)->label = b->label; 3519*45480ffeSMatthew G. Knepley (*bNew)->Nv = b->Nv; 3520*45480ffeSMatthew G. Knepley ierr = PetscMalloc1(b->Nv, &(*bNew)->values);CHKERRQ(ierr); 3521*45480ffeSMatthew G. Knepley ierr = PetscArraycpy((*bNew)->values, b->values, b->Nv);CHKERRQ(ierr); 3522*45480ffeSMatthew G. Knepley (*bNew)->field = b->field; 3523*45480ffeSMatthew G. Knepley (*bNew)->Nc = b->Nc; 3524*45480ffeSMatthew G. Knepley ierr = PetscMalloc1(b->Nc, &(*bNew)->comps);CHKERRQ(ierr); 3525*45480ffeSMatthew G. Knepley ierr = PetscArraycpy((*bNew)->comps, b->comps, b->Nc);CHKERRQ(ierr); 3526*45480ffeSMatthew G. Knepley (*bNew)->func = b->func; 3527*45480ffeSMatthew G. Knepley (*bNew)->func_t = b->func_t; 3528*45480ffeSMatthew G. Knepley (*bNew)->ctx = b->ctx; 3529*45480ffeSMatthew G. Knepley PetscFunctionReturn(0); 3530*45480ffeSMatthew G. Knepley } 3531*45480ffeSMatthew G. Knepley 35329252d075SMatthew G. Knepley /*@ 35339252d075SMatthew G. Knepley PetscDSCopyBoundary - Copy all boundary condition objects to the new problem 35349252d075SMatthew G. Knepley 35359252d075SMatthew G. Knepley Not collective 35369252d075SMatthew G. Knepley 353736951cb5SMatthew G. Knepley Input Parameters: 353836951cb5SMatthew G. Knepley + ds - The source PetscDS object 353936951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields 354036951cb5SMatthew G. Knepley - fields - The selected fields, or NULL for all fields 35419252d075SMatthew G. Knepley 35429252d075SMatthew G. Knepley Output Parameter: 354336951cb5SMatthew G. Knepley . newds - The target PetscDS, now with a copy of the boundary conditions 35449252d075SMatthew G. Knepley 35459252d075SMatthew G. Knepley Level: intermediate 35469252d075SMatthew G. Knepley 35479252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 35489252d075SMatthew G. Knepley @*/ 354936951cb5SMatthew G. Knepley PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds) 3550dff059c6SToby Isaac { 3551*45480ffeSMatthew G. Knepley DSBoundary b, *lastnext; 3552dff059c6SToby Isaac PetscErrorCode ierr; 3553dff059c6SToby Isaac 3554dff059c6SToby Isaac PetscFunctionBegin; 355536951cb5SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 355636951cb5SMatthew G. Knepley PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4); 355736951cb5SMatthew G. Knepley if (ds == newds) PetscFunctionReturn(0); 3558*45480ffeSMatthew G. Knepley ierr = PetscDSDestroyBoundary(newds);CHKERRQ(ierr); 355936951cb5SMatthew G. Knepley lastnext = &(newds->boundary); 356036951cb5SMatthew G. Knepley for (b = ds->boundary; b; b = b->next) { 3561dff059c6SToby Isaac DSBoundary bNew; 356236951cb5SMatthew G. Knepley PetscInt fieldNew = -1; 3563dff059c6SToby Isaac 356436951cb5SMatthew G. Knepley if (numFields > 0 && fields) { 356536951cb5SMatthew G. Knepley PetscInt f; 356636951cb5SMatthew G. Knepley 356736951cb5SMatthew G. Knepley for (f = 0; f < numFields; ++f) if (b->field == fields[f]) break; 356836951cb5SMatthew G. Knepley if (f == numFields) continue; 356936951cb5SMatthew G. Knepley fieldNew = f; 357036951cb5SMatthew G. Knepley } 3571*45480ffeSMatthew G. Knepley ierr = DSBoundaryDuplicate_Internal(b, &bNew);CHKERRQ(ierr); 357236951cb5SMatthew G. Knepley bNew->field = fieldNew < 0 ? b->field : fieldNew; 3573dff059c6SToby Isaac *lastnext = bNew; 3574dff059c6SToby Isaac lastnext = &(bNew->next); 3575dff059c6SToby Isaac } 3576dff059c6SToby Isaac PetscFunctionReturn(0); 3577dff059c6SToby Isaac } 3578dff059c6SToby Isaac 35796c1eb96dSMatthew G. Knepley /*@ 3580*45480ffeSMatthew G. Knepley PetscDSDestroyBoundary - Remove all DMBoundary objects from the PetscDS 3581*45480ffeSMatthew G. Knepley 3582*45480ffeSMatthew G. Knepley Not collective 3583*45480ffeSMatthew G. Knepley 3584*45480ffeSMatthew G. Knepley Input Parameter: 3585*45480ffeSMatthew G. Knepley . ds - The PetscDS object 3586*45480ffeSMatthew G. Knepley 3587*45480ffeSMatthew G. Knepley Level: intermediate 3588*45480ffeSMatthew G. Knepley 3589*45480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations() 3590*45480ffeSMatthew G. Knepley @*/ 3591*45480ffeSMatthew G. Knepley PetscErrorCode PetscDSDestroyBoundary(PetscDS ds) 3592*45480ffeSMatthew G. Knepley { 3593*45480ffeSMatthew G. Knepley DSBoundary next = ds->boundary; 3594*45480ffeSMatthew G. Knepley PetscErrorCode ierr; 3595*45480ffeSMatthew G. Knepley 3596*45480ffeSMatthew G. Knepley PetscFunctionBegin; 3597*45480ffeSMatthew G. Knepley while (next) { 3598*45480ffeSMatthew G. Knepley DSBoundary b = next; 3599*45480ffeSMatthew G. Knepley 3600*45480ffeSMatthew G. Knepley next = b->next; 3601*45480ffeSMatthew G. Knepley ierr = PetscWeakFormDestroy(&b->wf);CHKERRQ(ierr); 3602*45480ffeSMatthew G. Knepley ierr = PetscFree(b->name);CHKERRQ(ierr); 3603*45480ffeSMatthew G. Knepley ierr = PetscFree(b->lname);CHKERRQ(ierr); 3604*45480ffeSMatthew G. Knepley ierr = PetscFree(b->values);CHKERRQ(ierr); 3605*45480ffeSMatthew G. Knepley ierr = PetscFree(b->comps);CHKERRQ(ierr); 3606*45480ffeSMatthew G. Knepley ierr = PetscFree(b);CHKERRQ(ierr); 3607*45480ffeSMatthew G. Knepley } 3608*45480ffeSMatthew G. Knepley PetscFunctionReturn(0); 3609*45480ffeSMatthew G. Knepley } 3610*45480ffeSMatthew G. Knepley 3611*45480ffeSMatthew G. Knepley /*@ 36126c1eb96dSMatthew G. Knepley PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout 36136c1eb96dSMatthew G. Knepley 36146c1eb96dSMatthew G. Knepley Not collective 36156c1eb96dSMatthew G. Knepley 36166c1eb96dSMatthew G. Knepley Input Parameter: 36176c1eb96dSMatthew G. Knepley + prob - The PetscDS object 36186c1eb96dSMatthew G. Knepley . numFields - Number of new fields 36196c1eb96dSMatthew G. Knepley - fields - Old field number for each new field 36206c1eb96dSMatthew G. Knepley 36216c1eb96dSMatthew G. Knepley Output Parameter: 36226c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy 36236c1eb96dSMatthew G. Knepley 36246c1eb96dSMatthew G. Knepley Level: intermediate 36256c1eb96dSMatthew G. Knepley 36266c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectEquations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 36276c1eb96dSMatthew G. Knepley @*/ 36286c1eb96dSMatthew G. Knepley PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 36296c1eb96dSMatthew G. Knepley { 36306c1eb96dSMatthew G. Knepley PetscInt Nf, Nfn, fn; 36316c1eb96dSMatthew G. Knepley PetscErrorCode ierr; 36326c1eb96dSMatthew G. Knepley 36336c1eb96dSMatthew G. Knepley PetscFunctionBegin; 36346c1eb96dSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 36356c1eb96dSMatthew G. Knepley if (fields) PetscValidPointer(fields, 3); 36366c1eb96dSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 36376c1eb96dSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 36386c1eb96dSMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr); 3639*45480ffeSMatthew G. Knepley numFields = numFields < 0 ? Nf : numFields; 36406c1eb96dSMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 36416c1eb96dSMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 36426c1eb96dSMatthew G. Knepley PetscObject disc; 36436c1eb96dSMatthew G. Knepley 36446c1eb96dSMatthew G. Knepley if (f >= Nf) continue; 36456c1eb96dSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &disc);CHKERRQ(ierr); 36466c1eb96dSMatthew G. Knepley ierr = PetscDSSetDiscretization(newprob, fn, disc);CHKERRQ(ierr); 36476c1eb96dSMatthew G. Knepley } 36486c1eb96dSMatthew G. Knepley PetscFunctionReturn(0); 36496c1eb96dSMatthew G. Knepley } 36506c1eb96dSMatthew G. Knepley 36516c1eb96dSMatthew G. Knepley /*@ 36529252d075SMatthew G. Knepley PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout 36539252d075SMatthew G. Knepley 36549252d075SMatthew G. Knepley Not collective 36559252d075SMatthew G. Knepley 36569252d075SMatthew G. Knepley Input Parameter: 36579252d075SMatthew G. Knepley + prob - The PetscDS object 36589252d075SMatthew G. Knepley . numFields - Number of new fields 36599252d075SMatthew G. Knepley - fields - Old field number for each new field 36609252d075SMatthew G. Knepley 36619252d075SMatthew G. Knepley Output Parameter: 36629252d075SMatthew G. Knepley . newprob - The PetscDS copy 36639252d075SMatthew G. Knepley 36649252d075SMatthew G. Knepley Level: intermediate 36659252d075SMatthew G. Knepley 36666c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectDiscretizations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 36679252d075SMatthew G. Knepley @*/ 36689252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 36699252d075SMatthew G. Knepley { 36709252d075SMatthew G. Knepley PetscInt Nf, Nfn, fn, gn; 36719252d075SMatthew G. Knepley PetscErrorCode ierr; 36729252d075SMatthew G. Knepley 36739252d075SMatthew G. Knepley PetscFunctionBegin; 36749252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 36759252d075SMatthew G. Knepley if (fields) PetscValidPointer(fields, 3); 36769252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 36779252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 36789252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr); 36799252d075SMatthew 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); 36809252d075SMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 36819252d075SMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 36829252d075SMatthew G. Knepley PetscPointFunc obj; 36839252d075SMatthew G. Knepley PetscPointFunc f0, f1; 36849252d075SMatthew G. Knepley PetscBdPointFunc f0Bd, f1Bd; 36859252d075SMatthew G. Knepley PetscRiemannFunc r; 36869252d075SMatthew G. Knepley 3687c52f1e13SMatthew G. Knepley if (f >= Nf) continue; 36889252d075SMatthew G. Knepley ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr); 36899252d075SMatthew G. Knepley ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr); 36909252d075SMatthew G. Knepley ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr); 36919252d075SMatthew G. Knepley ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr); 36929252d075SMatthew G. Knepley ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr); 36939252d075SMatthew G. Knepley ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr); 36949252d075SMatthew G. Knepley ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr); 36959252d075SMatthew G. Knepley ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr); 36969252d075SMatthew G. Knepley for (gn = 0; gn < numFields; ++gn) { 36979252d075SMatthew G. Knepley const PetscInt g = fields ? fields[gn] : gn; 36989252d075SMatthew G. Knepley PetscPointJac g0, g1, g2, g3; 36999252d075SMatthew G. Knepley PetscPointJac g0p, g1p, g2p, g3p; 37009252d075SMatthew G. Knepley PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd; 37019252d075SMatthew G. Knepley 3702c52f1e13SMatthew G. Knepley if (g >= Nf) continue; 37039252d075SMatthew G. Knepley ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr); 37049252d075SMatthew G. Knepley ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr); 37059252d075SMatthew G. Knepley ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr); 37069252d075SMatthew G. Knepley ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr); 37076c1eb96dSMatthew G. Knepley ierr = PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr); 37089252d075SMatthew G. Knepley ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr); 37099252d075SMatthew G. Knepley } 37109252d075SMatthew G. Knepley } 37119252d075SMatthew G. Knepley PetscFunctionReturn(0); 37129252d075SMatthew G. Knepley } 37139252d075SMatthew G. Knepley 3714da51fcedSMatthew G. Knepley /*@ 3715da51fcedSMatthew G. Knepley PetscDSCopyEquations - Copy all pointwise function pointers to the new problem 3716da51fcedSMatthew G. Knepley 3717da51fcedSMatthew G. Knepley Not collective 3718da51fcedSMatthew G. Knepley 3719da51fcedSMatthew G. Knepley Input Parameter: 3720da51fcedSMatthew G. Knepley . prob - The PetscDS object 3721da51fcedSMatthew G. Knepley 3722da51fcedSMatthew G. Knepley Output Parameter: 3723da51fcedSMatthew G. Knepley . newprob - The PetscDS copy 3724da51fcedSMatthew G. Knepley 3725da51fcedSMatthew G. Knepley Level: intermediate 3726da51fcedSMatthew G. Knepley 37279252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 3728da51fcedSMatthew G. Knepley @*/ 3729da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob) 3730da51fcedSMatthew G. Knepley { 37319252d075SMatthew G. Knepley PetscInt Nf, Ng; 3732da51fcedSMatthew G. Knepley PetscErrorCode ierr; 3733da51fcedSMatthew G. Knepley 3734da51fcedSMatthew G. Knepley PetscFunctionBegin; 3735da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3736da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 3737da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3738da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr); 373913903a91SSatish Balay if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng); 37409252d075SMatthew G. Knepley ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr); 37419252d075SMatthew G. Knepley PetscFunctionReturn(0); 37429252d075SMatthew G. Knepley } 3743*45480ffeSMatthew G. Knepley 37449252d075SMatthew G. Knepley /*@ 37459252d075SMatthew G. Knepley PetscDSCopyConstants - Copy all constants to the new problem 3746da51fcedSMatthew G. Knepley 37479252d075SMatthew G. Knepley Not collective 37489252d075SMatthew G. Knepley 37499252d075SMatthew G. Knepley Input Parameter: 37509252d075SMatthew G. Knepley . prob - The PetscDS object 37519252d075SMatthew G. Knepley 37529252d075SMatthew G. Knepley Output Parameter: 37539252d075SMatthew G. Knepley . newprob - The PetscDS copy 37549252d075SMatthew G. Knepley 37559252d075SMatthew G. Knepley Level: intermediate 37569252d075SMatthew G. Knepley 37579252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 37589252d075SMatthew G. Knepley @*/ 37599252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob) 37609252d075SMatthew G. Knepley { 37619252d075SMatthew G. Knepley PetscInt Nc; 37629252d075SMatthew G. Knepley const PetscScalar *constants; 37639252d075SMatthew G. Knepley PetscErrorCode ierr; 37649252d075SMatthew G. Knepley 37659252d075SMatthew G. Knepley PetscFunctionBegin; 37669252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 37679252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 37689252d075SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr); 37699252d075SMatthew G. Knepley ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr); 3770da51fcedSMatthew G. Knepley PetscFunctionReturn(0); 3771da51fcedSMatthew G. Knepley } 3772da51fcedSMatthew G. Knepley 3773*45480ffeSMatthew G. Knepley /*@ 3774*45480ffeSMatthew G. Knepley PetscDSCopyExactSolutions - Copy all exact solutions to the new problem 3775*45480ffeSMatthew G. Knepley 3776*45480ffeSMatthew G. Knepley Not collective 3777*45480ffeSMatthew G. Knepley 3778*45480ffeSMatthew G. Knepley Input Parameter: 3779*45480ffeSMatthew G. Knepley . ds - The PetscDS object 3780*45480ffeSMatthew G. Knepley 3781*45480ffeSMatthew G. Knepley Output Parameter: 3782*45480ffeSMatthew G. Knepley . newds - The PetscDS copy 3783*45480ffeSMatthew G. Knepley 3784*45480ffeSMatthew G. Knepley Level: intermediate 3785*45480ffeSMatthew G. Knepley 3786*45480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 3787*45480ffeSMatthew G. Knepley @*/ 3788*45480ffeSMatthew G. Knepley PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds) 3789*45480ffeSMatthew G. Knepley { 3790*45480ffeSMatthew G. Knepley PetscSimplePointFunc sol; 3791*45480ffeSMatthew G. Knepley void *ctx; 3792*45480ffeSMatthew G. Knepley PetscInt Nf, f; 3793*45480ffeSMatthew G. Knepley PetscErrorCode ierr; 3794*45480ffeSMatthew G. Knepley 3795*45480ffeSMatthew G. Knepley PetscFunctionBegin; 3796*45480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3797*45480ffeSMatthew G. Knepley PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2); 3798*45480ffeSMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 3799*45480ffeSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3800*45480ffeSMatthew G. Knepley ierr = PetscDSGetExactSolution(ds, f, &sol, &ctx);CHKERRQ(ierr); 3801*45480ffeSMatthew G. Knepley ierr = PetscDSSetExactSolution(newds, f, sol, ctx);CHKERRQ(ierr); 3802*45480ffeSMatthew G. Knepley ierr = PetscDSGetExactSolutionTimeDerivative(ds, f, &sol, &ctx);CHKERRQ(ierr); 3803*45480ffeSMatthew G. Knepley ierr = PetscDSSetExactSolutionTimeDerivative(newds, f, sol, ctx);CHKERRQ(ierr); 3804*45480ffeSMatthew G. Knepley } 3805*45480ffeSMatthew G. Knepley PetscFunctionReturn(0); 3806*45480ffeSMatthew G. Knepley } 3807*45480ffeSMatthew G. Knepley 3808b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob) 3809b1353e8eSMatthew G. Knepley { 3810df3a45bdSMatthew G. Knepley PetscInt dim, Nf, f; 3811b1353e8eSMatthew G. Knepley PetscErrorCode ierr; 3812b1353e8eSMatthew G. Knepley 3813b1353e8eSMatthew G. Knepley PetscFunctionBegin; 3814b1353e8eSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3815b1353e8eSMatthew G. Knepley PetscValidPointer(subprob, 3); 3816b1353e8eSMatthew G. Knepley if (height == 0) {*subprob = prob; PetscFunctionReturn(0);} 3817b1353e8eSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3818df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 3819df3a45bdSMatthew 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); 3820df3a45bdSMatthew G. Knepley if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);} 3821df3a45bdSMatthew G. Knepley if (!prob->subprobs[height-1]) { 3822b1353e8eSMatthew G. Knepley PetscInt cdim; 3823b1353e8eSMatthew G. Knepley 3824df3a45bdSMatthew G. Knepley ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr); 3825b1353e8eSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr); 3826df3a45bdSMatthew G. Knepley ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr); 3827b1353e8eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3828b1353e8eSMatthew G. Knepley PetscFE subfe; 3829b1353e8eSMatthew G. Knepley PetscObject obj; 3830b1353e8eSMatthew G. Knepley PetscClassId id; 3831b1353e8eSMatthew G. Knepley 3832b1353e8eSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 3833b1353e8eSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3834b1353e8eSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);} 3835b1353e8eSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f); 3836df3a45bdSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr); 3837b1353e8eSMatthew G. Knepley } 3838b1353e8eSMatthew G. Knepley } 3839df3a45bdSMatthew G. Knepley *subprob = prob->subprobs[height-1]; 3840b1353e8eSMatthew G. Knepley PetscFunctionReturn(0); 3841b1353e8eSMatthew G. Knepley } 3842b1353e8eSMatthew G. Knepley 3843665f567fSMatthew G. Knepley PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype) 3844c7bd5f0bSMatthew G. Knepley { 3845c7bd5f0bSMatthew G. Knepley PetscObject obj; 3846c7bd5f0bSMatthew G. Knepley PetscClassId id; 3847c7bd5f0bSMatthew G. Knepley PetscInt Nf; 3848c7bd5f0bSMatthew G. Knepley PetscErrorCode ierr; 3849c7bd5f0bSMatthew G. Knepley 3850c7bd5f0bSMatthew G. Knepley PetscFunctionBegin; 3851c7bd5f0bSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3852665f567fSMatthew G. Knepley PetscValidPointer(disctype, 3); 3853665f567fSMatthew G. Knepley *disctype = PETSC_DISC_NONE; 3854c7bd5f0bSMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 3855c7bd5f0bSMatthew G. Knepley if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf); 3856c7bd5f0bSMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr); 3857665f567fSMatthew G. Knepley if (obj) { 3858c7bd5f0bSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3859665f567fSMatthew G. Knepley if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE; 3860665f567fSMatthew G. Knepley else *disctype = PETSC_DISC_FV; 3861665f567fSMatthew G. Knepley } 3862c7bd5f0bSMatthew G. Knepley PetscFunctionReturn(0); 3863c7bd5f0bSMatthew G. Knepley } 3864c7bd5f0bSMatthew G. Knepley 38656528b96dSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds) 38662764a2aaSMatthew G. Knepley { 3867931fb3b8SToby Isaac PetscErrorCode ierr; 3868931fb3b8SToby Isaac 38692764a2aaSMatthew G. Knepley PetscFunctionBegin; 38706528b96dSMatthew G. Knepley ierr = PetscFree(ds->data);CHKERRQ(ierr); 38712764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 38722764a2aaSMatthew G. Knepley } 38732764a2aaSMatthew G. Knepley 38746528b96dSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds) 38752764a2aaSMatthew G. Knepley { 38762764a2aaSMatthew G. Knepley PetscFunctionBegin; 38776528b96dSMatthew G. Knepley ds->ops->setfromoptions = NULL; 38786528b96dSMatthew G. Knepley ds->ops->setup = NULL; 38796528b96dSMatthew G. Knepley ds->ops->view = NULL; 38806528b96dSMatthew G. Knepley ds->ops->destroy = PetscDSDestroy_Basic; 38812764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 38822764a2aaSMatthew G. Knepley } 38832764a2aaSMatthew G. Knepley 38842764a2aaSMatthew G. Knepley /*MC 38852764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 38862764a2aaSMatthew G. Knepley 38872764a2aaSMatthew G. Knepley Level: intermediate 38882764a2aaSMatthew G. Knepley 38892764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType() 38902764a2aaSMatthew G. Knepley M*/ 38912764a2aaSMatthew G. Knepley 38926528b96dSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds) 38932764a2aaSMatthew G. Knepley { 38942764a2aaSMatthew G. Knepley PetscDS_Basic *b; 38952764a2aaSMatthew G. Knepley PetscErrorCode ierr; 38962764a2aaSMatthew G. Knepley 38972764a2aaSMatthew G. Knepley PetscFunctionBegin; 38986528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 38996528b96dSMatthew G. Knepley ierr = PetscNewLog(ds, &b);CHKERRQ(ierr); 39006528b96dSMatthew G. Knepley ds->data = b; 39012764a2aaSMatthew G. Knepley 39026528b96dSMatthew G. Knepley ierr = PetscDSInitialize_Basic(ds);CHKERRQ(ierr); 39032764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 39042764a2aaSMatthew G. Knepley } 3905