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 135*5fedec97SMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS ds, PetscViewer viewer) 1367d8a60eaSMatthew G. Knepley { 1377d8a60eaSMatthew G. Knepley PetscViewerFormat format; 13897b6e6e8SMatthew G. Knepley const PetscScalar *constants; 139*5fedec97SMatthew G. Knepley PetscInt Nf, numConstants, f; 1407d8a60eaSMatthew G. Knepley PetscErrorCode ierr; 1417d8a60eaSMatthew G. Knepley 1427d8a60eaSMatthew G. Knepley PetscFunctionBegin; 143*5fedec97SMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 1447d8a60eaSMatthew G. Knepley ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 145*5fedec97SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", Nf);CHKERRQ(ierr); 1467d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 147*5fedec97SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " cell total dim %D total comp %D\n", ds->totDim, ds->totComp);CHKERRQ(ierr); 148*5fedec97SMatthew G. Knepley if (ds->isCohesive) {ierr = PetscViewerASCIIPrintf(viewer, " cohesive cell\n");CHKERRQ(ierr);} 149*5fedec97SMatthew G. Knepley for (f = 0; f < Nf; ++f) { 15040967b3bSMatthew G. Knepley DSBoundary b; 1517d8a60eaSMatthew G. Knepley PetscObject obj; 1527d8a60eaSMatthew G. Knepley PetscClassId id; 153f35450b9SMatthew G. Knepley PetscQuadrature q; 1547d8a60eaSMatthew G. Knepley const char *name; 155f35450b9SMatthew G. Knepley PetscInt Nc, Nq, Nqc; 1567d8a60eaSMatthew G. Knepley 157*5fedec97SMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr); 1587d8a60eaSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 1597d8a60eaSMatthew G. Knepley ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr); 1607d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr); 1614727e194SMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 1627d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 1637d8a60eaSMatthew G. Knepley ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr); 164f35450b9SMatthew G. Knepley ierr = PetscFEGetQuadrature((PetscFE) obj, &q);CHKERRQ(ierr); 1657d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr); 1667d8a60eaSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 1677d8a60eaSMatthew G. Knepley ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr); 168f35450b9SMatthew G. Knepley ierr = PetscFVGetQuadrature((PetscFV) obj, &q);CHKERRQ(ierr); 1697d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr); 1707d8a60eaSMatthew G. Knepley } 171*5fedec97SMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f); 17297b6e6e8SMatthew G. Knepley if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, " %D components", Nc);CHKERRQ(ierr);} 17397b6e6e8SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " %D component ", Nc);CHKERRQ(ierr);} 174*5fedec97SMatthew G. Knepley if (ds->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);} 175249df284SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);} 1763e60c2a6SMatthew G. Knepley if (q) { 177f35450b9SMatthew G. Knepley ierr = PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL);CHKERRQ(ierr); 178f35450b9SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " (Nq %D Nqc %D)", Nq, Nqc);CHKERRQ(ierr); 1793e60c2a6SMatthew G. Knepley } 180*5fedec97SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " %D-jet", ds->jetDegree[f]);CHKERRQ(ierr); 1817d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 1824727e194SMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 1835d160056SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 1847d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);} 1857d8a60eaSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);} 1865d160056SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 18740967b3bSMatthew G. Knepley 188*5fedec97SMatthew G. Knepley for (b = ds->boundary; b; b = b->next) { 18906ad1575SMatthew G. Knepley char *name; 19040967b3bSMatthew G. Knepley PetscInt c, i; 19140967b3bSMatthew G. Knepley 19240967b3bSMatthew G. Knepley if (b->field != f) continue; 19340967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 19445480ffeSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Boundary %s (%s) %s\n", b->name, b->lname, DMBoundaryConditionTypes[b->type]);CHKERRQ(ierr); 19545480ffeSMatthew G. Knepley if (!b->Nc) { 19640967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " all components\n");CHKERRQ(ierr); 19740967b3bSMatthew G. Knepley } else { 19840967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " components: ");CHKERRQ(ierr); 19940967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 20045480ffeSMatthew G. Knepley for (c = 0; c < b->Nc; ++c) { 20140967b3bSMatthew G. Knepley if (c > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 20240967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->comps[c]);CHKERRQ(ierr); 20340967b3bSMatthew G. Knepley } 20440967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 20540967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 20640967b3bSMatthew G. Knepley } 20745480ffeSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " values: ");CHKERRQ(ierr); 20840967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_FALSE);CHKERRQ(ierr); 20945480ffeSMatthew G. Knepley for (i = 0; i < b->Nv; ++i) { 21040967b3bSMatthew G. Knepley if (i > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} 21145480ffeSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D", b->values[i]);CHKERRQ(ierr); 21240967b3bSMatthew G. Knepley } 21340967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 21440967b3bSMatthew G. Knepley ierr = PetscViewerASCIIUseTabs(viewer, PETSC_TRUE);CHKERRQ(ierr); 2158e0d8d9cSMatthew G. Knepley if (b->func) { 2168e0d8d9cSMatthew G. Knepley ierr = PetscDLAddr(b->func, &name);CHKERRQ(ierr); 2178e0d8d9cSMatthew G. Knepley if (name) {ierr = PetscViewerASCIIPrintf(viewer, " func: %s\n", name);CHKERRQ(ierr);} 2188e0d8d9cSMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " func: %p\n", b->func);CHKERRQ(ierr);} 21906ad1575SMatthew G. Knepley ierr = PetscFree(name);CHKERRQ(ierr); 2208e0d8d9cSMatthew G. Knepley } 2218e0d8d9cSMatthew G. Knepley if (b->func_t) { 2228e0d8d9cSMatthew G. Knepley ierr = PetscDLAddr(b->func_t, &name);CHKERRQ(ierr); 2232e144d55SMatthew G. Knepley if (name) {ierr = PetscViewerASCIIPrintf(viewer, " func_t: %s\n", name);CHKERRQ(ierr);} 2242e144d55SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " func_t: %p\n", b->func_t);CHKERRQ(ierr);} 22506ad1575SMatthew G. Knepley ierr = PetscFree(name);CHKERRQ(ierr); 2268e0d8d9cSMatthew G. Knepley } 22745480ffeSMatthew G. Knepley ierr = PetscWeakFormView(b->wf, viewer);CHKERRQ(ierr); 22840967b3bSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 22940967b3bSMatthew G. Knepley } 2307d8a60eaSMatthew G. Knepley } 231*5fedec97SMatthew G. Knepley ierr = PetscDSGetConstants(ds, &numConstants, &constants);CHKERRQ(ierr); 23297b6e6e8SMatthew G. Knepley if (numConstants) { 23397b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr); 23497b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 23557fc01e9SMatthew G. Knepley for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);} 23697b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 23797b6e6e8SMatthew G. Knepley } 238*5fedec97SMatthew G. Knepley ierr = PetscWeakFormView(ds->wf, viewer);CHKERRQ(ierr); 2397d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 2407d8a60eaSMatthew G. Knepley PetscFunctionReturn(0); 2417d8a60eaSMatthew G. Knepley } 2427d8a60eaSMatthew G. Knepley 2432764a2aaSMatthew G. Knepley /*@C 244fe2efc57SMark PetscDSViewFromOptions - View from Options 245fe2efc57SMark 246fe2efc57SMark Collective on PetscDS 247fe2efc57SMark 248fe2efc57SMark Input Parameters: 249fe2efc57SMark + A - the PetscDS object 250736c3998SJose E. Roman . obj - Optional object 251736c3998SJose E. Roman - name - command line option 252fe2efc57SMark 253fe2efc57SMark Level: intermediate 254fe2efc57SMark .seealso: PetscDS, PetscDSView, PetscObjectViewFromOptions(), PetscDSCreate() 255fe2efc57SMark @*/ 256fe2efc57SMark PetscErrorCode PetscDSViewFromOptions(PetscDS A,PetscObject obj,const char name[]) 257fe2efc57SMark { 258fe2efc57SMark PetscErrorCode ierr; 259fe2efc57SMark 260fe2efc57SMark PetscFunctionBegin; 261fe2efc57SMark PetscValidHeaderSpecific(A,PETSCDS_CLASSID,1); 262fe2efc57SMark ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr); 263fe2efc57SMark PetscFunctionReturn(0); 264fe2efc57SMark } 265fe2efc57SMark 266fe2efc57SMark /*@C 2672764a2aaSMatthew G. Knepley PetscDSView - Views a PetscDS 2682764a2aaSMatthew G. Knepley 269d083f849SBarry Smith Collective on prob 2702764a2aaSMatthew G. Knepley 271d8d19677SJose E. Roman Input Parameters: 2722764a2aaSMatthew G. Knepley + prob - the PetscDS object to view 2732764a2aaSMatthew G. Knepley - v - the viewer 2742764a2aaSMatthew G. Knepley 2752764a2aaSMatthew G. Knepley Level: developer 2762764a2aaSMatthew G. Knepley 2772764a2aaSMatthew G. Knepley .seealso PetscDSDestroy() 2782764a2aaSMatthew G. Knepley @*/ 2792764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v) 2802764a2aaSMatthew G. Knepley { 2817d8a60eaSMatthew G. Knepley PetscBool iascii; 2822764a2aaSMatthew G. Knepley PetscErrorCode ierr; 2832764a2aaSMatthew G. Knepley 2842764a2aaSMatthew G. Knepley PetscFunctionBegin; 2852764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2862764a2aaSMatthew G. Knepley if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);} 2877d8a60eaSMatthew G. Knepley else {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);} 2887d8a60eaSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 2897d8a60eaSMatthew G. Knepley if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);} 2902764a2aaSMatthew G. Knepley if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);} 2912764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 2922764a2aaSMatthew G. Knepley } 2932764a2aaSMatthew G. Knepley 2942764a2aaSMatthew G. Knepley /*@ 2952764a2aaSMatthew G. Knepley PetscDSSetFromOptions - sets parameters in a PetscDS from the options database 2962764a2aaSMatthew G. Knepley 297d083f849SBarry Smith Collective on prob 2982764a2aaSMatthew G. Knepley 2992764a2aaSMatthew G. Knepley Input Parameter: 3002764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for 3012764a2aaSMatthew G. Knepley 3022764a2aaSMatthew G. Knepley Options Database: 30355c1f793SMatthew G. Knepley + -petscds_type <type> : Set the DS type 30455c1f793SMatthew G. Knepley . -petscds_view <view opt> : View the DS 30555c1f793SMatthew G. Knepley . -petscds_jac_pre : Turn formation of a separate Jacobian preconditioner on and off 30655c1f793SMatthew G. Knepley . -bc_<name> <ids> : Specify a list of label ids for a boundary condition 30755c1f793SMatthew G. Knepley - -bc_<name>_comp <comps> : Specify a list of field components to constrain for a boundary condition 3082764a2aaSMatthew G. Knepley 3092764a2aaSMatthew G. Knepley Level: developer 3102764a2aaSMatthew G. Knepley 3112764a2aaSMatthew G. Knepley .seealso PetscDSView() 3122764a2aaSMatthew G. Knepley @*/ 3132764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob) 3142764a2aaSMatthew G. Knepley { 315f1fd5e65SToby Isaac DSBoundary b; 3162764a2aaSMatthew G. Knepley const char *defaultType; 3172764a2aaSMatthew G. Knepley char name[256]; 3182764a2aaSMatthew G. Knepley PetscBool flg; 3192764a2aaSMatthew G. Knepley PetscErrorCode ierr; 3202764a2aaSMatthew G. Knepley 3212764a2aaSMatthew G. Knepley PetscFunctionBegin; 3222764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3232764a2aaSMatthew G. Knepley if (!((PetscObject) prob)->type_name) { 3242764a2aaSMatthew G. Knepley defaultType = PETSCDSBASIC; 3252764a2aaSMatthew G. Knepley } else { 3262764a2aaSMatthew G. Knepley defaultType = ((PetscObject) prob)->type_name; 3272764a2aaSMatthew G. Knepley } 3280f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 3292764a2aaSMatthew G. Knepley 3302764a2aaSMatthew G. Knepley ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr); 331f1fd5e65SToby Isaac for (b = prob->boundary; b; b = b->next) { 332f1fd5e65SToby Isaac char optname[1024]; 333f1fd5e65SToby Isaac PetscInt ids[1024], len = 1024; 334f1fd5e65SToby Isaac PetscBool flg; 335f1fd5e65SToby Isaac 336f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr); 337f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 338f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr); 339f1fd5e65SToby Isaac if (flg) { 34045480ffeSMatthew G. Knepley b->Nv = len; 34145480ffeSMatthew G. Knepley ierr = PetscFree(b->values);CHKERRQ(ierr); 34245480ffeSMatthew G. Knepley ierr = PetscMalloc1(len, &b->values);CHKERRQ(ierr); 34345480ffeSMatthew G. Knepley ierr = PetscArraycpy(b->values, ids, len);CHKERRQ(ierr); 34445480ffeSMatthew G. Knepley ierr = PetscWeakFormRewriteKeys(b->wf, b->label, len, b->values);CHKERRQ(ierr); 345f1fd5e65SToby Isaac } 346e7b0402cSSander Arens len = 1024; 347f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr); 348f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 349f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr); 350f1fd5e65SToby Isaac if (flg) { 35145480ffeSMatthew G. Knepley b->Nc = len; 352f1fd5e65SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 353f1fd5e65SToby Isaac ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr); 354580bdb30SBarry Smith ierr = PetscArraycpy(b->comps, ids, len);CHKERRQ(ierr); 355f1fd5e65SToby Isaac } 356f1fd5e65SToby Isaac } 3572764a2aaSMatthew G. Knepley ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr); 3582764a2aaSMatthew G. Knepley if (flg) { 3592764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, name);CHKERRQ(ierr); 3602764a2aaSMatthew G. Knepley } else if (!((PetscObject) prob)->type_name) { 3612764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr); 3622764a2aaSMatthew G. Knepley } 36355c1f793SMatthew G. Knepley ierr = PetscOptionsBool("-petscds_jac_pre", "Discrete System", "PetscDSUseJacobianPreconditioner", prob->useJacPre, &prob->useJacPre, &flg);CHKERRQ(ierr); 3642764a2aaSMatthew G. Knepley if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);} 3652764a2aaSMatthew G. Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 3660633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr); 3672764a2aaSMatthew G. Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 3685d160056SMatthew G. Knepley if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);} 3692764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 3702764a2aaSMatthew G. Knepley } 3712764a2aaSMatthew G. Knepley 3722764a2aaSMatthew G. Knepley /*@C 3732764a2aaSMatthew G. Knepley PetscDSSetUp - Construct data structures for the PetscDS 3742764a2aaSMatthew G. Knepley 375d083f849SBarry Smith Collective on prob 3762764a2aaSMatthew G. Knepley 3772764a2aaSMatthew G. Knepley Input Parameter: 3782764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup 3792764a2aaSMatthew G. Knepley 3802764a2aaSMatthew G. Knepley Level: developer 3812764a2aaSMatthew G. Knepley 3822764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy() 3832764a2aaSMatthew G. Knepley @*/ 3842764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob) 3852764a2aaSMatthew G. Knepley { 3862764a2aaSMatthew G. Knepley const PetscInt Nf = prob->Nf; 387f9244615SMatthew G. Knepley PetscBool hasH = PETSC_FALSE; 3884bee2e38SMatthew G. Knepley PetscInt dim, dimEmbed, NbMax = 0, NcMax = 0, NqMax = 0, NsMax = 1, f; 3892764a2aaSMatthew G. Knepley PetscErrorCode ierr; 3902764a2aaSMatthew G. Knepley 3912764a2aaSMatthew G. Knepley PetscFunctionBegin; 3922764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3932764a2aaSMatthew G. Knepley if (prob->setup) PetscFunctionReturn(0); 3942764a2aaSMatthew G. Knepley /* Calculate sizes */ 3952764a2aaSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 396d1506c7cSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr); 397f744cafaSSander Arens prob->totDim = prob->totComp = 0; 39847e57110SSander Arens ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr); 399f744cafaSSander Arens ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr); 400ef0bb6c7SMatthew G. Knepley ierr = PetscMalloc2(Nf,&prob->T,Nf,&prob->Tf);CHKERRQ(ierr); 4012764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 4029de99aefSMatthew G. Knepley PetscObject obj; 4039de99aefSMatthew G. Knepley PetscClassId id; 404665f567fSMatthew G. Knepley PetscQuadrature q = NULL; 4059de99aefSMatthew G. Knepley PetscInt Nq = 0, Nb, Nc; 4062764a2aaSMatthew G. Knepley 4079de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 408f9244615SMatthew G. Knepley if (prob->jetDegree[f] > 1) hasH = PETSC_TRUE; 409665f567fSMatthew G. Knepley if (!obj) { 410665f567fSMatthew G. Knepley /* Empty mesh */ 411665f567fSMatthew G. Knepley Nb = Nc = 0; 412665f567fSMatthew G. Knepley prob->T[f] = prob->Tf[f] = NULL; 413665f567fSMatthew G. Knepley } else { 4149de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 4159de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 4169de99aefSMatthew G. Knepley PetscFE fe = (PetscFE) obj; 4179de99aefSMatthew G. Knepley 4182764a2aaSMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr); 4192764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 4202764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 421f9244615SMatthew G. Knepley ierr = PetscFEGetCellTabulation(fe, prob->jetDegree[f], &prob->T[f]);CHKERRQ(ierr); 422f9244615SMatthew G. Knepley ierr = PetscFEGetFaceTabulation(fe, prob->jetDegree[f], &prob->Tf[f]);CHKERRQ(ierr); 4239de99aefSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 4249de99aefSMatthew G. Knepley PetscFV fv = (PetscFV) obj; 4259de99aefSMatthew G. Knepley 4269de99aefSMatthew G. Knepley ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr); 4279de99aefSMatthew G. Knepley ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr); 4289c3cf19fSMatthew G. Knepley Nb = Nc; 429ef0bb6c7SMatthew G. Knepley ierr = PetscFVGetCellTabulation(fv, &prob->T[f]);CHKERRQ(ierr); 4304d0b9603SSander Arens /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */ 431abac5ca0SMatthew G. Knepley } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f); 432665f567fSMatthew G. Knepley } 43347e57110SSander Arens prob->Nc[f] = Nc; 43447e57110SSander Arens prob->Nb[f] = Nb; 435194d53e6SMatthew G. Knepley prob->off[f+1] = Nc + prob->off[f]; 436194d53e6SMatthew G. Knepley prob->offDer[f+1] = Nc*dim + prob->offDer[f]; 437a6b92713SMatthew G. Knepley if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);} 4382764a2aaSMatthew G. Knepley NqMax = PetscMax(NqMax, Nq); 4394bee2e38SMatthew G. Knepley NbMax = PetscMax(NbMax, Nb); 4402764a2aaSMatthew G. Knepley NcMax = PetscMax(NcMax, Nc); 4419c3cf19fSMatthew G. Knepley prob->totDim += Nb; 4422764a2aaSMatthew G. Knepley prob->totComp += Nc; 443*5fedec97SMatthew G. Knepley /* There are two faces for all fields on a cohesive cell, except for cohesive fields */ 444*5fedec97SMatthew G. Knepley if (prob->isCohesive && !prob->cohesive[f]) prob->totDim += Nb; 4452764a2aaSMatthew G. Knepley } 4462764a2aaSMatthew G. Knepley /* Allocate works space */ 447*5fedec97SMatthew G. Knepley NsMax = 2; /* A non-cohesive discretizations can be used on a cohesive cell, so we need this extra workspace for all DS */ 448f9244615SMatthew 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); 4494bee2e38SMatthew 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); 45027f02ce8SMatthew G. Knepley ierr = PetscMalloc6(NsMax*NqMax*NcMax,&prob->f0,NsMax*NqMax*NcMax*dimEmbed,&prob->f1, 45127f02ce8SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax,&prob->g0,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g1, 45227f02ce8SMatthew G. Knepley NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed,&prob->g2,NsMax*NsMax*NqMax*NcMax*NcMax*dimEmbed*dimEmbed,&prob->g3);CHKERRQ(ierr); 4532764a2aaSMatthew G. Knepley if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);} 4542764a2aaSMatthew G. Knepley prob->setup = PETSC_TRUE; 4552764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4562764a2aaSMatthew G. Knepley } 4572764a2aaSMatthew G. Knepley 4582764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob) 4592764a2aaSMatthew G. Knepley { 4602764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4612764a2aaSMatthew G. Knepley 4622764a2aaSMatthew G. Knepley PetscFunctionBegin; 46347e57110SSander Arens ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr); 464f744cafaSSander Arens ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr); 465ef0bb6c7SMatthew G. Knepley ierr = PetscFree2(prob->T,prob->Tf);CHKERRQ(ierr); 4664bee2e38SMatthew G. Knepley ierr = PetscFree3(prob->u,prob->u_t,prob->u_x);CHKERRQ(ierr); 4674bee2e38SMatthew G. Knepley ierr = PetscFree5(prob->x,prob->basisReal, prob->basisDerReal,prob->testReal,prob->testDerReal);CHKERRQ(ierr); 4682764a2aaSMatthew G. Knepley ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr); 4692764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4702764a2aaSMatthew G. Knepley } 4712764a2aaSMatthew G. Knepley 4722764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew) 4732764a2aaSMatthew G. Knepley { 474f744cafaSSander Arens PetscObject *tmpd; 47534aa8a36SMatthew G. Knepley PetscBool *tmpi; 476f9244615SMatthew G. Knepley PetscInt *tmpk; 477*5fedec97SMatthew G. Knepley PetscBool *tmpc; 4786528b96dSMatthew G. Knepley PetscPointFunc *tmpup; 479f2cacb80SMatthew G. Knepley PetscSimplePointFunc *tmpexactSol, *tmpexactSol_t; 480f2cacb80SMatthew G. Knepley void **tmpexactCtx, **tmpexactCtx_t; 4810c2f2876SMatthew G. Knepley void **tmpctx; 48234aa8a36SMatthew G. Knepley PetscInt Nf = prob->Nf, f; 4832764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4842764a2aaSMatthew G. Knepley 4852764a2aaSMatthew G. Knepley PetscFunctionBegin; 4862764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 4872764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 4882764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr); 489*5fedec97SMatthew G. Knepley ierr = PetscMalloc4(NfNew, &tmpd, NfNew, &tmpi, NfNew, &tmpc, NfNew, &tmpk);CHKERRQ(ierr); 490*5fedec97SMatthew G. Knepley for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; tmpc[f] = prob->cohesive[f]; tmpk[f] = prob->jetDegree[f];} 491*5fedec97SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE, tmpc[f] = PETSC_FALSE; tmpk[f] = 1;} 492*5fedec97SMatthew G. Knepley ierr = PetscFree4(prob->disc, prob->implicit, prob->cohesive, prob->jetDegree);CHKERRQ(ierr); 4936528b96dSMatthew G. Knepley ierr = PetscWeakFormSetNumFields(prob->wf, NfNew);CHKERRQ(ierr); 4942764a2aaSMatthew G. Knepley prob->Nf = NfNew; 4952764a2aaSMatthew G. Knepley prob->disc = tmpd; 496249df284SMatthew G. Knepley prob->implicit = tmpi; 497*5fedec97SMatthew G. Knepley prob->cohesive = tmpc; 498f9244615SMatthew G. Knepley prob->jetDegree = tmpk; 4996528b96dSMatthew G. Knepley ierr = PetscCalloc2(NfNew, &tmpup, NfNew, &tmpctx);CHKERRQ(ierr); 50032d2bbc9SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f]; 5010c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f]; 50232d2bbc9SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL; 5030c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL; 5046528b96dSMatthew G. Knepley ierr = PetscFree2(prob->update, prob->ctx);CHKERRQ(ierr); 50532d2bbc9SMatthew G. Knepley prob->update = tmpup; 5060c2f2876SMatthew G. Knepley prob->ctx = tmpctx; 5076528b96dSMatthew G. Knepley ierr = PetscCalloc4(NfNew, &tmpexactSol, NfNew, &tmpexactCtx, NfNew, &tmpexactSol_t, NfNew, &tmpexactCtx_t);CHKERRQ(ierr); 508c371a6d1SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f]; 50995cbbfd3SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx[f] = prob->exactCtx[f]; 510f2cacb80SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol_t[f] = prob->exactSol_t[f]; 511f2cacb80SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactCtx_t[f] = prob->exactCtx_t[f]; 512c371a6d1SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL; 51395cbbfd3SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx[f] = NULL; 514f2cacb80SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol_t[f] = NULL; 515f2cacb80SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactCtx_t[f] = NULL; 5166528b96dSMatthew G. Knepley ierr = PetscFree4(prob->exactSol, prob->exactCtx, prob->exactSol_t, prob->exactCtx_t);CHKERRQ(ierr); 517c371a6d1SMatthew G. Knepley prob->exactSol = tmpexactSol; 51895cbbfd3SMatthew G. Knepley prob->exactCtx = tmpexactCtx; 519f2cacb80SMatthew G. Knepley prob->exactSol_t = tmpexactSol_t; 520f2cacb80SMatthew G. Knepley prob->exactCtx_t = tmpexactCtx_t; 5212764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5222764a2aaSMatthew G. Knepley } 5232764a2aaSMatthew G. Knepley 5242764a2aaSMatthew G. Knepley /*@ 5252764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 5262764a2aaSMatthew G. Knepley 527d083f849SBarry Smith Collective on prob 5282764a2aaSMatthew G. Knepley 5292764a2aaSMatthew G. Knepley Input Parameter: 5302764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 5312764a2aaSMatthew G. Knepley 5322764a2aaSMatthew G. Knepley Level: developer 5332764a2aaSMatthew G. Knepley 5342764a2aaSMatthew G. Knepley .seealso PetscDSView() 5352764a2aaSMatthew G. Knepley @*/ 5366528b96dSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *ds) 5372764a2aaSMatthew G. Knepley { 5382764a2aaSMatthew G. Knepley PetscInt f; 5392764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5402764a2aaSMatthew G. Knepley 5412764a2aaSMatthew G. Knepley PetscFunctionBegin; 5426528b96dSMatthew G. Knepley if (!*ds) PetscFunctionReturn(0); 5436528b96dSMatthew G. Knepley PetscValidHeaderSpecific((*ds), PETSCDS_CLASSID, 1); 5442764a2aaSMatthew G. Knepley 5456528b96dSMatthew G. Knepley if (--((PetscObject)(*ds))->refct > 0) {*ds = NULL; PetscFunctionReturn(0);} 5466528b96dSMatthew G. Knepley ((PetscObject) (*ds))->refct = 0; 5476528b96dSMatthew G. Knepley if ((*ds)->subprobs) { 548df3a45bdSMatthew G. Knepley PetscInt dim, d; 549df3a45bdSMatthew G. Knepley 5506528b96dSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(*ds, &dim);CHKERRQ(ierr); 5516528b96dSMatthew G. Knepley for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*ds)->subprobs[d]);CHKERRQ(ierr);} 552df3a45bdSMatthew G. Knepley } 5536528b96dSMatthew G. Knepley ierr = PetscFree((*ds)->subprobs);CHKERRQ(ierr); 5546528b96dSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(*ds);CHKERRQ(ierr); 5556528b96dSMatthew G. Knepley for (f = 0; f < (*ds)->Nf; ++f) { 5566528b96dSMatthew G. Knepley ierr = PetscObjectDereference((*ds)->disc[f]);CHKERRQ(ierr); 5572764a2aaSMatthew G. Knepley } 558*5fedec97SMatthew G. Knepley ierr = PetscFree4((*ds)->disc, (*ds)->implicit, (*ds)->cohesive, (*ds)->jetDegree);CHKERRQ(ierr); 5596528b96dSMatthew G. Knepley ierr = PetscWeakFormDestroy(&(*ds)->wf);CHKERRQ(ierr); 5606528b96dSMatthew G. Knepley ierr = PetscFree2((*ds)->update,(*ds)->ctx);CHKERRQ(ierr); 5616528b96dSMatthew G. Knepley ierr = PetscFree4((*ds)->exactSol,(*ds)->exactCtx,(*ds)->exactSol_t,(*ds)->exactCtx_t);CHKERRQ(ierr); 5626528b96dSMatthew G. Knepley if ((*ds)->ops->destroy) {ierr = (*(*ds)->ops->destroy)(*ds);CHKERRQ(ierr);} 56345480ffeSMatthew G. Knepley ierr = PetscDSDestroyBoundary(*ds);CHKERRQ(ierr); 5646528b96dSMatthew G. Knepley ierr = PetscFree((*ds)->constants);CHKERRQ(ierr); 5656528b96dSMatthew G. Knepley ierr = PetscHeaderDestroy(ds);CHKERRQ(ierr); 5662764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5672764a2aaSMatthew G. Knepley } 5682764a2aaSMatthew G. Knepley 5692764a2aaSMatthew G. Knepley /*@ 5702764a2aaSMatthew G. Knepley PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType(). 5712764a2aaSMatthew G. Knepley 572d083f849SBarry Smith Collective 5732764a2aaSMatthew G. Knepley 5742764a2aaSMatthew G. Knepley Input Parameter: 5752764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object 5762764a2aaSMatthew G. Knepley 5772764a2aaSMatthew G. Knepley Output Parameter: 5786528b96dSMatthew G. Knepley . ds - The PetscDS object 5792764a2aaSMatthew G. Knepley 5802764a2aaSMatthew G. Knepley Level: beginner 5812764a2aaSMatthew G. Knepley 5822764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC 5832764a2aaSMatthew G. Knepley @*/ 5846528b96dSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *ds) 5852764a2aaSMatthew G. Knepley { 5862764a2aaSMatthew G. Knepley PetscDS p; 5872764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5882764a2aaSMatthew G. Knepley 5892764a2aaSMatthew G. Knepley PetscFunctionBegin; 5906528b96dSMatthew G. Knepley PetscValidPointer(ds, 2); 5916528b96dSMatthew G. Knepley *ds = NULL; 5922764a2aaSMatthew G. Knepley ierr = PetscDSInitializePackage();CHKERRQ(ierr); 5932764a2aaSMatthew G. Knepley 59473107ff1SLisandro Dalcin ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr); 5952764a2aaSMatthew G. Knepley 5962764a2aaSMatthew G. Knepley p->Nf = 0; 5972764a2aaSMatthew G. Knepley p->setup = PETSC_FALSE; 59897b6e6e8SMatthew G. Knepley p->numConstants = 0; 59997b6e6e8SMatthew G. Knepley p->constants = NULL; 600a859676bSMatthew G. Knepley p->dimEmbed = -1; 60155c1f793SMatthew G. Knepley p->useJacPre = PETSC_TRUE; 6026528b96dSMatthew G. Knepley ierr = PetscWeakFormCreate(comm, &p->wf);CHKERRQ(ierr); 6032764a2aaSMatthew G. Knepley 6046528b96dSMatthew G. Knepley *ds = p; 6052764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6062764a2aaSMatthew G. Knepley } 6072764a2aaSMatthew G. Knepley 608bc4ae4beSMatthew G. Knepley /*@ 609bc4ae4beSMatthew G. Knepley PetscDSGetNumFields - Returns the number of fields in the DS 610bc4ae4beSMatthew G. Knepley 611bc4ae4beSMatthew G. Knepley Not collective 612bc4ae4beSMatthew G. Knepley 613bc4ae4beSMatthew G. Knepley Input Parameter: 614bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 615bc4ae4beSMatthew G. Knepley 616bc4ae4beSMatthew G. Knepley Output Parameter: 617bc4ae4beSMatthew G. Knepley . Nf - The number of fields 618bc4ae4beSMatthew G. Knepley 619bc4ae4beSMatthew G. Knepley Level: beginner 620bc4ae4beSMatthew G. Knepley 621bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate() 622bc4ae4beSMatthew G. Knepley @*/ 6232764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) 6242764a2aaSMatthew G. Knepley { 6252764a2aaSMatthew G. Knepley PetscFunctionBegin; 6262764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6272764a2aaSMatthew G. Knepley PetscValidPointer(Nf, 2); 6282764a2aaSMatthew G. Knepley *Nf = prob->Nf; 6292764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6302764a2aaSMatthew G. Knepley } 6312764a2aaSMatthew G. Knepley 632bc4ae4beSMatthew G. Knepley /*@ 633a859676bSMatthew G. Knepley PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations 634bc4ae4beSMatthew G. Knepley 635bc4ae4beSMatthew G. Knepley Not collective 636bc4ae4beSMatthew G. Knepley 637bc4ae4beSMatthew G. Knepley Input Parameter: 638bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 639bc4ae4beSMatthew G. Knepley 640bc4ae4beSMatthew G. Knepley Output Parameter: 641bc4ae4beSMatthew G. Knepley . dim - The spatial dimension 642bc4ae4beSMatthew G. Knepley 643bc4ae4beSMatthew G. Knepley Level: beginner 644bc4ae4beSMatthew G. Knepley 645a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate() 646bc4ae4beSMatthew G. Knepley @*/ 6472764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) 6482764a2aaSMatthew G. Knepley { 6492764a2aaSMatthew G. Knepley PetscErrorCode ierr; 6502764a2aaSMatthew G. Knepley 6512764a2aaSMatthew G. Knepley PetscFunctionBegin; 6522764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6532764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 6542764a2aaSMatthew G. Knepley *dim = 0; 6559de99aefSMatthew G. Knepley if (prob->Nf) { 6569de99aefSMatthew G. Knepley PetscObject obj; 6579de99aefSMatthew G. Knepley PetscClassId id; 6589de99aefSMatthew G. Knepley 6599de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 660665f567fSMatthew G. Knepley if (obj) { 6619de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 6629de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);} 6639de99aefSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);} 6649de99aefSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 6659de99aefSMatthew G. Knepley } 666665f567fSMatthew G. Knepley } 6672764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6682764a2aaSMatthew G. Knepley } 6692764a2aaSMatthew G. Knepley 670bc4ae4beSMatthew G. Knepley /*@ 671a859676bSMatthew G. Knepley PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 672a859676bSMatthew G. Knepley 673a859676bSMatthew G. Knepley Not collective 674a859676bSMatthew G. Knepley 675a859676bSMatthew G. Knepley Input Parameter: 676a859676bSMatthew G. Knepley . prob - The PetscDS object 677a859676bSMatthew G. Knepley 678a859676bSMatthew G. Knepley Output Parameter: 679a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension 680a859676bSMatthew G. Knepley 681a859676bSMatthew G. Knepley Level: beginner 682a859676bSMatthew G. Knepley 683a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 684a859676bSMatthew G. Knepley @*/ 685a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed) 686a859676bSMatthew G. Knepley { 687a859676bSMatthew G. Knepley PetscFunctionBegin; 688a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 689a859676bSMatthew G. Knepley PetscValidPointer(dimEmbed, 2); 690a859676bSMatthew G. Knepley if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS"); 691a859676bSMatthew G. Knepley *dimEmbed = prob->dimEmbed; 692a859676bSMatthew G. Knepley PetscFunctionReturn(0); 693a859676bSMatthew G. Knepley } 694a859676bSMatthew G. Knepley 695a859676bSMatthew G. Knepley /*@ 696a859676bSMatthew G. Knepley PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded 697a859676bSMatthew G. Knepley 698d083f849SBarry Smith Logically collective on prob 699a859676bSMatthew G. Knepley 700a859676bSMatthew G. Knepley Input Parameters: 701a859676bSMatthew G. Knepley + prob - The PetscDS object 702a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension 703a859676bSMatthew G. Knepley 704a859676bSMatthew G. Knepley Level: beginner 705a859676bSMatthew G. Knepley 706a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate() 707a859676bSMatthew G. Knepley @*/ 708a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed) 709a859676bSMatthew G. Knepley { 710a859676bSMatthew G. Knepley PetscFunctionBegin; 711a859676bSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 712ebfe4b0dSMatthew G. Knepley if (dimEmbed < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Coordinate dimension must be non-negative, not %D", dimEmbed); 713a859676bSMatthew G. Knepley prob->dimEmbed = dimEmbed; 714a859676bSMatthew G. Knepley PetscFunctionReturn(0); 715a859676bSMatthew G. Knepley } 716a859676bSMatthew G. Knepley 717a859676bSMatthew G. Knepley /*@ 718*5fedec97SMatthew G. Knepley PetscDSIsCohesive - Returns the flag indicating that this DS is for a cohesive cell 7198edf6225SMatthew G. Knepley 7208edf6225SMatthew G. Knepley Not collective 7218edf6225SMatthew G. Knepley 7228edf6225SMatthew G. Knepley Input Parameter: 723*5fedec97SMatthew G. Knepley . ds - The PetscDS object 7248edf6225SMatthew G. Knepley 7258edf6225SMatthew G. Knepley Output Parameter: 726*5fedec97SMatthew G. Knepley . isCohesive - The flag 7278edf6225SMatthew G. Knepley 7288edf6225SMatthew G. Knepley Level: developer 7298edf6225SMatthew G. Knepley 730*5fedec97SMatthew G. Knepley .seealso: PetscDSGetNumCohesive(), PetscDSGetCohesive(), PetscDSSetCohesive(), PetscDSCreate() 7318edf6225SMatthew G. Knepley @*/ 732*5fedec97SMatthew G. Knepley PetscErrorCode PetscDSIsCohesive(PetscDS ds, PetscBool *isCohesive) 7338edf6225SMatthew G. Knepley { 7348edf6225SMatthew G. Knepley PetscFunctionBegin; 735*5fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 736*5fedec97SMatthew G. Knepley PetscValidPointer(isCohesive, 2); 737*5fedec97SMatthew G. Knepley *isCohesive = ds->isCohesive; 7388edf6225SMatthew G. Knepley PetscFunctionReturn(0); 7398edf6225SMatthew G. Knepley } 7408edf6225SMatthew G. Knepley 7418edf6225SMatthew G. Knepley /*@ 742*5fedec97SMatthew G. Knepley PetscDSGetNumCohesive - Returns the numer of cohesive fields, meaning those defined on the interior of a cohesive cell 743*5fedec97SMatthew G. Knepley 744*5fedec97SMatthew G. Knepley Not collective 745*5fedec97SMatthew G. Knepley 746*5fedec97SMatthew G. Knepley Input Parameter: 747*5fedec97SMatthew G. Knepley . ds - The PetscDS object 748*5fedec97SMatthew G. Knepley 749*5fedec97SMatthew G. Knepley Output Parameter: 750*5fedec97SMatthew G. Knepley . numCohesive - The number of cohesive fields 751*5fedec97SMatthew G. Knepley 752*5fedec97SMatthew G. Knepley Level: developer 753*5fedec97SMatthew G. Knepley 754*5fedec97SMatthew G. Knepley .seealso: PetscDSSetCohesive(), PetscDSCreate() 755*5fedec97SMatthew G. Knepley @*/ 756*5fedec97SMatthew G. Knepley PetscErrorCode PetscDSGetNumCohesive(PetscDS ds, PetscInt *numCohesive) 757*5fedec97SMatthew G. Knepley { 758*5fedec97SMatthew G. Knepley PetscInt f; 759*5fedec97SMatthew G. Knepley 760*5fedec97SMatthew G. Knepley PetscFunctionBegin; 761*5fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 762*5fedec97SMatthew G. Knepley PetscValidPointer(numCohesive, 2); 763*5fedec97SMatthew G. Knepley *numCohesive = 0; 764*5fedec97SMatthew G. Knepley for (f = 0; f < ds->Nf; ++f) *numCohesive += ds->cohesive[f] ? 1 : 0; 765*5fedec97SMatthew G. Knepley PetscFunctionReturn(0); 766*5fedec97SMatthew G. Knepley } 767*5fedec97SMatthew G. Knepley 768*5fedec97SMatthew G. Knepley /*@ 769*5fedec97SMatthew G. Knepley PetscDSGetCohesive - Returns the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell 770*5fedec97SMatthew G. Knepley 771*5fedec97SMatthew G. Knepley Not collective 772*5fedec97SMatthew G. Knepley 773*5fedec97SMatthew G. Knepley Input Parameter: 774*5fedec97SMatthew G. Knepley + ds - The PetscDS object 775*5fedec97SMatthew G. Knepley - f - The field index 776*5fedec97SMatthew G. Knepley 777*5fedec97SMatthew G. Knepley Output Parameter: 778*5fedec97SMatthew G. Knepley . isCohesive - The flag 779*5fedec97SMatthew G. Knepley 780*5fedec97SMatthew G. Knepley Level: developer 781*5fedec97SMatthew G. Knepley 782*5fedec97SMatthew G. Knepley .seealso: PetscDSSetCohesive(), PetscDSIsCohesive(), PetscDSCreate() 783*5fedec97SMatthew G. Knepley @*/ 784*5fedec97SMatthew G. Knepley PetscErrorCode PetscDSGetCohesive(PetscDS ds, PetscInt f, PetscBool *isCohesive) 785*5fedec97SMatthew G. Knepley { 786*5fedec97SMatthew G. Knepley PetscFunctionBegin; 787*5fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 788*5fedec97SMatthew G. Knepley PetscValidPointer(isCohesive, 3); 789*5fedec97SMatthew 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); 790*5fedec97SMatthew G. Knepley *isCohesive = ds->cohesive[f]; 791*5fedec97SMatthew G. Knepley PetscFunctionReturn(0); 792*5fedec97SMatthew G. Knepley } 793*5fedec97SMatthew G. Knepley 794*5fedec97SMatthew G. Knepley /*@ 795*5fedec97SMatthew G. Knepley PetscDSSetCohesive - Set the flag indicating that a field is cohesive, meaning it is defined on the interior of a cohesive cell 7968edf6225SMatthew G. Knepley 7978edf6225SMatthew G. Knepley Not collective 7988edf6225SMatthew G. Knepley 7998edf6225SMatthew G. Knepley Input Parameters: 800*5fedec97SMatthew G. Knepley + ds - The PetscDS object 801*5fedec97SMatthew G. Knepley . f - The field index 802*5fedec97SMatthew G. Knepley - isCohesive - The flag for a cohesive field 8038edf6225SMatthew G. Knepley 8048edf6225SMatthew G. Knepley Level: developer 8058edf6225SMatthew G. Knepley 806*5fedec97SMatthew G. Knepley .seealso: PetscDSGetCohesive(), PetscDSIsCohesive(), PetscDSCreate() 8078edf6225SMatthew G. Knepley @*/ 808*5fedec97SMatthew G. Knepley PetscErrorCode PetscDSSetCohesive(PetscDS ds, PetscInt f, PetscBool isCohesive) 8098edf6225SMatthew G. Knepley { 810*5fedec97SMatthew G. Knepley PetscInt i; 811*5fedec97SMatthew G. Knepley 8128edf6225SMatthew G. Knepley PetscFunctionBegin; 813*5fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 814*5fedec97SMatthew 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); 815*5fedec97SMatthew G. Knepley ds->cohesive[f] = isCohesive; 816*5fedec97SMatthew G. Knepley ds->isCohesive = PETSC_FALSE; 817*5fedec97SMatthew G. Knepley for (i = 0; i < ds->Nf; ++i) ds->isCohesive = ds->isCohesive || ds->cohesive[f] ? PETSC_TRUE : PETSC_FALSE; 8188edf6225SMatthew G. Knepley PetscFunctionReturn(0); 8198edf6225SMatthew G. Knepley } 8208edf6225SMatthew G. Knepley 8218edf6225SMatthew G. Knepley /*@ 822bc4ae4beSMatthew G. Knepley PetscDSGetTotalDimension - Returns the total size of the approximation space for this system 823bc4ae4beSMatthew G. Knepley 824bc4ae4beSMatthew G. Knepley Not collective 825bc4ae4beSMatthew G. Knepley 826bc4ae4beSMatthew G. Knepley Input Parameter: 827bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 828bc4ae4beSMatthew G. Knepley 829bc4ae4beSMatthew G. Knepley Output Parameter: 830bc4ae4beSMatthew G. Knepley . dim - The total problem dimension 831bc4ae4beSMatthew G. Knepley 832bc4ae4beSMatthew G. Knepley Level: beginner 833bc4ae4beSMatthew G. Knepley 834bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 835bc4ae4beSMatthew G. Knepley @*/ 8362764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) 8372764a2aaSMatthew G. Knepley { 8382764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8392764a2aaSMatthew G. Knepley 8402764a2aaSMatthew G. Knepley PetscFunctionBegin; 8412764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8422764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 8432764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 8442764a2aaSMatthew G. Knepley *dim = prob->totDim; 8452764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8462764a2aaSMatthew G. Knepley } 8472764a2aaSMatthew G. Knepley 848bc4ae4beSMatthew G. Knepley /*@ 849bc4ae4beSMatthew G. Knepley PetscDSGetTotalComponents - Returns the total number of components in this system 850bc4ae4beSMatthew G. Knepley 851bc4ae4beSMatthew G. Knepley Not collective 852bc4ae4beSMatthew G. Knepley 853bc4ae4beSMatthew G. Knepley Input Parameter: 854bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 855bc4ae4beSMatthew G. Knepley 856bc4ae4beSMatthew G. Knepley Output Parameter: 857bc4ae4beSMatthew G. Knepley . dim - The total number of components 858bc4ae4beSMatthew G. Knepley 859bc4ae4beSMatthew G. Knepley Level: beginner 860bc4ae4beSMatthew G. Knepley 861bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 862bc4ae4beSMatthew G. Knepley @*/ 8632764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) 8642764a2aaSMatthew G. Knepley { 8652764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8662764a2aaSMatthew G. Knepley 8672764a2aaSMatthew G. Knepley PetscFunctionBegin; 8682764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8692764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 8702764a2aaSMatthew G. Knepley PetscValidPointer(Nc, 2); 8712764a2aaSMatthew G. Knepley *Nc = prob->totComp; 8722764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8732764a2aaSMatthew G. Knepley } 8742764a2aaSMatthew G. Knepley 875bc4ae4beSMatthew G. Knepley /*@ 876bc4ae4beSMatthew G. Knepley PetscDSGetDiscretization - Returns the discretization object for the given field 877bc4ae4beSMatthew G. Knepley 878bc4ae4beSMatthew G. Knepley Not collective 879bc4ae4beSMatthew G. Knepley 880bc4ae4beSMatthew G. Knepley Input Parameters: 881bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 882bc4ae4beSMatthew G. Knepley - f - The field number 883bc4ae4beSMatthew G. Knepley 884bc4ae4beSMatthew G. Knepley Output Parameter: 885bc4ae4beSMatthew G. Knepley . disc - The discretization object 886bc4ae4beSMatthew G. Knepley 887bc4ae4beSMatthew G. Knepley Level: beginner 888bc4ae4beSMatthew G. Knepley 889f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 890bc4ae4beSMatthew G. Knepley @*/ 8912764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 8922764a2aaSMatthew G. Knepley { 8936528b96dSMatthew G. Knepley PetscFunctionBeginHot; 8942764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8952764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 8962764a2aaSMatthew 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); 8972764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 8982764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8992764a2aaSMatthew G. Knepley } 9002764a2aaSMatthew G. Knepley 901bc4ae4beSMatthew G. Knepley /*@ 902bc4ae4beSMatthew G. Knepley PetscDSSetDiscretization - Sets the discretization object for the given field 903bc4ae4beSMatthew G. Knepley 904bc4ae4beSMatthew G. Knepley Not collective 905bc4ae4beSMatthew G. Knepley 906bc4ae4beSMatthew G. Knepley Input Parameters: 907bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 908bc4ae4beSMatthew G. Knepley . f - The field number 909bc4ae4beSMatthew G. Knepley - disc - The discretization object 910bc4ae4beSMatthew G. Knepley 911bc4ae4beSMatthew G. Knepley Level: beginner 912bc4ae4beSMatthew G. Knepley 913bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 914bc4ae4beSMatthew G. Knepley @*/ 9152764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 9162764a2aaSMatthew G. Knepley { 9172764a2aaSMatthew G. Knepley PetscErrorCode ierr; 9182764a2aaSMatthew G. Knepley 9192764a2aaSMatthew G. Knepley PetscFunctionBegin; 9202764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 921665f567fSMatthew G. Knepley if (disc) PetscValidPointer(disc, 3); 9222764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 9232764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 924c10f2116SMatthew G. Knepley ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr); 9252764a2aaSMatthew G. Knepley prob->disc[f] = disc; 9262764a2aaSMatthew G. Knepley ierr = PetscObjectReference(disc);CHKERRQ(ierr); 927665f567fSMatthew G. Knepley if (disc) { 928249df284SMatthew G. Knepley PetscClassId id; 929249df284SMatthew G. Knepley 930249df284SMatthew G. Knepley ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr); 9311cf84007SMatthew G. Knepley if (id == PETSCFE_CLASSID) { 9321cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr); 9331cf84007SMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 9341cf84007SMatthew G. Knepley ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr); 935a6cbbb48SMatthew G. Knepley } 936f9244615SMatthew G. Knepley ierr = PetscDSSetJetDegree(prob, f, 1);CHKERRQ(ierr); 937249df284SMatthew G. Knepley } 9382764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9392764a2aaSMatthew G. Knepley } 9402764a2aaSMatthew G. Knepley 941bc4ae4beSMatthew G. Knepley /*@ 9426528b96dSMatthew G. Knepley PetscDSGetWeakForm - Returns the weak form object 9436528b96dSMatthew G. Knepley 9446528b96dSMatthew G. Knepley Not collective 9456528b96dSMatthew G. Knepley 9466528b96dSMatthew G. Knepley Input Parameter: 9476528b96dSMatthew G. Knepley . ds - The PetscDS object 9486528b96dSMatthew G. Knepley 9496528b96dSMatthew G. Knepley Output Parameter: 9506528b96dSMatthew G. Knepley . wf - The weak form object 9516528b96dSMatthew G. Knepley 9526528b96dSMatthew G. Knepley Level: beginner 9536528b96dSMatthew G. Knepley 9546528b96dSMatthew G. Knepley .seealso: PetscDSSetWeakForm(), PetscDSGetNumFields(), PetscDSCreate() 9556528b96dSMatthew G. Knepley @*/ 9566528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetWeakForm(PetscDS ds, PetscWeakForm *wf) 9576528b96dSMatthew G. Knepley { 9586528b96dSMatthew G. Knepley PetscFunctionBegin; 9596528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 9606528b96dSMatthew G. Knepley PetscValidPointer(wf, 2); 9616528b96dSMatthew G. Knepley *wf = ds->wf; 9626528b96dSMatthew G. Knepley PetscFunctionReturn(0); 9636528b96dSMatthew G. Knepley } 9646528b96dSMatthew G. Knepley 9656528b96dSMatthew G. Knepley /*@ 9666528b96dSMatthew G. Knepley PetscDSSetWeakForm - Sets the weak form object 9676528b96dSMatthew G. Knepley 9686528b96dSMatthew G. Knepley Not collective 9696528b96dSMatthew G. Knepley 9706528b96dSMatthew G. Knepley Input Parameters: 9716528b96dSMatthew G. Knepley + ds - The PetscDS object 9726528b96dSMatthew G. Knepley - wf - The weak form object 9736528b96dSMatthew G. Knepley 9746528b96dSMatthew G. Knepley Level: beginner 9756528b96dSMatthew G. Knepley 9766528b96dSMatthew G. Knepley .seealso: PetscDSGetWeakForm(), PetscDSGetNumFields(), PetscDSCreate() 9776528b96dSMatthew G. Knepley @*/ 9786528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetWeakForm(PetscDS ds, PetscWeakForm wf) 9796528b96dSMatthew G. Knepley { 9806528b96dSMatthew G. Knepley PetscErrorCode ierr; 9816528b96dSMatthew G. Knepley 9826528b96dSMatthew G. Knepley PetscFunctionBegin; 9836528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 9846528b96dSMatthew G. Knepley PetscValidHeaderSpecific(wf, PETSCWEAKFORM_CLASSID, 2); 9856528b96dSMatthew G. Knepley ierr = PetscObjectDereference((PetscObject) ds->wf);CHKERRQ(ierr); 9866528b96dSMatthew G. Knepley ds->wf = wf; 9876528b96dSMatthew G. Knepley ierr = PetscObjectReference((PetscObject) wf);CHKERRQ(ierr); 9886528b96dSMatthew G. Knepley ierr = PetscWeakFormSetNumFields(wf, ds->Nf);CHKERRQ(ierr); 9896528b96dSMatthew G. Knepley PetscFunctionReturn(0); 9906528b96dSMatthew G. Knepley } 9916528b96dSMatthew G. Knepley 9926528b96dSMatthew G. Knepley /*@ 993bc4ae4beSMatthew G. Knepley PetscDSAddDiscretization - Adds a discretization object 994bc4ae4beSMatthew G. Knepley 995bc4ae4beSMatthew G. Knepley Not collective 996bc4ae4beSMatthew G. Knepley 997bc4ae4beSMatthew G. Knepley Input Parameters: 998bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 999bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object 1000bc4ae4beSMatthew G. Knepley 1001bc4ae4beSMatthew G. Knepley Level: beginner 1002bc4ae4beSMatthew G. Knepley 1003bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 1004bc4ae4beSMatthew G. Knepley @*/ 10052764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) 10062764a2aaSMatthew G. Knepley { 10072764a2aaSMatthew G. Knepley PetscErrorCode ierr; 10082764a2aaSMatthew G. Knepley 10092764a2aaSMatthew G. Knepley PetscFunctionBegin; 10102764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr); 10112764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10122764a2aaSMatthew G. Knepley } 10132764a2aaSMatthew G. Knepley 1014249df284SMatthew G. Knepley /*@ 1015083401c6SMatthew G. Knepley PetscDSGetQuadrature - Returns the quadrature, which must agree for all fields in the DS 1016083401c6SMatthew G. Knepley 1017083401c6SMatthew G. Knepley Not collective 1018083401c6SMatthew G. Knepley 1019083401c6SMatthew G. Knepley Input Parameter: 1020083401c6SMatthew G. Knepley . prob - The PetscDS object 1021083401c6SMatthew G. Knepley 1022083401c6SMatthew G. Knepley Output Parameter: 1023083401c6SMatthew G. Knepley . q - The quadrature object 1024083401c6SMatthew G. Knepley 1025083401c6SMatthew G. Knepley Level: intermediate 1026083401c6SMatthew G. Knepley 1027083401c6SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 1028083401c6SMatthew G. Knepley @*/ 1029083401c6SMatthew G. Knepley PetscErrorCode PetscDSGetQuadrature(PetscDS prob, PetscQuadrature *q) 1030083401c6SMatthew G. Knepley { 1031083401c6SMatthew G. Knepley PetscObject obj; 1032083401c6SMatthew G. Knepley PetscClassId id; 1033083401c6SMatthew G. Knepley PetscErrorCode ierr; 1034083401c6SMatthew G. Knepley 1035083401c6SMatthew G. Knepley PetscFunctionBegin; 1036083401c6SMatthew G. Knepley *q = NULL; 1037083401c6SMatthew G. Knepley if (!prob->Nf) PetscFunctionReturn(0); 1038083401c6SMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 1039083401c6SMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 1040083401c6SMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetQuadrature((PetscFE) obj, q);CHKERRQ(ierr);} 1041083401c6SMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetQuadrature((PetscFV) obj, q);CHKERRQ(ierr);} 1042083401c6SMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 1043083401c6SMatthew G. Knepley PetscFunctionReturn(0); 1044083401c6SMatthew G. Knepley } 1045083401c6SMatthew G. Knepley 1046083401c6SMatthew G. Knepley /*@ 1047249df284SMatthew G. Knepley PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX 1048249df284SMatthew G. Knepley 1049249df284SMatthew G. Knepley Not collective 1050249df284SMatthew G. Knepley 1051249df284SMatthew G. Knepley Input Parameters: 1052249df284SMatthew G. Knepley + prob - The PetscDS object 1053249df284SMatthew G. Knepley - f - The field number 1054249df284SMatthew G. Knepley 1055249df284SMatthew G. Knepley Output Parameter: 1056249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field 1057249df284SMatthew G. Knepley 1058249df284SMatthew G. Knepley Level: developer 1059249df284SMatthew G. Knepley 1060f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 1061249df284SMatthew G. Knepley @*/ 1062249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit) 1063249df284SMatthew G. Knepley { 1064249df284SMatthew G. Knepley PetscFunctionBegin; 1065249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1066249df284SMatthew G. Knepley PetscValidPointer(implicit, 3); 1067249df284SMatthew 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); 1068249df284SMatthew G. Knepley *implicit = prob->implicit[f]; 1069249df284SMatthew G. Knepley PetscFunctionReturn(0); 1070249df284SMatthew G. Knepley } 1071249df284SMatthew G. Knepley 1072249df284SMatthew G. Knepley /*@ 1073249df284SMatthew G. Knepley PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX 1074249df284SMatthew G. Knepley 1075249df284SMatthew G. Knepley Not collective 1076249df284SMatthew G. Knepley 1077249df284SMatthew G. Knepley Input Parameters: 1078249df284SMatthew G. Knepley + prob - The PetscDS object 1079249df284SMatthew G. Knepley . f - The field number 1080249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field 1081249df284SMatthew G. Knepley 1082249df284SMatthew G. Knepley Level: developer 1083249df284SMatthew G. Knepley 1084f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 1085249df284SMatthew G. Knepley @*/ 1086249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit) 1087249df284SMatthew G. Knepley { 1088249df284SMatthew G. Knepley PetscFunctionBegin; 1089249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1090249df284SMatthew 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); 1091249df284SMatthew G. Knepley prob->implicit[f] = implicit; 1092249df284SMatthew G. Knepley PetscFunctionReturn(0); 1093249df284SMatthew G. Knepley } 1094249df284SMatthew G. Knepley 1095f9244615SMatthew G. Knepley /*@ 1096f9244615SMatthew G. Knepley PetscDSGetJetDegree - Returns the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate. 1097f9244615SMatthew G. Knepley 1098f9244615SMatthew G. Knepley Not collective 1099f9244615SMatthew G. Knepley 1100f9244615SMatthew G. Knepley Input Parameters: 1101f9244615SMatthew G. Knepley + ds - The PetscDS object 1102f9244615SMatthew G. Knepley - f - The field number 1103f9244615SMatthew G. Knepley 1104f9244615SMatthew G. Knepley Output Parameter: 1105f9244615SMatthew G. Knepley . k - The highest derivative we need to tabulate 1106f9244615SMatthew G. Knepley 1107f9244615SMatthew G. Knepley Level: developer 1108f9244615SMatthew G. Knepley 1109f9244615SMatthew G. Knepley .seealso: PetscDSSetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 1110f9244615SMatthew G. Knepley @*/ 1111f9244615SMatthew G. Knepley PetscErrorCode PetscDSGetJetDegree(PetscDS ds, PetscInt f, PetscInt *k) 1112f9244615SMatthew G. Knepley { 1113f9244615SMatthew G. Knepley PetscFunctionBegin; 1114f9244615SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1115f9244615SMatthew G. Knepley PetscValidPointer(k, 3); 1116f9244615SMatthew 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); 1117f9244615SMatthew G. Knepley *k = ds->jetDegree[f]; 1118f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1119f9244615SMatthew G. Knepley } 1120f9244615SMatthew G. Knepley 1121f9244615SMatthew G. Knepley /*@ 1122f9244615SMatthew G. Knepley PetscDSSetJetDegree - Set the highest derivative for this field equation, or the k-jet that the discretization needs to tabulate. 1123f9244615SMatthew G. Knepley 1124f9244615SMatthew G. Knepley Not collective 1125f9244615SMatthew G. Knepley 1126f9244615SMatthew G. Knepley Input Parameters: 1127f9244615SMatthew G. Knepley + ds - The PetscDS object 1128f9244615SMatthew G. Knepley . f - The field number 1129f9244615SMatthew G. Knepley - k - The highest derivative we need to tabulate 1130f9244615SMatthew G. Knepley 1131f9244615SMatthew G. Knepley Level: developer 1132f9244615SMatthew G. Knepley 1133f9244615SMatthew G. Knepley .seealso: PetscDSGetJetDegree(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 1134f9244615SMatthew G. Knepley @*/ 1135f9244615SMatthew G. Knepley PetscErrorCode PetscDSSetJetDegree(PetscDS ds, PetscInt f, PetscInt k) 1136f9244615SMatthew G. Knepley { 1137f9244615SMatthew G. Knepley PetscFunctionBegin; 1138f9244615SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1139f9244615SMatthew 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); 1140f9244615SMatthew G. Knepley ds->jetDegree[f] = k; 1141f9244615SMatthew G. Knepley PetscFunctionReturn(0); 1142f9244615SMatthew G. Knepley } 1143f9244615SMatthew G. Knepley 11446528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS ds, PetscInt f, 114530b9ff8bSMatthew G. Knepley void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1146194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1147194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 114897b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 11492764a2aaSMatthew G. Knepley { 11506528b96dSMatthew G. Knepley PetscPointFunc *tmp; 11516528b96dSMatthew G. Knepley PetscInt n; 11526528b96dSMatthew G. Knepley PetscErrorCode ierr; 11536528b96dSMatthew G. Knepley 11542764a2aaSMatthew G. Knepley PetscFunctionBegin; 11556528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 11566528b96dSMatthew G. Knepley PetscValidPointer(obj, 3); 11576528b96dSMatthew 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); 115806ad1575SMatthew G. Knepley ierr = PetscWeakFormGetObjective(ds->wf, NULL, 0, f, 0, &n, &tmp);CHKERRQ(ierr); 11596528b96dSMatthew G. Knepley *obj = tmp ? tmp[0] : NULL; 11602764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11612764a2aaSMatthew G. Knepley } 11622764a2aaSMatthew G. Knepley 11636528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS ds, PetscInt f, 116430b9ff8bSMatthew G. Knepley void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1165194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1166194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 116797b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 11682764a2aaSMatthew G. Knepley { 11692764a2aaSMatthew G. Knepley PetscErrorCode ierr; 11702764a2aaSMatthew G. Knepley 11712764a2aaSMatthew G. Knepley PetscFunctionBegin; 11726528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 11736528b96dSMatthew G. Knepley if (obj) PetscValidFunction(obj, 3); 11742764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 117506ad1575SMatthew G. Knepley ierr = PetscWeakFormSetIndexObjective(ds->wf, NULL, 0, f, 0, 0, obj);CHKERRQ(ierr); 11762764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11772764a2aaSMatthew G. Knepley } 11782764a2aaSMatthew G. Knepley 1179194d53e6SMatthew G. Knepley /*@C 1180194d53e6SMatthew G. Knepley PetscDSGetResidual - Get the pointwise residual function for a given test field 1181194d53e6SMatthew G. Knepley 1182194d53e6SMatthew G. Knepley Not collective 1183194d53e6SMatthew G. Knepley 1184194d53e6SMatthew G. Knepley Input Parameters: 11856528b96dSMatthew G. Knepley + ds - The PetscDS 1186194d53e6SMatthew G. Knepley - f - The test field number 1187194d53e6SMatthew G. Knepley 1188194d53e6SMatthew G. Knepley Output Parameters: 1189194d53e6SMatthew G. Knepley + f0 - integrand for the test function term 1190194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1191194d53e6SMatthew G. Knepley 1192194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1193194d53e6SMatthew G. Knepley 1194194d53e6SMatthew 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) 1195194d53e6SMatthew G. Knepley 1196194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1197194d53e6SMatthew G. Knepley 119830b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1199194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1200194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 120130b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1202194d53e6SMatthew G. Knepley 1203194d53e6SMatthew G. Knepley + dim - the spatial dimension 1204194d53e6SMatthew G. Knepley . Nf - the number of fields 1205194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1206194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1207194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1208194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1209194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1210194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1211194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1212194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1213194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1214194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1215194d53e6SMatthew G. Knepley . t - current time 1216194d53e6SMatthew G. Knepley . x - coordinates of the current point 121797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 121897b6e6e8SMatthew G. Knepley . constants - constant parameters 1219194d53e6SMatthew G. Knepley - f0 - output values at the current point 1220194d53e6SMatthew G. Knepley 1221194d53e6SMatthew G. Knepley Level: intermediate 1222194d53e6SMatthew G. Knepley 1223194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual() 1224194d53e6SMatthew G. Knepley @*/ 12256528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS ds, PetscInt f, 122630b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1227194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1228194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 122997b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 123030b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1231194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1232194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 123397b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 12342764a2aaSMatthew G. Knepley { 12356528b96dSMatthew G. Knepley PetscPointFunc *tmp0, *tmp1; 12366528b96dSMatthew G. Knepley PetscInt n0, n1; 12376528b96dSMatthew G. Knepley PetscErrorCode ierr; 12386528b96dSMatthew G. Knepley 12392764a2aaSMatthew G. Knepley PetscFunctionBegin; 12406528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 12416528b96dSMatthew 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); 124206ad1575SMatthew G. Knepley ierr = PetscWeakFormGetResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr); 12436528b96dSMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 12446528b96dSMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 12452764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 12462764a2aaSMatthew G. Knepley } 12472764a2aaSMatthew G. Knepley 1248194d53e6SMatthew G. Knepley /*@C 1249194d53e6SMatthew G. Knepley PetscDSSetResidual - Set the pointwise residual function for a given test field 1250194d53e6SMatthew G. Knepley 1251194d53e6SMatthew G. Knepley Not collective 1252194d53e6SMatthew G. Knepley 1253194d53e6SMatthew G. Knepley Input Parameters: 12546528b96dSMatthew G. Knepley + ds - The PetscDS 1255194d53e6SMatthew G. Knepley . f - The test field number 1256194d53e6SMatthew G. Knepley . f0 - integrand for the test function term 1257194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 1258194d53e6SMatthew G. Knepley 1259194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1260194d53e6SMatthew G. Knepley 1261194d53e6SMatthew 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) 1262194d53e6SMatthew G. Knepley 1263194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1264194d53e6SMatthew G. Knepley 126530b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1266194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1267194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 126830b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 1269194d53e6SMatthew G. Knepley 1270194d53e6SMatthew G. Knepley + dim - the spatial dimension 1271194d53e6SMatthew G. Knepley . Nf - the number of fields 1272194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1273194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1274194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1275194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1276194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1277194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1278194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1279194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1280194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1281194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1282194d53e6SMatthew G. Knepley . t - current time 1283194d53e6SMatthew G. Knepley . x - coordinates of the current point 128497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 128597b6e6e8SMatthew G. Knepley . constants - constant parameters 1286194d53e6SMatthew G. Knepley - f0 - output values at the current point 1287194d53e6SMatthew G. Knepley 1288194d53e6SMatthew G. Knepley Level: intermediate 1289194d53e6SMatthew G. Knepley 1290194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual() 1291194d53e6SMatthew G. Knepley @*/ 12926528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS ds, PetscInt f, 129330b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1294194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1295194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 129697b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 129730b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1298194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1299194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 130097b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 13012764a2aaSMatthew G. Knepley { 13022764a2aaSMatthew G. Knepley PetscErrorCode ierr; 13032764a2aaSMatthew G. Knepley 13042764a2aaSMatthew G. Knepley PetscFunctionBegin; 13056528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1306f866a1d0SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 1307f866a1d0SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 13082764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 130906ad1575SMatthew G. Knepley ierr = PetscWeakFormSetIndexResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1);CHKERRQ(ierr); 13102764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 13112764a2aaSMatthew G. Knepley } 13122764a2aaSMatthew G. Knepley 13133e75805dSMatthew G. Knepley /*@C 13143e75805dSMatthew G. Knepley PetscDSHasJacobian - Signals that Jacobian functions have been set 13153e75805dSMatthew G. Knepley 13163e75805dSMatthew G. Knepley Not collective 13173e75805dSMatthew G. Knepley 13183e75805dSMatthew G. Knepley Input Parameter: 13193e75805dSMatthew G. Knepley . prob - The PetscDS 13203e75805dSMatthew G. Knepley 13213e75805dSMatthew G. Knepley Output Parameter: 13223e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set 13233e75805dSMatthew G. Knepley 13243e75805dSMatthew G. Knepley Level: intermediate 13253e75805dSMatthew G. Knepley 13263e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 13273e75805dSMatthew G. Knepley @*/ 13286528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS ds, PetscBool *hasJac) 13293e75805dSMatthew G. Knepley { 13306528b96dSMatthew G. Knepley PetscErrorCode ierr; 13313e75805dSMatthew G. Knepley 13323e75805dSMatthew G. Knepley PetscFunctionBegin; 13336528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 13346528b96dSMatthew G. Knepley ierr = PetscWeakFormHasJacobian(ds->wf, hasJac);CHKERRQ(ierr); 13353e75805dSMatthew G. Knepley PetscFunctionReturn(0); 13363e75805dSMatthew G. Knepley } 13373e75805dSMatthew G. Knepley 1338194d53e6SMatthew G. Knepley /*@C 1339194d53e6SMatthew G. Knepley PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field 1340194d53e6SMatthew G. Knepley 1341194d53e6SMatthew G. Knepley Not collective 1342194d53e6SMatthew G. Knepley 1343194d53e6SMatthew G. Knepley Input Parameters: 13446528b96dSMatthew G. Knepley + ds - The PetscDS 1345194d53e6SMatthew G. Knepley . f - The test field number 1346194d53e6SMatthew G. Knepley - g - The field number 1347194d53e6SMatthew G. Knepley 1348194d53e6SMatthew G. Knepley Output Parameters: 1349194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1350194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1351194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1352194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1353194d53e6SMatthew G. Knepley 1354194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1355194d53e6SMatthew G. Knepley 1356194d53e6SMatthew 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 1357194d53e6SMatthew G. Knepley 1358194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1359194d53e6SMatthew G. Knepley 136030b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1361194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1362194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 136330b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1364194d53e6SMatthew G. Knepley 1365194d53e6SMatthew G. Knepley + dim - the spatial dimension 1366194d53e6SMatthew G. Knepley . Nf - the number of fields 1367194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1368194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1369194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1370194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1371194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1372194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1373194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1374194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1375194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1376194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1377194d53e6SMatthew G. Knepley . t - current time 13782aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1379194d53e6SMatthew G. Knepley . x - coordinates of the current point 138097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 138197b6e6e8SMatthew G. Knepley . constants - constant parameters 1382194d53e6SMatthew G. Knepley - g0 - output values at the current point 1383194d53e6SMatthew G. Knepley 1384194d53e6SMatthew G. Knepley Level: intermediate 1385194d53e6SMatthew G. Knepley 1386194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1387194d53e6SMatthew G. Knepley @*/ 13886528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS ds, PetscInt f, PetscInt g, 138930b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1390194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1391194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 139297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 139330b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1394194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1395194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 139697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 139730b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1398194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1399194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 140097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 140130b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1402194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1403194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 140497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 14052764a2aaSMatthew G. Knepley { 14066528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 14076528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 14086528b96dSMatthew G. Knepley PetscErrorCode ierr; 14096528b96dSMatthew G. Knepley 14102764a2aaSMatthew G. Knepley PetscFunctionBegin; 14116528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14126528b96dSMatthew 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); 14136528b96dSMatthew 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); 141406ad1575SMatthew G. Knepley ierr = PetscWeakFormGetJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 14156528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 14166528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 14176528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 14186528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 14192764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 14202764a2aaSMatthew G. Knepley } 14212764a2aaSMatthew G. Knepley 1422194d53e6SMatthew G. Knepley /*@C 1423194d53e6SMatthew G. Knepley PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields 1424194d53e6SMatthew G. Knepley 1425194d53e6SMatthew G. Knepley Not collective 1426194d53e6SMatthew G. Knepley 1427194d53e6SMatthew G. Knepley Input Parameters: 14286528b96dSMatthew G. Knepley + ds - The PetscDS 1429194d53e6SMatthew G. Knepley . f - The test field number 1430194d53e6SMatthew G. Knepley . g - The field number 1431194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1432194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1433194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1434194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1435194d53e6SMatthew G. Knepley 1436194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1437194d53e6SMatthew G. Knepley 1438194d53e6SMatthew 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 1439194d53e6SMatthew G. Knepley 1440194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1441194d53e6SMatthew G. Knepley 144230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1443194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1444194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 144530b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1446194d53e6SMatthew G. Knepley 1447194d53e6SMatthew G. Knepley + dim - the spatial dimension 1448194d53e6SMatthew G. Knepley . Nf - the number of fields 1449194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1450194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1451194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1452194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1453194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1454194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1455194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1456194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1457194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1458194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1459194d53e6SMatthew G. Knepley . t - current time 14602aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1461194d53e6SMatthew G. Knepley . x - coordinates of the current point 146297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 146397b6e6e8SMatthew G. Knepley . constants - constant parameters 1464194d53e6SMatthew G. Knepley - g0 - output values at the current point 1465194d53e6SMatthew G. Knepley 1466194d53e6SMatthew G. Knepley Level: intermediate 1467194d53e6SMatthew G. Knepley 1468194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1469194d53e6SMatthew G. Knepley @*/ 14706528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS ds, PetscInt f, PetscInt g, 147130b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1472194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1473194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 147497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 147530b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1476194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1477194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 147897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 147930b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1480194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1481194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 148297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 148330b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1484194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1485194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 148697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 14872764a2aaSMatthew G. Knepley { 14882764a2aaSMatthew G. Knepley PetscErrorCode ierr; 14892764a2aaSMatthew G. Knepley 14902764a2aaSMatthew G. Knepley PetscFunctionBegin; 14916528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 14922764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 14932764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 14942764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 14952764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 14962764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 14972764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 149806ad1575SMatthew G. Knepley ierr = PetscWeakFormSetIndexJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 14992764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 15002764a2aaSMatthew G. Knepley } 15012764a2aaSMatthew G. Knepley 1502475e0ac9SMatthew G. Knepley /*@C 150355c1f793SMatthew G. Knepley PetscDSUseJacobianPreconditioner - Whether to construct a Jacobian preconditioner 150455c1f793SMatthew G. Knepley 150555c1f793SMatthew G. Knepley Not collective 150655c1f793SMatthew G. Knepley 150755c1f793SMatthew G. Knepley Input Parameters: 150855c1f793SMatthew G. Knepley + prob - The PetscDS 150955c1f793SMatthew G. Knepley - useJacPre - flag that enables construction of a Jacobian preconditioner 151055c1f793SMatthew G. Knepley 151155c1f793SMatthew G. Knepley Level: intermediate 151255c1f793SMatthew G. Knepley 151355c1f793SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 151455c1f793SMatthew G. Knepley @*/ 151555c1f793SMatthew G. Knepley PetscErrorCode PetscDSUseJacobianPreconditioner(PetscDS prob, PetscBool useJacPre) 151655c1f793SMatthew G. Knepley { 151755c1f793SMatthew G. Knepley PetscFunctionBegin; 151855c1f793SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 151955c1f793SMatthew G. Knepley prob->useJacPre = useJacPre; 152055c1f793SMatthew G. Knepley PetscFunctionReturn(0); 152155c1f793SMatthew G. Knepley } 152255c1f793SMatthew G. Knepley 152355c1f793SMatthew G. Knepley /*@C 1524475e0ac9SMatthew G. Knepley PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set 1525475e0ac9SMatthew G. Knepley 1526475e0ac9SMatthew G. Knepley Not collective 1527475e0ac9SMatthew G. Knepley 1528475e0ac9SMatthew G. Knepley Input Parameter: 1529475e0ac9SMatthew G. Knepley . prob - The PetscDS 1530475e0ac9SMatthew G. Knepley 1531475e0ac9SMatthew G. Knepley Output Parameter: 1532475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set 1533475e0ac9SMatthew G. Knepley 1534475e0ac9SMatthew G. Knepley Level: intermediate 1535475e0ac9SMatthew G. Knepley 1536475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1537475e0ac9SMatthew G. Knepley @*/ 15386528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS ds, PetscBool *hasJacPre) 1539475e0ac9SMatthew G. Knepley { 15406528b96dSMatthew G. Knepley PetscErrorCode ierr; 1541475e0ac9SMatthew G. Knepley 1542475e0ac9SMatthew G. Knepley PetscFunctionBegin; 15436528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1544475e0ac9SMatthew G. Knepley *hasJacPre = PETSC_FALSE; 15456528b96dSMatthew G. Knepley if (!ds->useJacPre) PetscFunctionReturn(0); 15466528b96dSMatthew G. Knepley ierr = PetscWeakFormHasJacobianPreconditioner(ds->wf, hasJacPre);CHKERRQ(ierr); 1547475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1548475e0ac9SMatthew G. Knepley } 1549475e0ac9SMatthew G. Knepley 1550475e0ac9SMatthew G. Knepley /*@C 1551475e0ac9SMatthew 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. 1552475e0ac9SMatthew G. Knepley 1553475e0ac9SMatthew G. Knepley Not collective 1554475e0ac9SMatthew G. Knepley 1555475e0ac9SMatthew G. Knepley Input Parameters: 15566528b96dSMatthew G. Knepley + ds - The PetscDS 1557475e0ac9SMatthew G. Knepley . f - The test field number 1558475e0ac9SMatthew G. Knepley - g - The field number 1559475e0ac9SMatthew G. Knepley 1560475e0ac9SMatthew G. Knepley Output Parameters: 1561475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term 1562475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1563475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1564475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1565475e0ac9SMatthew G. Knepley 1566475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1567475e0ac9SMatthew G. Knepley 1568475e0ac9SMatthew 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 1569475e0ac9SMatthew G. Knepley 1570475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1571475e0ac9SMatthew G. Knepley 1572475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1573475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1574475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1575475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1576475e0ac9SMatthew G. Knepley 1577475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1578475e0ac9SMatthew G. Knepley . Nf - the number of fields 1579475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1580475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1581475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1582475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1583475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1584475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1585475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1586475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1587475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1588475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1589475e0ac9SMatthew G. Knepley . t - current time 1590475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1591475e0ac9SMatthew G. Knepley . x - coordinates of the current point 159297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 159397b6e6e8SMatthew G. Knepley . constants - constant parameters 1594475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1595475e0ac9SMatthew G. Knepley 1596475e0ac9SMatthew G. Knepley Level: intermediate 1597475e0ac9SMatthew G. Knepley 1598475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1599475e0ac9SMatthew G. Knepley @*/ 16006528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, 1601475e0ac9SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1602475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1603475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 160497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1605475e0ac9SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1606475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1607475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 160897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1609475e0ac9SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1610475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1611475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 161297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1613475e0ac9SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1614475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1615475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 161697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1617475e0ac9SMatthew G. Knepley { 16186528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 16196528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 16206528b96dSMatthew G. Knepley PetscErrorCode ierr; 16216528b96dSMatthew G. Knepley 1622475e0ac9SMatthew G. Knepley PetscFunctionBegin; 16236528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 16246528b96dSMatthew 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); 16256528b96dSMatthew 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); 162606ad1575SMatthew G. Knepley ierr = PetscWeakFormGetJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 16276528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 16286528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 16296528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 16306528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 1631475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1632475e0ac9SMatthew G. Knepley } 1633475e0ac9SMatthew G. Knepley 1634475e0ac9SMatthew G. Knepley /*@C 1635475e0ac9SMatthew 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. 1636475e0ac9SMatthew G. Knepley 1637475e0ac9SMatthew G. Knepley Not collective 1638475e0ac9SMatthew G. Knepley 1639475e0ac9SMatthew G. Knepley Input Parameters: 16406528b96dSMatthew G. Knepley + ds - The PetscDS 1641475e0ac9SMatthew G. Knepley . f - The test field number 1642475e0ac9SMatthew G. Knepley . g - The field number 1643475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term 1644475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1645475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1646475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1647475e0ac9SMatthew G. Knepley 1648475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1649475e0ac9SMatthew G. Knepley 1650475e0ac9SMatthew 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 1651475e0ac9SMatthew G. Knepley 1652475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1653475e0ac9SMatthew G. Knepley 1654475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1655475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1656475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1657475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1658475e0ac9SMatthew G. Knepley 1659475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1660475e0ac9SMatthew G. Knepley . Nf - the number of fields 1661475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1662475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1663475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1664475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1665475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1666475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1667475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1668475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1669475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1670475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1671475e0ac9SMatthew G. Knepley . t - current time 1672475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1673475e0ac9SMatthew G. Knepley . x - coordinates of the current point 167497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 167597b6e6e8SMatthew G. Knepley . constants - constant parameters 1676475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1677475e0ac9SMatthew G. Knepley 1678475e0ac9SMatthew G. Knepley Level: intermediate 1679475e0ac9SMatthew G. Knepley 1680475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian() 1681475e0ac9SMatthew G. Knepley @*/ 16826528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, 1683475e0ac9SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1684475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1685475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 168697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1687475e0ac9SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1688475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1689475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 169097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1691475e0ac9SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1692475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1693475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 169497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1695475e0ac9SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1696475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1697475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 169897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1699475e0ac9SMatthew G. Knepley { 1700475e0ac9SMatthew G. Knepley PetscErrorCode ierr; 1701475e0ac9SMatthew G. Knepley 1702475e0ac9SMatthew G. Knepley PetscFunctionBegin; 17036528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1704475e0ac9SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1705475e0ac9SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1706475e0ac9SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1707475e0ac9SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1708475e0ac9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1709475e0ac9SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 171006ad1575SMatthew G. Knepley ierr = PetscWeakFormSetIndexJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 1711475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1712475e0ac9SMatthew G. Knepley } 1713475e0ac9SMatthew G. Knepley 1714b7e05686SMatthew G. Knepley /*@C 1715b7e05686SMatthew G. Knepley PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set 1716b7e05686SMatthew G. Knepley 1717b7e05686SMatthew G. Knepley Not collective 1718b7e05686SMatthew G. Knepley 1719b7e05686SMatthew G. Knepley Input Parameter: 17206528b96dSMatthew G. Knepley . ds - The PetscDS 1721b7e05686SMatthew G. Knepley 1722b7e05686SMatthew G. Knepley Output Parameter: 1723b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set 1724b7e05686SMatthew G. Knepley 1725b7e05686SMatthew G. Knepley Level: intermediate 1726b7e05686SMatthew G. Knepley 1727b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian() 1728b7e05686SMatthew G. Knepley @*/ 17296528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS ds, PetscBool *hasDynJac) 1730b7e05686SMatthew G. Knepley { 17316528b96dSMatthew G. Knepley PetscErrorCode ierr; 1732b7e05686SMatthew G. Knepley 1733b7e05686SMatthew G. Knepley PetscFunctionBegin; 17346528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 17356528b96dSMatthew G. Knepley ierr = PetscWeakFormHasDynamicJacobian(ds->wf, hasDynJac);CHKERRQ(ierr); 1736b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1737b7e05686SMatthew G. Knepley } 1738b7e05686SMatthew G. Knepley 1739b7e05686SMatthew G. Knepley /*@C 1740b7e05686SMatthew G. Knepley PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field 1741b7e05686SMatthew G. Knepley 1742b7e05686SMatthew G. Knepley Not collective 1743b7e05686SMatthew G. Knepley 1744b7e05686SMatthew G. Knepley Input Parameters: 17456528b96dSMatthew G. Knepley + ds - The PetscDS 1746b7e05686SMatthew G. Knepley . f - The test field number 1747b7e05686SMatthew G. Knepley - g - The field number 1748b7e05686SMatthew G. Knepley 1749b7e05686SMatthew G. Knepley Output Parameters: 1750b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term 1751b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1752b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1753b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1754b7e05686SMatthew G. Knepley 1755b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1756b7e05686SMatthew G. Knepley 1757b7e05686SMatthew 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 1758b7e05686SMatthew G. Knepley 1759b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1760b7e05686SMatthew G. Knepley 1761b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1762b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1763b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1764b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1765b7e05686SMatthew G. Knepley 1766b7e05686SMatthew G. Knepley + dim - the spatial dimension 1767b7e05686SMatthew G. Knepley . Nf - the number of fields 1768b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1769b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1770b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1771b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1772b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1773b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1774b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1775b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1776b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1777b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1778b7e05686SMatthew G. Knepley . t - current time 1779b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1780b7e05686SMatthew G. Knepley . x - coordinates of the current point 178197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 178297b6e6e8SMatthew G. Knepley . constants - constant parameters 1783b7e05686SMatthew G. Knepley - g0 - output values at the current point 1784b7e05686SMatthew G. Knepley 1785b7e05686SMatthew G. Knepley Level: intermediate 1786b7e05686SMatthew G. Knepley 1787b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1788b7e05686SMatthew G. Knepley @*/ 17896528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g, 1790b7e05686SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1791b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1792b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 179397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1794b7e05686SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1795b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1796b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 179797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1798b7e05686SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1799b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1800b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 180197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1802b7e05686SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1803b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1804b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 180597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1806b7e05686SMatthew G. Knepley { 18076528b96dSMatthew G. Knepley PetscPointJac *tmp0, *tmp1, *tmp2, *tmp3; 18086528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 18096528b96dSMatthew G. Knepley PetscErrorCode ierr; 18106528b96dSMatthew G. Knepley 1811b7e05686SMatthew G. Knepley PetscFunctionBegin; 18126528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 18136528b96dSMatthew 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); 18146528b96dSMatthew 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); 181506ad1575SMatthew G. Knepley ierr = PetscWeakFormGetDynamicJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 18166528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 18176528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 18186528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 18196528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 1820b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1821b7e05686SMatthew G. Knepley } 1822b7e05686SMatthew G. Knepley 1823b7e05686SMatthew G. Knepley /*@C 1824b7e05686SMatthew G. Knepley PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields 1825b7e05686SMatthew G. Knepley 1826b7e05686SMatthew G. Knepley Not collective 1827b7e05686SMatthew G. Knepley 1828b7e05686SMatthew G. Knepley Input Parameters: 18296528b96dSMatthew G. Knepley + ds - The PetscDS 1830b7e05686SMatthew G. Knepley . f - The test field number 1831b7e05686SMatthew G. Knepley . g - The field number 1832b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term 1833b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1834b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1835b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1836b7e05686SMatthew G. Knepley 1837b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1838b7e05686SMatthew G. Knepley 1839b7e05686SMatthew 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 1840b7e05686SMatthew G. Knepley 1841b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1842b7e05686SMatthew G. Knepley 1843b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1844b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1845b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1846b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1847b7e05686SMatthew G. Knepley 1848b7e05686SMatthew G. Knepley + dim - the spatial dimension 1849b7e05686SMatthew G. Knepley . Nf - the number of fields 1850b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1851b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1852b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1853b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1854b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1855b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1856b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1857b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1858b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1859b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1860b7e05686SMatthew G. Knepley . t - current time 1861b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1862b7e05686SMatthew G. Knepley . x - coordinates of the current point 186397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 186497b6e6e8SMatthew G. Knepley . constants - constant parameters 1865b7e05686SMatthew G. Knepley - g0 - output values at the current point 1866b7e05686SMatthew G. Knepley 1867b7e05686SMatthew G. Knepley Level: intermediate 1868b7e05686SMatthew G. Knepley 1869b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1870b7e05686SMatthew G. Knepley @*/ 18716528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS ds, PetscInt f, PetscInt g, 1872b7e05686SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1873b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1874b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 187597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1876b7e05686SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1877b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1878b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 187997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1880b7e05686SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1881b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1882b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 188397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1884b7e05686SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1885b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1886b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 188797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1888b7e05686SMatthew G. Knepley { 1889b7e05686SMatthew G. Knepley PetscErrorCode ierr; 1890b7e05686SMatthew G. Knepley 1891b7e05686SMatthew G. Knepley PetscFunctionBegin; 18926528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1893b7e05686SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1894b7e05686SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1895b7e05686SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1896b7e05686SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1897b7e05686SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1898b7e05686SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 189906ad1575SMatthew G. Knepley ierr = PetscWeakFormSetIndexDynamicJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 1900b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1901b7e05686SMatthew G. Knepley } 1902b7e05686SMatthew G. Knepley 19030c2f2876SMatthew G. Knepley /*@C 19040c2f2876SMatthew G. Knepley PetscDSGetRiemannSolver - Returns the Riemann solver for the given field 19050c2f2876SMatthew G. Knepley 19060c2f2876SMatthew G. Knepley Not collective 19070c2f2876SMatthew G. Knepley 19084165533cSJose E. Roman Input Parameters: 19096528b96dSMatthew G. Knepley + ds - The PetscDS object 19100c2f2876SMatthew G. Knepley - f - The field number 19110c2f2876SMatthew G. Knepley 19124165533cSJose E. Roman Output Parameter: 19130c2f2876SMatthew G. Knepley . r - Riemann solver 19140c2f2876SMatthew G. Knepley 19150c2f2876SMatthew G. Knepley Calling sequence for r: 19160c2f2876SMatthew G. Knepley 19175db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 19180c2f2876SMatthew G. Knepley 19195db36cf9SMatthew G. Knepley + dim - The spatial dimension 19205db36cf9SMatthew G. Knepley . Nf - The number of fields 19215db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 19220c2f2876SMatthew G. Knepley . n - The normal vector to the interface 19230c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 19240c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 19250c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 192697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 192797b6e6e8SMatthew G. Knepley . constants - constant parameters 19280c2f2876SMatthew G. Knepley - ctx - optional user context 19290c2f2876SMatthew G. Knepley 19300c2f2876SMatthew G. Knepley Level: intermediate 19310c2f2876SMatthew G. Knepley 19320c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver() 19330c2f2876SMatthew G. Knepley @*/ 19346528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS ds, PetscInt f, 193597b6e6e8SMatthew 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)) 19360c2f2876SMatthew G. Knepley { 19376528b96dSMatthew G. Knepley PetscRiemannFunc *tmp; 19386528b96dSMatthew G. Knepley PetscInt n; 19396528b96dSMatthew G. Knepley PetscErrorCode ierr; 19406528b96dSMatthew G. Knepley 19410c2f2876SMatthew G. Knepley PetscFunctionBegin; 19426528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 19430c2f2876SMatthew G. Knepley PetscValidPointer(r, 3); 19446528b96dSMatthew 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); 194506ad1575SMatthew G. Knepley ierr = PetscWeakFormGetRiemannSolver(ds->wf, NULL, 0, f, 0, &n, &tmp);CHKERRQ(ierr); 19466528b96dSMatthew G. Knepley *r = tmp ? tmp[0] : NULL; 19470c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19480c2f2876SMatthew G. Knepley } 19490c2f2876SMatthew G. Knepley 19500c2f2876SMatthew G. Knepley /*@C 19510c2f2876SMatthew G. Knepley PetscDSSetRiemannSolver - Sets the Riemann solver for the given field 19520c2f2876SMatthew G. Knepley 19530c2f2876SMatthew G. Knepley Not collective 19540c2f2876SMatthew G. Knepley 19554165533cSJose E. Roman Input Parameters: 19566528b96dSMatthew G. Knepley + ds - The PetscDS object 19570c2f2876SMatthew G. Knepley . f - The field number 19580c2f2876SMatthew G. Knepley - r - Riemann solver 19590c2f2876SMatthew G. Knepley 19600c2f2876SMatthew G. Knepley Calling sequence for r: 19610c2f2876SMatthew G. Knepley 19625db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 19630c2f2876SMatthew G. Knepley 19645db36cf9SMatthew G. Knepley + dim - The spatial dimension 19655db36cf9SMatthew G. Knepley . Nf - The number of fields 19665db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 19670c2f2876SMatthew G. Knepley . n - The normal vector to the interface 19680c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 19690c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 19700c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 197197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 197297b6e6e8SMatthew G. Knepley . constants - constant parameters 19730c2f2876SMatthew G. Knepley - ctx - optional user context 19740c2f2876SMatthew G. Knepley 19750c2f2876SMatthew G. Knepley Level: intermediate 19760c2f2876SMatthew G. Knepley 19770c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver() 19780c2f2876SMatthew G. Knepley @*/ 19796528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS ds, PetscInt f, 198097b6e6e8SMatthew 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)) 19810c2f2876SMatthew G. Knepley { 19820c2f2876SMatthew G. Knepley PetscErrorCode ierr; 19830c2f2876SMatthew G. Knepley 19840c2f2876SMatthew G. Knepley PetscFunctionBegin; 19856528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 1986de716cbcSToby Isaac if (r) PetscValidFunction(r, 3); 19870c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 198806ad1575SMatthew G. Knepley ierr = PetscWeakFormSetIndexRiemannSolver(ds->wf, NULL, 0, f, 0, 0, r);CHKERRQ(ierr); 19890c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 19900c2f2876SMatthew G. Knepley } 19910c2f2876SMatthew G. Knepley 199232d2bbc9SMatthew G. Knepley /*@C 199332d2bbc9SMatthew G. Knepley PetscDSGetUpdate - Get the pointwise update function for a given field 199432d2bbc9SMatthew G. Knepley 199532d2bbc9SMatthew G. Knepley Not collective 199632d2bbc9SMatthew G. Knepley 199732d2bbc9SMatthew G. Knepley Input Parameters: 19986528b96dSMatthew G. Knepley + ds - The PetscDS 199932d2bbc9SMatthew G. Knepley - f - The field number 200032d2bbc9SMatthew G. Knepley 2001f899ff85SJose E. Roman Output Parameter: 2002a2b725a8SWilliam Gropp . update - update function 200332d2bbc9SMatthew G. Knepley 200432d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 200532d2bbc9SMatthew G. Knepley 200632d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 200732d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 200832d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 200932d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 201032d2bbc9SMatthew G. Knepley 201132d2bbc9SMatthew G. Knepley + dim - the spatial dimension 201232d2bbc9SMatthew G. Knepley . Nf - the number of fields 201332d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 201432d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 201532d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 201632d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 201732d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 201832d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 201932d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 202032d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 202132d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 202232d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 202332d2bbc9SMatthew G. Knepley . t - current time 202432d2bbc9SMatthew G. Knepley . x - coordinates of the current point 202532d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point 202632d2bbc9SMatthew G. Knepley 202732d2bbc9SMatthew G. Knepley Level: intermediate 202832d2bbc9SMatthew G. Knepley 202932d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual() 203032d2bbc9SMatthew G. Knepley @*/ 20316528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS ds, PetscInt f, 203232d2bbc9SMatthew G. Knepley void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 203332d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 203432d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 20353fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 203632d2bbc9SMatthew G. Knepley { 203732d2bbc9SMatthew G. Knepley PetscFunctionBegin; 20386528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 20396528b96dSMatthew 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); 20406528b96dSMatthew G. Knepley if (update) {PetscValidPointer(update, 3); *update = ds->update[f];} 204132d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 204232d2bbc9SMatthew G. Knepley } 204332d2bbc9SMatthew G. Knepley 204432d2bbc9SMatthew G. Knepley /*@C 20453fa77dffSMatthew G. Knepley PetscDSSetUpdate - Set the pointwise update function for a given field 204632d2bbc9SMatthew G. Knepley 204732d2bbc9SMatthew G. Knepley Not collective 204832d2bbc9SMatthew G. Knepley 204932d2bbc9SMatthew G. Knepley Input Parameters: 20506528b96dSMatthew G. Knepley + ds - The PetscDS 205132d2bbc9SMatthew G. Knepley . f - The field number 205232d2bbc9SMatthew G. Knepley - update - update function 205332d2bbc9SMatthew G. Knepley 205432d2bbc9SMatthew G. Knepley Note: The calling sequence for the callback update is given by: 205532d2bbc9SMatthew G. Knepley 205632d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux, 205732d2bbc9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 205832d2bbc9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 205932d2bbc9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar uNew[]) 206032d2bbc9SMatthew G. Knepley 206132d2bbc9SMatthew G. Knepley + dim - the spatial dimension 206232d2bbc9SMatthew G. Knepley . Nf - the number of fields 206332d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 206432d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 206532d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point 206632d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 206732d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 206832d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 206932d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 207032d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 207132d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 207232d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 207332d2bbc9SMatthew G. Knepley . t - current time 207432d2bbc9SMatthew G. Knepley . x - coordinates of the current point 207532d2bbc9SMatthew G. Knepley - uNew - new field values at the current point 207632d2bbc9SMatthew G. Knepley 207732d2bbc9SMatthew G. Knepley Level: intermediate 207832d2bbc9SMatthew G. Knepley 207932d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual() 208032d2bbc9SMatthew G. Knepley @*/ 20816528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS ds, PetscInt f, 208232d2bbc9SMatthew G. Knepley void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 208332d2bbc9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 208432d2bbc9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 20853fa77dffSMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[])) 208632d2bbc9SMatthew G. Knepley { 208732d2bbc9SMatthew G. Knepley PetscErrorCode ierr; 208832d2bbc9SMatthew G. Knepley 208932d2bbc9SMatthew G. Knepley PetscFunctionBegin; 20906528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 209132d2bbc9SMatthew G. Knepley if (update) PetscValidFunction(update, 3); 209232d2bbc9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 20936528b96dSMatthew G. Knepley ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr); 20946528b96dSMatthew G. Knepley ds->update[f] = update; 209532d2bbc9SMatthew G. Knepley PetscFunctionReturn(0); 209632d2bbc9SMatthew G. Knepley } 209732d2bbc9SMatthew G. Knepley 20983ec1f749SStefano Zampini PetscErrorCode PetscDSGetContext(PetscDS ds, PetscInt f, void *ctx) 20990c2f2876SMatthew G. Knepley { 21000c2f2876SMatthew G. Knepley PetscFunctionBegin; 21016528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 21026528b96dSMatthew 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); 21030c2f2876SMatthew G. Knepley PetscValidPointer(ctx, 3); 21043ec1f749SStefano Zampini *(void**)ctx = ds->ctx[f]; 21050c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 21060c2f2876SMatthew G. Knepley } 21070c2f2876SMatthew G. Knepley 21086528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS ds, PetscInt f, void *ctx) 21090c2f2876SMatthew G. Knepley { 21100c2f2876SMatthew G. Knepley PetscErrorCode ierr; 21110c2f2876SMatthew G. Knepley 21120c2f2876SMatthew G. Knepley PetscFunctionBegin; 21136528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 21140c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 21156528b96dSMatthew G. Knepley ierr = PetscDSEnlarge_Static(ds, f+1);CHKERRQ(ierr); 21166528b96dSMatthew G. Knepley ds->ctx[f] = ctx; 21170c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 21180c2f2876SMatthew G. Knepley } 21190c2f2876SMatthew G. Knepley 2120194d53e6SMatthew G. Knepley /*@C 2121194d53e6SMatthew G. Knepley PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field 2122194d53e6SMatthew G. Knepley 2123194d53e6SMatthew G. Knepley Not collective 2124194d53e6SMatthew G. Knepley 2125194d53e6SMatthew G. Knepley Input Parameters: 21266528b96dSMatthew G. Knepley + ds - The PetscDS 2127194d53e6SMatthew G. Knepley - f - The test field number 2128194d53e6SMatthew G. Knepley 2129194d53e6SMatthew G. Knepley Output Parameters: 2130194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term 2131194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2132194d53e6SMatthew G. Knepley 2133194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2134194d53e6SMatthew G. Knepley 2135194d53e6SMatthew 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 2136194d53e6SMatthew G. Knepley 2137194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2138194d53e6SMatthew G. Knepley 213930b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2140194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2141194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 214230b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2143194d53e6SMatthew G. Knepley 2144194d53e6SMatthew G. Knepley + dim - the spatial dimension 2145194d53e6SMatthew G. Knepley . Nf - the number of fields 2146194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2147194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2148194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2149194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2150194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2151194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2152194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2153194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2154194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2155194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2156194d53e6SMatthew G. Knepley . t - current time 2157194d53e6SMatthew G. Knepley . x - coordinates of the current point 2158194d53e6SMatthew G. Knepley . n - unit normal at the current point 215997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 216097b6e6e8SMatthew G. Knepley . constants - constant parameters 2161194d53e6SMatthew G. Knepley - f0 - output values at the current point 2162194d53e6SMatthew G. Knepley 2163194d53e6SMatthew G. Knepley Level: intermediate 2164194d53e6SMatthew G. Knepley 2165194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual() 2166194d53e6SMatthew G. Knepley @*/ 21676528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS ds, PetscInt f, 216830b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2169194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2170194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 217197b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 217230b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2173194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2174194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 217597b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 21762764a2aaSMatthew G. Knepley { 21776528b96dSMatthew G. Knepley PetscBdPointFunc *tmp0, *tmp1; 21786528b96dSMatthew G. Knepley PetscInt n0, n1; 21796528b96dSMatthew G. Knepley PetscErrorCode ierr; 21806528b96dSMatthew G. Knepley 21812764a2aaSMatthew G. Knepley PetscFunctionBegin; 21826528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 21836528b96dSMatthew 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); 218406ad1575SMatthew G. Knepley ierr = PetscWeakFormGetBdResidual(ds->wf, NULL, 0, f, 0, &n0, &tmp0, &n1, &tmp1);CHKERRQ(ierr); 21856528b96dSMatthew G. Knepley *f0 = tmp0 ? tmp0[0] : NULL; 21866528b96dSMatthew G. Knepley *f1 = tmp1 ? tmp1[0] : NULL; 21872764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21882764a2aaSMatthew G. Knepley } 21892764a2aaSMatthew G. Knepley 2190194d53e6SMatthew G. Knepley /*@C 2191194d53e6SMatthew G. Knepley PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field 2192194d53e6SMatthew G. Knepley 2193194d53e6SMatthew G. Knepley Not collective 2194194d53e6SMatthew G. Knepley 2195194d53e6SMatthew G. Knepley Input Parameters: 21966528b96dSMatthew G. Knepley + ds - The PetscDS 2197194d53e6SMatthew G. Knepley . f - The test field number 2198194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term 2199194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 2200194d53e6SMatthew G. Knepley 2201194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2202194d53e6SMatthew G. Knepley 2203194d53e6SMatthew 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 2204194d53e6SMatthew G. Knepley 2205194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 2206194d53e6SMatthew G. Knepley 220730b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2208194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2209194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 221030b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 2211194d53e6SMatthew G. Knepley 2212194d53e6SMatthew G. Knepley + dim - the spatial dimension 2213194d53e6SMatthew G. Knepley . Nf - the number of fields 2214194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2215194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2216194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2217194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2218194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2219194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2220194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2221194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2222194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2223194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2224194d53e6SMatthew G. Knepley . t - current time 2225194d53e6SMatthew G. Knepley . x - coordinates of the current point 2226194d53e6SMatthew G. Knepley . n - unit normal at the current point 222797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 222897b6e6e8SMatthew G. Knepley . constants - constant parameters 2229194d53e6SMatthew G. Knepley - f0 - output values at the current point 2230194d53e6SMatthew G. Knepley 2231194d53e6SMatthew G. Knepley Level: intermediate 2232194d53e6SMatthew G. Knepley 2233194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual() 2234194d53e6SMatthew G. Knepley @*/ 22356528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS ds, PetscInt f, 223630b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2237194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2238194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 223997b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 224030b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2241194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2242194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 224397b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 22442764a2aaSMatthew G. Knepley { 22452764a2aaSMatthew G. Knepley PetscErrorCode ierr; 22462764a2aaSMatthew G. Knepley 22472764a2aaSMatthew G. Knepley PetscFunctionBegin; 22486528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 22492764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 225006ad1575SMatthew G. Knepley ierr = PetscWeakFormSetIndexBdResidual(ds->wf, NULL, 0, f, 0, 0, f0, 0, f1);CHKERRQ(ierr); 22512764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22522764a2aaSMatthew G. Knepley } 22532764a2aaSMatthew G. Knepley 225427f02ce8SMatthew G. Knepley /*@ 225527f02ce8SMatthew G. Knepley PetscDSHasBdJacobian - Signals that boundary Jacobian functions have been set 225627f02ce8SMatthew G. Knepley 225727f02ce8SMatthew G. Knepley Not collective 225827f02ce8SMatthew G. Knepley 225927f02ce8SMatthew G. Knepley Input Parameter: 22606528b96dSMatthew G. Knepley . ds - The PetscDS 226127f02ce8SMatthew G. Knepley 226227f02ce8SMatthew G. Knepley Output Parameter: 226327f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian has been set 226427f02ce8SMatthew G. Knepley 226527f02ce8SMatthew G. Knepley Level: intermediate 226627f02ce8SMatthew G. Knepley 226727f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian() 226827f02ce8SMatthew G. Knepley @*/ 22696528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobian(PetscDS ds, PetscBool *hasBdJac) 227027f02ce8SMatthew G. Knepley { 22716528b96dSMatthew G. Knepley PetscErrorCode ierr; 227227f02ce8SMatthew G. Knepley 227327f02ce8SMatthew G. Knepley PetscFunctionBegin; 22746528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 22756528b96dSMatthew G. Knepley PetscValidBoolPointer(hasBdJac, 2); 22766528b96dSMatthew G. Knepley ierr = PetscWeakFormHasBdJacobian(ds->wf, hasBdJac);CHKERRQ(ierr); 227727f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 227827f02ce8SMatthew G. Knepley } 227927f02ce8SMatthew G. Knepley 2280194d53e6SMatthew G. Knepley /*@C 2281194d53e6SMatthew G. Knepley PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field 2282194d53e6SMatthew G. Knepley 2283194d53e6SMatthew G. Knepley Not collective 2284194d53e6SMatthew G. Knepley 2285194d53e6SMatthew G. Knepley Input Parameters: 22866528b96dSMatthew G. Knepley + ds - The PetscDS 2287194d53e6SMatthew G. Knepley . f - The test field number 2288194d53e6SMatthew G. Knepley - g - The field number 2289194d53e6SMatthew G. Knepley 2290194d53e6SMatthew G. Knepley Output Parameters: 2291194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 2292194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2293194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2294194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2295194d53e6SMatthew G. Knepley 2296194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2297194d53e6SMatthew G. Knepley 2298194d53e6SMatthew 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 2299194d53e6SMatthew G. Knepley 2300194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2301194d53e6SMatthew G. Knepley 230230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2303194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2304194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 230530b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2306194d53e6SMatthew G. Knepley 2307194d53e6SMatthew G. Knepley + dim - the spatial dimension 2308194d53e6SMatthew G. Knepley . Nf - the number of fields 2309194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2310194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2311194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2312194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2313194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2314194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2315194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2316194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2317194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2318194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2319194d53e6SMatthew G. Knepley . t - current time 23202aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2321194d53e6SMatthew G. Knepley . x - coordinates of the current point 2322194d53e6SMatthew G. Knepley . n - normal at the current point 232397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 232497b6e6e8SMatthew G. Knepley . constants - constant parameters 2325194d53e6SMatthew G. Knepley - g0 - output values at the current point 2326194d53e6SMatthew G. Knepley 2327194d53e6SMatthew G. Knepley Level: intermediate 2328194d53e6SMatthew G. Knepley 2329194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian() 2330194d53e6SMatthew G. Knepley @*/ 23316528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS ds, PetscInt f, PetscInt g, 233230b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2333194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2334194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 233597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 233630b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2337194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2338194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 233997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 234030b9ff8bSMatthew G. Knepley void (**g2)(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 g2[]), 234430b9ff8bSMatthew G. Knepley void (**g3)(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 g3[])) 23482764a2aaSMatthew G. Knepley { 23496528b96dSMatthew G. Knepley PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3; 23506528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 23516528b96dSMatthew G. Knepley PetscErrorCode ierr; 23526528b96dSMatthew G. Knepley 23532764a2aaSMatthew G. Knepley PetscFunctionBegin; 23546528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 23556528b96dSMatthew 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); 23566528b96dSMatthew 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); 235706ad1575SMatthew G. Knepley ierr = PetscWeakFormGetBdJacobian(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 23586528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 23596528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 23606528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 23616528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 23622764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 23632764a2aaSMatthew G. Knepley } 23642764a2aaSMatthew G. Knepley 2365194d53e6SMatthew G. Knepley /*@C 2366194d53e6SMatthew G. Knepley PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field 2367194d53e6SMatthew G. Knepley 2368194d53e6SMatthew G. Knepley Not collective 2369194d53e6SMatthew G. Knepley 2370194d53e6SMatthew G. Knepley Input Parameters: 23716528b96dSMatthew G. Knepley + ds - The PetscDS 2372194d53e6SMatthew G. Knepley . f - The test field number 2373194d53e6SMatthew G. Knepley . g - The field number 2374194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 2375194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 2376194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 2377194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 2378194d53e6SMatthew G. Knepley 2379194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 2380194d53e6SMatthew G. Knepley 2381194d53e6SMatthew 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 2382194d53e6SMatthew G. Knepley 2383194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 2384194d53e6SMatthew G. Knepley 238530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2386194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2387194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 238830b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 2389194d53e6SMatthew G. Knepley 2390194d53e6SMatthew G. Knepley + dim - the spatial dimension 2391194d53e6SMatthew G. Knepley . Nf - the number of fields 2392194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 2393194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 2394194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 2395194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 2396194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 2397194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 2398194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 2399194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 2400194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 2401194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 2402194d53e6SMatthew G. Knepley . t - current time 24032aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 2404194d53e6SMatthew G. Knepley . x - coordinates of the current point 2405194d53e6SMatthew G. Knepley . n - normal at the current point 240697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 240797b6e6e8SMatthew G. Knepley . constants - constant parameters 2408194d53e6SMatthew G. Knepley - g0 - output values at the current point 2409194d53e6SMatthew G. Knepley 2410194d53e6SMatthew G. Knepley Level: intermediate 2411194d53e6SMatthew G. Knepley 2412194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian() 2413194d53e6SMatthew G. Knepley @*/ 24146528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS ds, PetscInt f, PetscInt g, 241530b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2416194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2417194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 241897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 241930b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2420194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2421194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 242297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 242330b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2424194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2425194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 242697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 242730b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 2428194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 2429194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 243097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 24312764a2aaSMatthew G. Knepley { 24322764a2aaSMatthew G. Knepley PetscErrorCode ierr; 24332764a2aaSMatthew G. Knepley 24342764a2aaSMatthew G. Knepley PetscFunctionBegin; 24356528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 24362764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 24372764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 24382764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 24392764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 24402764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 24412764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 244206ad1575SMatthew G. Knepley ierr = PetscWeakFormSetIndexBdJacobian(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 24432764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 24442764a2aaSMatthew G. Knepley } 24452764a2aaSMatthew G. Knepley 244627f02ce8SMatthew G. Knepley /*@ 244727f02ce8SMatthew G. Knepley PetscDSHasBdJacobianPreconditioner - Signals that boundary Jacobian preconditioner functions have been set 244827f02ce8SMatthew G. Knepley 244927f02ce8SMatthew G. Knepley Not collective 245027f02ce8SMatthew G. Knepley 245127f02ce8SMatthew G. Knepley Input Parameter: 24526528b96dSMatthew G. Knepley . ds - The PetscDS 245327f02ce8SMatthew G. Knepley 245427f02ce8SMatthew G. Knepley Output Parameter: 245527f02ce8SMatthew G. Knepley . hasBdJac - flag that pointwise function for the boundary Jacobian preconditioner has been set 245627f02ce8SMatthew G. Knepley 245727f02ce8SMatthew G. Knepley Level: intermediate 245827f02ce8SMatthew G. Knepley 245927f02ce8SMatthew G. Knepley .seealso: PetscDSHasJacobian(), PetscDSSetBdJacobian(), PetscDSGetBdJacobian() 246027f02ce8SMatthew G. Knepley @*/ 24616528b96dSMatthew G. Knepley PetscErrorCode PetscDSHasBdJacobianPreconditioner(PetscDS ds, PetscBool *hasBdJacPre) 246227f02ce8SMatthew G. Knepley { 24636528b96dSMatthew G. Knepley PetscErrorCode ierr; 246427f02ce8SMatthew G. Knepley 246527f02ce8SMatthew G. Knepley PetscFunctionBegin; 24666528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 24676528b96dSMatthew G. Knepley PetscValidBoolPointer(hasBdJacPre, 2); 24686528b96dSMatthew G. Knepley ierr = PetscWeakFormHasBdJacobianPreconditioner(ds->wf, hasBdJacPre);CHKERRQ(ierr); 246927f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 247027f02ce8SMatthew G. Knepley } 247127f02ce8SMatthew G. Knepley 247227f02ce8SMatthew G. Knepley /*@C 247327f02ce8SMatthew G. Knepley PetscDSGetBdJacobianPreconditioner - Get the pointwise boundary Jacobian preconditioner function for given test and basis field 247427f02ce8SMatthew G. Knepley 247527f02ce8SMatthew G. Knepley Not collective 247627f02ce8SMatthew G. Knepley 247727f02ce8SMatthew G. Knepley Input Parameters: 24786528b96dSMatthew G. Knepley + ds - The PetscDS 247927f02ce8SMatthew G. Knepley . f - The test field number 248027f02ce8SMatthew G. Knepley - g - The field number 248127f02ce8SMatthew G. Knepley 248227f02ce8SMatthew G. Knepley Output Parameters: 248327f02ce8SMatthew G. Knepley + g0 - integrand for the test and basis function term 248427f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 248527f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 248627f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 248727f02ce8SMatthew G. Knepley 248827f02ce8SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 248927f02ce8SMatthew G. Knepley 249027f02ce8SMatthew 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 249127f02ce8SMatthew G. Knepley 249227f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 249327f02ce8SMatthew G. Knepley 249427f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 249527f02ce8SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 249627f02ce8SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 249727f02ce8SMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 249827f02ce8SMatthew G. Knepley 249927f02ce8SMatthew G. Knepley + dim - the spatial dimension 250027f02ce8SMatthew G. Knepley . Nf - the number of fields 250127f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 250227f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 250327f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 250427f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 250527f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 250627f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 250727f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 250827f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 250927f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 251027f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 251127f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 251227f02ce8SMatthew G. Knepley . t - current time 251327f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 251427f02ce8SMatthew G. Knepley . x - coordinates of the current point 251527f02ce8SMatthew G. Knepley . n - normal at the current point 251627f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 251727f02ce8SMatthew G. Knepley . constants - constant parameters 251827f02ce8SMatthew G. Knepley - g0 - output values at the current point 251927f02ce8SMatthew G. Knepley 252027f02ce8SMatthew G. Knepley This is not yet available in Fortran. 252127f02ce8SMatthew G. Knepley 252227f02ce8SMatthew G. Knepley Level: intermediate 252327f02ce8SMatthew G. Knepley 252427f02ce8SMatthew G. Knepley .seealso: PetscDSSetBdJacobianPreconditioner() 252527f02ce8SMatthew G. Knepley @*/ 25266528b96dSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, 252727f02ce8SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 252827f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 252927f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 253027f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 253127f02ce8SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 253227f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 253327f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 253427f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 253527f02ce8SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 253627f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 253727f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 253827f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 253927f02ce8SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 254027f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 254127f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 254227f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 254327f02ce8SMatthew G. Knepley { 25446528b96dSMatthew G. Knepley PetscBdPointJac *tmp0, *tmp1, *tmp2, *tmp3; 25456528b96dSMatthew G. Knepley PetscInt n0, n1, n2, n3; 25466528b96dSMatthew G. Knepley PetscErrorCode ierr; 25476528b96dSMatthew G. Knepley 254827f02ce8SMatthew G. Knepley PetscFunctionBegin; 25496528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 25506528b96dSMatthew 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); 25516528b96dSMatthew 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); 255206ad1575SMatthew G. Knepley ierr = PetscWeakFormGetBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, &n0, &tmp0, &n1, &tmp1, &n2, &tmp2, &n3, &tmp3);CHKERRQ(ierr); 25536528b96dSMatthew G. Knepley *g0 = tmp0 ? tmp0[0] : NULL; 25546528b96dSMatthew G. Knepley *g1 = tmp1 ? tmp1[0] : NULL; 25556528b96dSMatthew G. Knepley *g2 = tmp2 ? tmp2[0] : NULL; 25566528b96dSMatthew G. Knepley *g3 = tmp3 ? tmp3[0] : NULL; 255727f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 255827f02ce8SMatthew G. Knepley } 255927f02ce8SMatthew G. Knepley 256027f02ce8SMatthew G. Knepley /*@C 256127f02ce8SMatthew G. Knepley PetscDSSetBdJacobianPreconditioner - Set the pointwise boundary Jacobian preconditioner function for given test and basis field 256227f02ce8SMatthew G. Knepley 256327f02ce8SMatthew G. Knepley Not collective 256427f02ce8SMatthew G. Knepley 256527f02ce8SMatthew G. Knepley Input Parameters: 25666528b96dSMatthew G. Knepley + ds - The PetscDS 256727f02ce8SMatthew G. Knepley . f - The test field number 256827f02ce8SMatthew G. Knepley . g - The field number 256927f02ce8SMatthew G. Knepley . g0 - integrand for the test and basis function term 257027f02ce8SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 257127f02ce8SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 257227f02ce8SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 257327f02ce8SMatthew G. Knepley 257427f02ce8SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 257527f02ce8SMatthew G. Knepley 257627f02ce8SMatthew 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 257727f02ce8SMatthew G. Knepley 257827f02ce8SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 257927f02ce8SMatthew G. Knepley 258027f02ce8SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 258127f02ce8SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 258227f02ce8SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 258327f02ce8SMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 258427f02ce8SMatthew G. Knepley 258527f02ce8SMatthew G. Knepley + dim - the spatial dimension 258627f02ce8SMatthew G. Knepley . Nf - the number of fields 258727f02ce8SMatthew G. Knepley . NfAux - the number of auxiliary fields 258827f02ce8SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 258927f02ce8SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 259027f02ce8SMatthew G. Knepley . u - each field evaluated at the current point 259127f02ce8SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 259227f02ce8SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 259327f02ce8SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 259427f02ce8SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 259527f02ce8SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 259627f02ce8SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 259727f02ce8SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 259827f02ce8SMatthew G. Knepley . t - current time 259927f02ce8SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 260027f02ce8SMatthew G. Knepley . x - coordinates of the current point 260127f02ce8SMatthew G. Knepley . n - normal at the current point 260227f02ce8SMatthew G. Knepley . numConstants - number of constant parameters 260327f02ce8SMatthew G. Knepley . constants - constant parameters 260427f02ce8SMatthew G. Knepley - g0 - output values at the current point 260527f02ce8SMatthew G. Knepley 260627f02ce8SMatthew G. Knepley This is not yet available in Fortran. 260727f02ce8SMatthew G. Knepley 260827f02ce8SMatthew G. Knepley Level: intermediate 260927f02ce8SMatthew G. Knepley 261027f02ce8SMatthew G. Knepley .seealso: PetscDSGetBdJacobianPreconditioner() 261127f02ce8SMatthew G. Knepley @*/ 26126528b96dSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobianPreconditioner(PetscDS ds, PetscInt f, PetscInt g, 261327f02ce8SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 261427f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 261527f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 261627f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 261727f02ce8SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 261827f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 261927f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 262027f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 262127f02ce8SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 262227f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 262327f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 262427f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 262527f02ce8SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 262627f02ce8SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 262727f02ce8SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 262827f02ce8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 262927f02ce8SMatthew G. Knepley { 263027f02ce8SMatthew G. Knepley PetscErrorCode ierr; 263127f02ce8SMatthew G. Knepley 263227f02ce8SMatthew G. Knepley PetscFunctionBegin; 26336528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 263427f02ce8SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 263527f02ce8SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 263627f02ce8SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 263727f02ce8SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 263827f02ce8SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 263927f02ce8SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 264006ad1575SMatthew G. Knepley ierr = PetscWeakFormSetIndexBdJacobianPreconditioner(ds->wf, NULL, 0, f, g, 0, 0, g0, 0, g1, 0, g2, 0, g3);CHKERRQ(ierr); 264127f02ce8SMatthew G. Knepley PetscFunctionReturn(0); 264227f02ce8SMatthew G. Knepley } 264327f02ce8SMatthew G. Knepley 26440d3e9b51SMatthew G. Knepley /*@C 2645c371a6d1SMatthew G. Knepley PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field 2646c371a6d1SMatthew G. Knepley 2647c371a6d1SMatthew G. Knepley Not collective 2648c371a6d1SMatthew G. Knepley 2649c371a6d1SMatthew G. Knepley Input Parameters: 2650c371a6d1SMatthew G. Knepley + prob - The PetscDS 2651c371a6d1SMatthew G. Knepley - f - The test field number 2652c371a6d1SMatthew G. Knepley 2653d8d19677SJose E. Roman Output Parameters: 265495cbbfd3SMatthew G. Knepley + exactSol - exact solution for the test field 265595cbbfd3SMatthew G. Knepley - exactCtx - exact solution context 2656c371a6d1SMatthew G. Knepley 2657c371a6d1SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2658c371a6d1SMatthew G. Knepley 2659c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2660c371a6d1SMatthew G. Knepley 2661c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2662c371a6d1SMatthew G. Knepley . t - current time 2663c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2664c371a6d1SMatthew G. Knepley . Nc - the number of field components 2665c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2666c371a6d1SMatthew G. Knepley - ctx - a user context 2667c371a6d1SMatthew G. Knepley 2668c371a6d1SMatthew G. Knepley Level: intermediate 2669c371a6d1SMatthew G. Knepley 2670f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolution(), PetscDSGetExactSolutionTimeDerivative() 2671c371a6d1SMatthew G. Knepley @*/ 267295cbbfd3SMatthew 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) 2673c371a6d1SMatthew G. Knepley { 2674c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2675c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2676c371a6d1SMatthew 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); 2677c371a6d1SMatthew G. Knepley if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];} 267895cbbfd3SMatthew G. Knepley if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx[f];} 2679c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2680c371a6d1SMatthew G. Knepley } 2681c371a6d1SMatthew G. Knepley 2682c371a6d1SMatthew G. Knepley /*@C 2683578a5ef5SMatthew Knepley PetscDSSetExactSolution - Set the pointwise exact solution function for a given test field 2684c371a6d1SMatthew G. Knepley 2685c371a6d1SMatthew G. Knepley Not collective 2686c371a6d1SMatthew G. Knepley 2687c371a6d1SMatthew G. Knepley Input Parameters: 2688c371a6d1SMatthew G. Knepley + prob - The PetscDS 2689c371a6d1SMatthew G. Knepley . f - The test field number 269095cbbfd3SMatthew G. Knepley . sol - solution function for the test fields 269195cbbfd3SMatthew G. Knepley - ctx - solution context or NULL 2692c371a6d1SMatthew G. Knepley 2693c371a6d1SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2694c371a6d1SMatthew G. Knepley 2695c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2696c371a6d1SMatthew G. Knepley 2697c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2698c371a6d1SMatthew G. Knepley . t - current time 2699c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2700c371a6d1SMatthew G. Knepley . Nc - the number of field components 2701c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2702c371a6d1SMatthew G. Knepley - ctx - a user context 2703c371a6d1SMatthew G. Knepley 2704c371a6d1SMatthew G. Knepley Level: intermediate 2705c371a6d1SMatthew G. Knepley 2706c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution() 2707c371a6d1SMatthew G. Knepley @*/ 270895cbbfd3SMatthew 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) 2709c371a6d1SMatthew G. Knepley { 2710c371a6d1SMatthew G. Knepley PetscErrorCode ierr; 2711c371a6d1SMatthew G. Knepley 2712c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2713c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2714c371a6d1SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 2715c371a6d1SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 2716c371a6d1SMatthew G. Knepley if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;} 271795cbbfd3SMatthew G. Knepley if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx[f] = ctx;} 2718c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2719c371a6d1SMatthew G. Knepley } 2720c371a6d1SMatthew G. Knepley 27215638fd0eSMatthew G. Knepley /*@C 2722f2cacb80SMatthew G. Knepley PetscDSGetExactSolutionTimeDerivative - Get the pointwise time derivative of the exact solution function for a given test field 2723f2cacb80SMatthew G. Knepley 2724f2cacb80SMatthew G. Knepley Not collective 2725f2cacb80SMatthew G. Knepley 2726f2cacb80SMatthew G. Knepley Input Parameters: 2727f2cacb80SMatthew G. Knepley + prob - The PetscDS 2728f2cacb80SMatthew G. Knepley - f - The test field number 2729f2cacb80SMatthew G. Knepley 2730d8d19677SJose E. Roman Output Parameters: 2731f2cacb80SMatthew G. Knepley + exactSol - time derivative of the exact solution for the test field 2732f2cacb80SMatthew G. Knepley - exactCtx - time derivative of the exact solution context 2733f2cacb80SMatthew G. Knepley 2734f2cacb80SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 2735f2cacb80SMatthew G. Knepley 2736f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2737f2cacb80SMatthew G. Knepley 2738f2cacb80SMatthew G. Knepley + dim - the spatial dimension 2739f2cacb80SMatthew G. Knepley . t - current time 2740f2cacb80SMatthew G. Knepley . x - coordinates of the current point 2741f2cacb80SMatthew G. Knepley . Nc - the number of field components 2742f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point 2743f2cacb80SMatthew G. Knepley - ctx - a user context 2744f2cacb80SMatthew G. Knepley 2745f2cacb80SMatthew G. Knepley Level: intermediate 2746f2cacb80SMatthew G. Knepley 2747f2cacb80SMatthew G. Knepley .seealso: PetscDSSetExactSolutionTimeDerivative(), PetscDSGetExactSolution() 2748f2cacb80SMatthew G. Knepley @*/ 2749f2cacb80SMatthew 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) 2750f2cacb80SMatthew G. Knepley { 2751f2cacb80SMatthew G. Knepley PetscFunctionBegin; 2752f2cacb80SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2753f2cacb80SMatthew 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); 2754f2cacb80SMatthew G. Knepley if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol_t[f];} 2755f2cacb80SMatthew G. Knepley if (ctx) {PetscValidPointer(ctx, 4); *ctx = prob->exactCtx_t[f];} 2756f2cacb80SMatthew G. Knepley PetscFunctionReturn(0); 2757f2cacb80SMatthew G. Knepley } 2758f2cacb80SMatthew G. Knepley 2759f2cacb80SMatthew G. Knepley /*@C 2760f2cacb80SMatthew G. Knepley PetscDSSetExactSolutionTimeDerivative - Set the pointwise time derivative of the exact solution function for a given test field 2761f2cacb80SMatthew G. Knepley 2762f2cacb80SMatthew G. Knepley Not collective 2763f2cacb80SMatthew G. Knepley 2764f2cacb80SMatthew G. Knepley Input Parameters: 2765f2cacb80SMatthew G. Knepley + prob - The PetscDS 2766f2cacb80SMatthew G. Knepley . f - The test field number 2767f2cacb80SMatthew G. Knepley . sol - time derivative of the solution function for the test fields 2768f2cacb80SMatthew G. Knepley - ctx - time derivative of the solution context or NULL 2769f2cacb80SMatthew G. Knepley 2770f2cacb80SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2771f2cacb80SMatthew G. Knepley 2772f2cacb80SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2773f2cacb80SMatthew G. Knepley 2774f2cacb80SMatthew G. Knepley + dim - the spatial dimension 2775f2cacb80SMatthew G. Knepley . t - current time 2776f2cacb80SMatthew G. Knepley . x - coordinates of the current point 2777f2cacb80SMatthew G. Knepley . Nc - the number of field components 2778f2cacb80SMatthew G. Knepley . u - the solution field evaluated at the current point 2779f2cacb80SMatthew G. Knepley - ctx - a user context 2780f2cacb80SMatthew G. Knepley 2781f2cacb80SMatthew G. Knepley Level: intermediate 2782f2cacb80SMatthew G. Knepley 2783f2cacb80SMatthew G. Knepley .seealso: PetscDSGetExactSolutionTimeDerivative(), PetscDSSetExactSolution() 2784f2cacb80SMatthew G. Knepley @*/ 2785f2cacb80SMatthew 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) 2786f2cacb80SMatthew G. Knepley { 2787f2cacb80SMatthew G. Knepley PetscErrorCode ierr; 2788f2cacb80SMatthew G. Knepley 2789f2cacb80SMatthew G. Knepley PetscFunctionBegin; 2790f2cacb80SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2791f2cacb80SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 2792f2cacb80SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 2793f2cacb80SMatthew G. Knepley if (sol) {PetscValidFunction(sol, 3); prob->exactSol_t[f] = sol;} 2794f2cacb80SMatthew G. Knepley if (ctx) {PetscValidFunction(ctx, 4); prob->exactCtx_t[f] = ctx;} 2795f2cacb80SMatthew G. Knepley PetscFunctionReturn(0); 2796f2cacb80SMatthew G. Knepley } 2797f2cacb80SMatthew G. Knepley 2798f2cacb80SMatthew G. Knepley /*@C 279997b6e6e8SMatthew G. Knepley PetscDSGetConstants - Returns the array of constants passed to point functions 280097b6e6e8SMatthew G. Knepley 280197b6e6e8SMatthew G. Knepley Not collective 280297b6e6e8SMatthew G. Knepley 280397b6e6e8SMatthew G. Knepley Input Parameter: 280497b6e6e8SMatthew G. Knepley . prob - The PetscDS object 280597b6e6e8SMatthew G. Knepley 280697b6e6e8SMatthew G. Knepley Output Parameters: 280797b6e6e8SMatthew G. Knepley + numConstants - The number of constants 280897b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 280997b6e6e8SMatthew G. Knepley 281097b6e6e8SMatthew G. Knepley Level: intermediate 281197b6e6e8SMatthew G. Knepley 281297b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate() 281397b6e6e8SMatthew G. Knepley @*/ 281497b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[]) 281597b6e6e8SMatthew G. Knepley { 281697b6e6e8SMatthew G. Knepley PetscFunctionBegin; 281797b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 281897b6e6e8SMatthew G. Knepley if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;} 281997b6e6e8SMatthew G. Knepley if (constants) {PetscValidPointer(constants, 3); *constants = prob->constants;} 282097b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 282197b6e6e8SMatthew G. Knepley } 282297b6e6e8SMatthew G. Knepley 28230d3e9b51SMatthew G. Knepley /*@C 282497b6e6e8SMatthew G. Knepley PetscDSSetConstants - Set the array of constants passed to point functions 282597b6e6e8SMatthew G. Knepley 282697b6e6e8SMatthew G. Knepley Not collective 282797b6e6e8SMatthew G. Knepley 282897b6e6e8SMatthew G. Knepley Input Parameters: 282997b6e6e8SMatthew G. Knepley + prob - The PetscDS object 283097b6e6e8SMatthew G. Knepley . numConstants - The number of constants 283197b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 283297b6e6e8SMatthew G. Knepley 283397b6e6e8SMatthew G. Knepley Level: intermediate 283497b6e6e8SMatthew G. Knepley 283597b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate() 283697b6e6e8SMatthew G. Knepley @*/ 283797b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[]) 283897b6e6e8SMatthew G. Knepley { 283997b6e6e8SMatthew G. Knepley PetscErrorCode ierr; 284097b6e6e8SMatthew G. Knepley 284197b6e6e8SMatthew G. Knepley PetscFunctionBegin; 284297b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 284397b6e6e8SMatthew G. Knepley if (numConstants != prob->numConstants) { 284497b6e6e8SMatthew G. Knepley ierr = PetscFree(prob->constants);CHKERRQ(ierr); 284597b6e6e8SMatthew G. Knepley prob->numConstants = numConstants; 284697b6e6e8SMatthew G. Knepley if (prob->numConstants) { 284797b6e6e8SMatthew G. Knepley ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr); 284820be0f5bSMatthew G. Knepley } else { 284920be0f5bSMatthew G. Knepley prob->constants = NULL; 285020be0f5bSMatthew G. Knepley } 285120be0f5bSMatthew G. Knepley } 285220be0f5bSMatthew G. Knepley if (prob->numConstants) { 285320be0f5bSMatthew G. Knepley PetscValidPointer(constants, 3); 2854580bdb30SBarry Smith ierr = PetscArraycpy(prob->constants, constants, prob->numConstants);CHKERRQ(ierr); 285597b6e6e8SMatthew G. Knepley } 285697b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 285797b6e6e8SMatthew G. Knepley } 285897b6e6e8SMatthew G. Knepley 28594cd1e086SMatthew G. Knepley /*@ 28604cd1e086SMatthew G. Knepley PetscDSGetFieldIndex - Returns the index of the given field 28614cd1e086SMatthew G. Knepley 28624cd1e086SMatthew G. Knepley Not collective 28634cd1e086SMatthew G. Knepley 28644cd1e086SMatthew G. Knepley Input Parameters: 28654cd1e086SMatthew G. Knepley + prob - The PetscDS object 28664cd1e086SMatthew G. Knepley - disc - The discretization object 28674cd1e086SMatthew G. Knepley 28684cd1e086SMatthew G. Knepley Output Parameter: 28694cd1e086SMatthew G. Knepley . f - The field number 28704cd1e086SMatthew G. Knepley 28714cd1e086SMatthew G. Knepley Level: beginner 28724cd1e086SMatthew G. Knepley 2873f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 28744cd1e086SMatthew G. Knepley @*/ 28754cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f) 28764cd1e086SMatthew G. Knepley { 28774cd1e086SMatthew G. Knepley PetscInt g; 28784cd1e086SMatthew G. Knepley 28794cd1e086SMatthew G. Knepley PetscFunctionBegin; 28804cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 28814cd1e086SMatthew G. Knepley PetscValidPointer(f, 3); 28824cd1e086SMatthew G. Knepley *f = -1; 28834cd1e086SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;} 28844cd1e086SMatthew G. Knepley if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS."); 28854cd1e086SMatthew G. Knepley *f = g; 28864cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 28874cd1e086SMatthew G. Knepley } 28884cd1e086SMatthew G. Knepley 28894cd1e086SMatthew G. Knepley /*@ 28904cd1e086SMatthew G. Knepley PetscDSGetFieldSize - Returns the size of the given field in the full space basis 28914cd1e086SMatthew G. Knepley 28924cd1e086SMatthew G. Knepley Not collective 28934cd1e086SMatthew G. Knepley 28944cd1e086SMatthew G. Knepley Input Parameters: 28954cd1e086SMatthew G. Knepley + prob - The PetscDS object 28964cd1e086SMatthew G. Knepley - f - The field number 28974cd1e086SMatthew G. Knepley 28984cd1e086SMatthew G. Knepley Output Parameter: 28994cd1e086SMatthew G. Knepley . size - The size 29004cd1e086SMatthew G. Knepley 29014cd1e086SMatthew G. Knepley Level: beginner 29024cd1e086SMatthew G. Knepley 2903f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate() 29044cd1e086SMatthew G. Knepley @*/ 29054cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size) 29064cd1e086SMatthew G. Knepley { 29072166fd64SMatthew G. Knepley PetscErrorCode ierr; 29082166fd64SMatthew G. Knepley 29094cd1e086SMatthew G. Knepley PetscFunctionBegin; 29104cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 29114cd1e086SMatthew G. Knepley PetscValidPointer(size, 3); 29124cd1e086SMatthew 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); 29132166fd64SMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2914d4742ddaSMatthew G. Knepley *size = prob->Nb[f]; 29154cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 29164cd1e086SMatthew G. Knepley } 29174cd1e086SMatthew G. Knepley 2918bc4ae4beSMatthew G. Knepley /*@ 2919bc4ae4beSMatthew G. Knepley PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis 2920bc4ae4beSMatthew G. Knepley 2921bc4ae4beSMatthew G. Knepley Not collective 2922bc4ae4beSMatthew G. Knepley 2923bc4ae4beSMatthew G. Knepley Input Parameters: 2924bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 2925bc4ae4beSMatthew G. Knepley - f - The field number 2926bc4ae4beSMatthew G. Knepley 2927bc4ae4beSMatthew G. Knepley Output Parameter: 2928bc4ae4beSMatthew G. Knepley . off - The offset 2929bc4ae4beSMatthew G. Knepley 2930bc4ae4beSMatthew G. Knepley Level: beginner 2931bc4ae4beSMatthew G. Knepley 2932f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate() 2933bc4ae4beSMatthew G. Knepley @*/ 29342764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 29352764a2aaSMatthew G. Knepley { 29364cd1e086SMatthew G. Knepley PetscInt size, g; 29372764a2aaSMatthew G. Knepley PetscErrorCode ierr; 29382764a2aaSMatthew G. Knepley 29392764a2aaSMatthew G. Knepley PetscFunctionBegin; 29402764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 29412764a2aaSMatthew G. Knepley PetscValidPointer(off, 3); 29422764a2aaSMatthew 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); 29432764a2aaSMatthew G. Knepley *off = 0; 29442764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 29454cd1e086SMatthew G. Knepley ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr); 29464cd1e086SMatthew G. Knepley *off += size; 29472764a2aaSMatthew G. Knepley } 29482764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 29492764a2aaSMatthew G. Knepley } 29502764a2aaSMatthew G. Knepley 2951bc4ae4beSMatthew G. Knepley /*@ 2952*5fedec97SMatthew G. Knepley PetscDSGetFieldOffsetCohesive - Returns the offset of the given field in the full space basis on a cohesive cell 2953*5fedec97SMatthew G. Knepley 2954*5fedec97SMatthew G. Knepley Not collective 2955*5fedec97SMatthew G. Knepley 2956*5fedec97SMatthew G. Knepley Input Parameters: 2957*5fedec97SMatthew G. Knepley + prob - The PetscDS object 2958*5fedec97SMatthew G. Knepley - f - The field number 2959*5fedec97SMatthew G. Knepley 2960*5fedec97SMatthew G. Knepley Output Parameter: 2961*5fedec97SMatthew G. Knepley . off - The offset 2962*5fedec97SMatthew G. Knepley 2963*5fedec97SMatthew G. Knepley Level: beginner 2964*5fedec97SMatthew G. Knepley 2965*5fedec97SMatthew G. Knepley .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate() 2966*5fedec97SMatthew G. Knepley @*/ 2967*5fedec97SMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffsetCohesive(PetscDS ds, PetscInt f, PetscInt *off) 2968*5fedec97SMatthew G. Knepley { 2969*5fedec97SMatthew G. Knepley PetscInt size, g; 2970*5fedec97SMatthew G. Knepley PetscErrorCode ierr; 2971*5fedec97SMatthew G. Knepley 2972*5fedec97SMatthew G. Knepley PetscFunctionBegin; 2973*5fedec97SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 2974*5fedec97SMatthew G. Knepley PetscValidPointer(off, 3); 2975*5fedec97SMatthew 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); 2976*5fedec97SMatthew G. Knepley *off = 0; 2977*5fedec97SMatthew G. Knepley for (g = 0; g < f; ++g) { 2978*5fedec97SMatthew G. Knepley PetscBool cohesive; 2979*5fedec97SMatthew G. Knepley 2980*5fedec97SMatthew G. Knepley ierr = PetscDSGetCohesive(ds, g, &cohesive);CHKERRQ(ierr); 2981*5fedec97SMatthew G. Knepley ierr = PetscDSGetFieldSize(ds, g, &size);CHKERRQ(ierr); 2982*5fedec97SMatthew G. Knepley *off += cohesive ? size : size*2; 2983*5fedec97SMatthew G. Knepley } 2984*5fedec97SMatthew G. Knepley PetscFunctionReturn(0); 2985*5fedec97SMatthew G. Knepley } 2986*5fedec97SMatthew G. Knepley 2987*5fedec97SMatthew G. Knepley /*@ 298847e57110SSander Arens PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point 2989bc4ae4beSMatthew G. Knepley 2990bc4ae4beSMatthew G. Knepley Not collective 2991bc4ae4beSMatthew G. Knepley 299247e57110SSander Arens Input Parameter: 299347e57110SSander Arens . prob - The PetscDS object 2994bc4ae4beSMatthew G. Knepley 2995bc4ae4beSMatthew G. Knepley Output Parameter: 299647e57110SSander Arens . dimensions - The number of dimensions 2997bc4ae4beSMatthew G. Knepley 2998bc4ae4beSMatthew G. Knepley Level: beginner 2999bc4ae4beSMatthew G. Knepley 300047e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 3001bc4ae4beSMatthew G. Knepley @*/ 300247e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[]) 30032764a2aaSMatthew G. Knepley { 30042764a2aaSMatthew G. Knepley PetscErrorCode ierr; 30052764a2aaSMatthew G. Knepley 30062764a2aaSMatthew G. Knepley PetscFunctionBegin; 30072764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 300847e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 300947e57110SSander Arens PetscValidPointer(dimensions, 2); 301047e57110SSander Arens *dimensions = prob->Nb; 301147e57110SSander Arens PetscFunctionReturn(0); 30126ce16762SMatthew G. Knepley } 301347e57110SSander Arens 301447e57110SSander Arens /*@ 301547e57110SSander Arens PetscDSGetComponents - Returns the number of components for each field on an evaluation point 301647e57110SSander Arens 301747e57110SSander Arens Not collective 301847e57110SSander Arens 301947e57110SSander Arens Input Parameter: 302047e57110SSander Arens . prob - The PetscDS object 302147e57110SSander Arens 302247e57110SSander Arens Output Parameter: 302347e57110SSander Arens . components - The number of components 302447e57110SSander Arens 302547e57110SSander Arens Level: beginner 302647e57110SSander Arens 302747e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 302847e57110SSander Arens @*/ 302947e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[]) 303047e57110SSander Arens { 303147e57110SSander Arens PetscErrorCode ierr; 303247e57110SSander Arens 303347e57110SSander Arens PetscFunctionBegin; 303447e57110SSander Arens PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 303547e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 303647e57110SSander Arens PetscValidPointer(components, 2); 303747e57110SSander Arens *components = prob->Nc; 30386ce16762SMatthew G. Knepley PetscFunctionReturn(0); 30396ce16762SMatthew G. Knepley } 30406ce16762SMatthew G. Knepley 30416ce16762SMatthew G. Knepley /*@ 30426ce16762SMatthew G. Knepley PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point 30436ce16762SMatthew G. Knepley 30446ce16762SMatthew G. Knepley Not collective 30456ce16762SMatthew G. Knepley 30466ce16762SMatthew G. Knepley Input Parameters: 30476ce16762SMatthew G. Knepley + prob - The PetscDS object 30486ce16762SMatthew G. Knepley - f - The field number 30496ce16762SMatthew G. Knepley 30506ce16762SMatthew G. Knepley Output Parameter: 30516ce16762SMatthew G. Knepley . off - The offset 30526ce16762SMatthew G. Knepley 30536ce16762SMatthew G. Knepley Level: beginner 30546ce16762SMatthew G. Knepley 3055f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 30566ce16762SMatthew G. Knepley @*/ 30576ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off) 30586ce16762SMatthew G. Knepley { 3059e1d313ffSMatthew G. Knepley PetscErrorCode ierr; 3060e1d313ffSMatthew G. Knepley 30616ce16762SMatthew G. Knepley PetscFunctionBegin; 30626ce16762SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 30636ce16762SMatthew G. Knepley PetscValidPointer(off, 3); 30646ce16762SMatthew 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); 3065e1d313ffSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 306647e57110SSander Arens *off = prob->off[f]; 30672764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 30682764a2aaSMatthew G. Knepley } 30692764a2aaSMatthew G. Knepley 3070194d53e6SMatthew G. Knepley /*@ 3071194d53e6SMatthew G. Knepley PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point 3072194d53e6SMatthew G. Knepley 3073194d53e6SMatthew G. Knepley Not collective 3074194d53e6SMatthew G. Knepley 3075194d53e6SMatthew G. Knepley Input Parameter: 3076194d53e6SMatthew G. Knepley . prob - The PetscDS object 3077194d53e6SMatthew G. Knepley 3078194d53e6SMatthew G. Knepley Output Parameter: 3079194d53e6SMatthew G. Knepley . offsets - The offsets 3080194d53e6SMatthew G. Knepley 3081194d53e6SMatthew G. Knepley Level: beginner 3082194d53e6SMatthew G. Knepley 3083f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 3084194d53e6SMatthew G. Knepley @*/ 3085194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[]) 3086194d53e6SMatthew G. Knepley { 3087e1d313ffSMatthew G. Knepley PetscErrorCode ierr; 3088e1d313ffSMatthew G. Knepley 3089194d53e6SMatthew G. Knepley PetscFunctionBegin; 3090194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3091194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 3092e1d313ffSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 3093194d53e6SMatthew G. Knepley *offsets = prob->off; 3094194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 3095194d53e6SMatthew G. Knepley } 3096194d53e6SMatthew G. Knepley 3097194d53e6SMatthew G. Knepley /*@ 3098194d53e6SMatthew G. Knepley PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point 3099194d53e6SMatthew G. Knepley 3100194d53e6SMatthew G. Knepley Not collective 3101194d53e6SMatthew G. Knepley 3102194d53e6SMatthew G. Knepley Input Parameter: 3103194d53e6SMatthew G. Knepley . prob - The PetscDS object 3104194d53e6SMatthew G. Knepley 3105194d53e6SMatthew G. Knepley Output Parameter: 3106194d53e6SMatthew G. Knepley . offsets - The offsets 3107194d53e6SMatthew G. Knepley 3108194d53e6SMatthew G. Knepley Level: beginner 3109194d53e6SMatthew G. Knepley 3110f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 3111194d53e6SMatthew G. Knepley @*/ 3112194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[]) 3113194d53e6SMatthew G. Knepley { 3114e1d313ffSMatthew G. Knepley PetscErrorCode ierr; 3115e1d313ffSMatthew G. Knepley 3116194d53e6SMatthew G. Knepley PetscFunctionBegin; 3117194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3118194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 3119e1d313ffSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 3120194d53e6SMatthew G. Knepley *offsets = prob->offDer; 3121194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 3122194d53e6SMatthew G. Knepley } 3123194d53e6SMatthew G. Knepley 312468c9edb9SMatthew G. Knepley /*@C 312568c9edb9SMatthew G. Knepley PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization 312668c9edb9SMatthew G. Knepley 312768c9edb9SMatthew G. Knepley Not collective 312868c9edb9SMatthew G. Knepley 312968c9edb9SMatthew G. Knepley Input Parameter: 313068c9edb9SMatthew G. Knepley . prob - The PetscDS object 313168c9edb9SMatthew G. Knepley 3132ef0bb6c7SMatthew G. Knepley Output Parameter: 3133ef0bb6c7SMatthew G. Knepley . T - The basis function and derivatives tabulation at quadrature points for each field 313468c9edb9SMatthew G. Knepley 313568c9edb9SMatthew G. Knepley Level: intermediate 313668c9edb9SMatthew G. Knepley 3137f744cafaSSander Arens .seealso: PetscDSCreate() 313868c9edb9SMatthew G. Knepley @*/ 3139ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscTabulation *T[]) 31402764a2aaSMatthew G. Knepley { 31412764a2aaSMatthew G. Knepley PetscErrorCode ierr; 31422764a2aaSMatthew G. Knepley 31432764a2aaSMatthew G. Knepley PetscFunctionBegin; 31442764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3145ef0bb6c7SMatthew G. Knepley PetscValidPointer(T, 2); 31462764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 3147ef0bb6c7SMatthew G. Knepley *T = prob->T; 31482764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31492764a2aaSMatthew G. Knepley } 31502764a2aaSMatthew G. Knepley 315168c9edb9SMatthew G. Knepley /*@C 31524d0b9603SSander Arens PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces 315368c9edb9SMatthew G. Knepley 315468c9edb9SMatthew G. Knepley Not collective 315568c9edb9SMatthew G. Knepley 315668c9edb9SMatthew G. Knepley Input Parameter: 315768c9edb9SMatthew G. Knepley . prob - The PetscDS object 315868c9edb9SMatthew G. Knepley 3159ef0bb6c7SMatthew G. Knepley Output Parameter: 3160a5b23f4aSJose E. Roman . Tf - The basis function and derivative tabulation on each local face at quadrature points for each and field 316168c9edb9SMatthew G. Knepley 316268c9edb9SMatthew G. Knepley Level: intermediate 316368c9edb9SMatthew G. Knepley 316468c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate() 316568c9edb9SMatthew G. Knepley @*/ 3166ef0bb6c7SMatthew G. Knepley PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscTabulation *Tf[]) 31672764a2aaSMatthew G. Knepley { 31682764a2aaSMatthew G. Knepley PetscErrorCode ierr; 31692764a2aaSMatthew G. Knepley 31702764a2aaSMatthew G. Knepley PetscFunctionBegin; 31712764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3172ef0bb6c7SMatthew G. Knepley PetscValidPointer(Tf, 2); 31732764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 3174ef0bb6c7SMatthew G. Knepley *Tf = prob->Tf; 31752764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31762764a2aaSMatthew G. Knepley } 31772764a2aaSMatthew G. Knepley 31782764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) 31792764a2aaSMatthew G. Knepley { 31802764a2aaSMatthew G. Knepley PetscErrorCode ierr; 31812764a2aaSMatthew G. Knepley 31822764a2aaSMatthew G. Knepley PetscFunctionBegin; 31832764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 31842764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 31852764a2aaSMatthew G. Knepley if (u) {PetscValidPointer(u, 2); *u = prob->u;} 31862764a2aaSMatthew G. Knepley if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;} 31872764a2aaSMatthew G. Knepley if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;} 31882764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 31892764a2aaSMatthew G. Knepley } 31902764a2aaSMatthew G. Knepley 31912764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) 31922764a2aaSMatthew G. Knepley { 31932764a2aaSMatthew G. Knepley PetscErrorCode ierr; 31942764a2aaSMatthew G. Knepley 31952764a2aaSMatthew G. Knepley PetscFunctionBegin; 31962764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 31972764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 31982764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;} 31992764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;} 32002764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;} 32012764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;} 32022764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;} 32032764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;} 32042764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 32052764a2aaSMatthew G. Knepley } 32062764a2aaSMatthew G. Knepley 32074bee2e38SMatthew G. Knepley PetscErrorCode PetscDSGetWorkspace(PetscDS prob, PetscReal **x, PetscScalar **basisReal, PetscScalar **basisDerReal, PetscScalar **testReal, PetscScalar **testDerReal) 32082764a2aaSMatthew G. Knepley { 32092764a2aaSMatthew G. Knepley PetscErrorCode ierr; 32102764a2aaSMatthew G. Knepley 32112764a2aaSMatthew G. Knepley PetscFunctionBegin; 32122764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 32132764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 32142764a2aaSMatthew G. Knepley if (x) {PetscValidPointer(x, 2); *x = prob->x;} 32154bee2e38SMatthew G. Knepley if (basisReal) {PetscValidPointer(basisReal, 3); *basisReal = prob->basisReal;} 32167506b574SStefano Zampini if (basisDerReal) {PetscValidPointer(basisDerReal, 4); *basisDerReal = prob->basisDerReal;} 32177506b574SStefano Zampini if (testReal) {PetscValidPointer(testReal, 5); *testReal = prob->testReal;} 32187506b574SStefano Zampini if (testDerReal) {PetscValidPointer(testDerReal, 6); *testDerReal = prob->testDerReal;} 32192764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 32202764a2aaSMatthew G. Knepley } 32212764a2aaSMatthew G. Knepley 322258ebd649SToby Isaac /*@C 322356cf3b9cSMatthew 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(). 322458ebd649SToby Isaac 3225783e2ec8SMatthew G. Knepley Collective on ds 3226783e2ec8SMatthew G. Knepley 322758ebd649SToby Isaac Input Parameters: 322858ebd649SToby Isaac + ds - The PetscDS object 32292d47a189SJulian Andrej . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 323058ebd649SToby Isaac . name - The BC name 323145480ffeSMatthew G. Knepley . label - The label defining constrained points 323245480ffeSMatthew G. Knepley . Nv - The number of DMLabel values for constrained points 323345480ffeSMatthew G. Knepley . values - An array of label values for constrained points 323458ebd649SToby Isaac . field - The field to constrain 323545480ffeSMatthew G. Knepley . Nc - The number of constrained field components (0 will constrain all fields) 323658ebd649SToby Isaac . comps - An array of constrained component numbers 323758ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 3238a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL 323958ebd649SToby Isaac - ctx - An optional user context for bcFunc 324058ebd649SToby Isaac 324145480ffeSMatthew G. Knepley Output Parameters: 324245480ffeSMatthew G. Knepley - bd - The boundary number 324345480ffeSMatthew G. Knepley 324458ebd649SToby Isaac Options Database Keys: 324558ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 324658ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 324758ebd649SToby Isaac 324856cf3b9cSMatthew G. Knepley Note: 324956cf3b9cSMatthew 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: 325056cf3b9cSMatthew G. Knepley 325156cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[]) 325256cf3b9cSMatthew G. Knepley 325356cf3b9cSMatthew G. Knepley If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is: 325456cf3b9cSMatthew G. Knepley 325556cf3b9cSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux, 325656cf3b9cSMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 325756cf3b9cSMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 325856cf3b9cSMatthew G. Knepley $ PetscReal time, const PetscReal x[], PetscScalar bcval[]) 325956cf3b9cSMatthew G. Knepley 326056cf3b9cSMatthew G. Knepley + dim - the spatial dimension 326156cf3b9cSMatthew G. Knepley . Nf - the number of fields 326256cf3b9cSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 326356cf3b9cSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 326456cf3b9cSMatthew G. Knepley . u - each field evaluated at the current point 326556cf3b9cSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 326656cf3b9cSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 326756cf3b9cSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 326856cf3b9cSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 326956cf3b9cSMatthew G. Knepley . a - each auxiliary field evaluated at the current point 327056cf3b9cSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 327156cf3b9cSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 327256cf3b9cSMatthew G. Knepley . t - current time 327356cf3b9cSMatthew G. Knepley . x - coordinates of the current point 327456cf3b9cSMatthew G. Knepley . numConstants - number of constant parameters 327556cf3b9cSMatthew G. Knepley . constants - constant parameters 327656cf3b9cSMatthew G. Knepley - bcval - output values at the current point 327756cf3b9cSMatthew G. Knepley 327858ebd649SToby Isaac Level: developer 327958ebd649SToby Isaac 328045480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundaryByName(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual() 328158ebd649SToby Isaac @*/ 328245480ffeSMatthew 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) 328358ebd649SToby Isaac { 328445480ffeSMatthew G. Knepley DSBoundary head = ds->boundary, b; 328545480ffeSMatthew G. Knepley PetscInt n = 0; 328645480ffeSMatthew G. Knepley const char *lname; 328758ebd649SToby Isaac PetscErrorCode ierr; 328858ebd649SToby Isaac 328958ebd649SToby Isaac PetscFunctionBegin; 329058ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3291783e2ec8SMatthew G. Knepley PetscValidLogicalCollectiveEnum(ds, type, 2); 329245480ffeSMatthew G. Knepley PetscValidCharPointer(name, 3); 329345480ffeSMatthew G. Knepley PetscValidHeaderSpecific(label, DMLABEL_CLASSID, 4); 329445480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nv, 5); 329545480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, field, 7); 329645480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nc, 8); 3297d57bb9dbSMatthew G. Knepley if (Nc > 0) { 3298d57bb9dbSMatthew G. Knepley PetscInt *fcomps; 3299d57bb9dbSMatthew G. Knepley PetscInt c; 3300d57bb9dbSMatthew G. Knepley 3301d57bb9dbSMatthew G. Knepley ierr = PetscDSGetComponents(ds, &fcomps);CHKERRQ(ierr); 3302d57bb9dbSMatthew G. Knepley if (Nc > fcomps[field]) SETERRQ3(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_OUTOFRANGE, "Number of constrained components %D > %D components for field %D", Nc, fcomps[field], field); 3303d57bb9dbSMatthew G. Knepley for (c = 0; c < Nc; ++c) { 3304d57bb9dbSMatthew G. Knepley if (comps[c] < 0 || comps[c] >= fcomps[field]) SETERRQ4(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_OUTOFRANGE, "Constrained component[%D] %D not in [0, %D) components for field %D", c, comps[c], fcomps[field], field); 3305d57bb9dbSMatthew G. Knepley } 3306d57bb9dbSMatthew G. Knepley } 330758ebd649SToby Isaac ierr = PetscNew(&b);CHKERRQ(ierr); 330858ebd649SToby Isaac ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 330945480ffeSMatthew G. Knepley ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr); 331045480ffeSMatthew G. Knepley ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr); 331145480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr); 331245480ffeSMatthew G. Knepley if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);} 331345480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr); 331445480ffeSMatthew G. Knepley if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);} 331545480ffeSMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) label, &lname);CHKERRQ(ierr); 331645480ffeSMatthew G. Knepley ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr); 3317f971fd6bSMatthew G. Knepley b->type = type; 331845480ffeSMatthew G. Knepley b->label = label; 331945480ffeSMatthew G. Knepley b->Nv = Nv; 332058ebd649SToby Isaac b->field = field; 332145480ffeSMatthew G. Knepley b->Nc = Nc; 332258ebd649SToby Isaac b->func = bcFunc; 332356cf3b9cSMatthew G. Knepley b->func_t = bcFunc_t; 332458ebd649SToby Isaac b->ctx = ctx; 332545480ffeSMatthew G. Knepley b->next = NULL; 332645480ffeSMatthew G. Knepley /* Append to linked list so that we can preserve the order */ 332745480ffeSMatthew G. Knepley if (!head) ds->boundary = b; 332845480ffeSMatthew G. Knepley while (head) { 332945480ffeSMatthew G. Knepley if (!head->next) { 333045480ffeSMatthew G. Knepley head->next = b; 333145480ffeSMatthew G. Knepley head = b; 333245480ffeSMatthew G. Knepley } 333345480ffeSMatthew G. Knepley head = head->next; 333445480ffeSMatthew G. Knepley ++n; 333545480ffeSMatthew G. Knepley } 3336064a246eSJacob Faibussowitsch if (bd) {PetscValidIntPointer(bd, 13); *bd = n;} 333745480ffeSMatthew G. Knepley PetscFunctionReturn(0); 333845480ffeSMatthew G. Knepley } 333945480ffeSMatthew G. Knepley 334045480ffeSMatthew G. Knepley /*@C 334145480ffeSMatthew 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(). 334245480ffeSMatthew G. Knepley 334345480ffeSMatthew G. Knepley Collective on ds 334445480ffeSMatthew G. Knepley 334545480ffeSMatthew G. Knepley Input Parameters: 334645480ffeSMatthew G. Knepley + ds - The PetscDS object 334745480ffeSMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 334845480ffeSMatthew G. Knepley . name - The BC name 334945480ffeSMatthew G. Knepley . lname - The naem of the label defining constrained points 335045480ffeSMatthew G. Knepley . Nv - The number of DMLabel values for constrained points 335145480ffeSMatthew G. Knepley . values - An array of label values for constrained points 335245480ffeSMatthew G. Knepley . field - The field to constrain 335345480ffeSMatthew G. Knepley . Nc - The number of constrained field components (0 will constrain all fields) 335445480ffeSMatthew G. Knepley . comps - An array of constrained component numbers 335545480ffeSMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 3356a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL 335745480ffeSMatthew G. Knepley - ctx - An optional user context for bcFunc 335845480ffeSMatthew G. Knepley 335945480ffeSMatthew G. Knepley Output Parameters: 336045480ffeSMatthew G. Knepley - bd - The boundary number 336145480ffeSMatthew G. Knepley 336245480ffeSMatthew G. Knepley Options Database Keys: 336345480ffeSMatthew G. Knepley + -bc_<boundary name> <num> - Overrides the boundary ids 336445480ffeSMatthew G. Knepley - -bc_<boundary name>_comp <num> - Overrides the boundary components 336545480ffeSMatthew G. Knepley 336645480ffeSMatthew G. Knepley Note: 336745480ffeSMatthew G. Knepley This function should only be used with DMForest currently, since labels cannot be defined before the underlygin Plex is built. 336845480ffeSMatthew G. Knepley 336945480ffeSMatthew 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: 337045480ffeSMatthew G. Knepley 337145480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar bcval[]) 337245480ffeSMatthew G. Knepley 337345480ffeSMatthew G. Knepley If the type is DM_BC_ESSENTIAL_FIELD or other _FIELD value, then the calling sequence is: 337445480ffeSMatthew G. Knepley 337545480ffeSMatthew G. Knepley $ bcFunc(PetscInt dim, PetscInt Nf, PetscInt NfAux, 337645480ffeSMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 337745480ffeSMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 337845480ffeSMatthew G. Knepley $ PetscReal time, const PetscReal x[], PetscScalar bcval[]) 337945480ffeSMatthew G. Knepley 338045480ffeSMatthew G. Knepley + dim - the spatial dimension 338145480ffeSMatthew G. Knepley . Nf - the number of fields 338245480ffeSMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 338345480ffeSMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 338445480ffeSMatthew G. Knepley . u - each field evaluated at the current point 338545480ffeSMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 338645480ffeSMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 338745480ffeSMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 338845480ffeSMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 338945480ffeSMatthew G. Knepley . a - each auxiliary field evaluated at the current point 339045480ffeSMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 339145480ffeSMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 339245480ffeSMatthew G. Knepley . t - current time 339345480ffeSMatthew G. Knepley . x - coordinates of the current point 339445480ffeSMatthew G. Knepley . numConstants - number of constant parameters 339545480ffeSMatthew G. Knepley . constants - constant parameters 339645480ffeSMatthew G. Knepley - bcval - output values at the current point 339745480ffeSMatthew G. Knepley 339845480ffeSMatthew G. Knepley Level: developer 339945480ffeSMatthew G. Knepley 340045480ffeSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSSetResidual(), PetscDSSetBdResidual() 340145480ffeSMatthew G. Knepley @*/ 340245480ffeSMatthew 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) 340345480ffeSMatthew G. Knepley { 340445480ffeSMatthew G. Knepley DSBoundary head = ds->boundary, b; 340545480ffeSMatthew G. Knepley PetscInt n = 0; 340645480ffeSMatthew G. Knepley PetscErrorCode ierr; 340745480ffeSMatthew G. Knepley 340845480ffeSMatthew G. Knepley PetscFunctionBegin; 340945480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 341045480ffeSMatthew G. Knepley PetscValidLogicalCollectiveEnum(ds, type, 2); 341145480ffeSMatthew G. Knepley PetscValidCharPointer(name, 3); 341245480ffeSMatthew G. Knepley PetscValidCharPointer(lname, 4); 341345480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nv, 5); 341445480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, field, 7); 341545480ffeSMatthew G. Knepley PetscValidLogicalCollectiveInt(ds, Nc, 8); 341645480ffeSMatthew G. Knepley ierr = PetscNew(&b);CHKERRQ(ierr); 341745480ffeSMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 341845480ffeSMatthew G. Knepley ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &b->wf);CHKERRQ(ierr); 341945480ffeSMatthew G. Knepley ierr = PetscWeakFormSetNumFields(b->wf, ds->Nf);CHKERRQ(ierr); 342045480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr); 342145480ffeSMatthew G. Knepley if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);} 342245480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr); 342345480ffeSMatthew G. Knepley if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);} 342445480ffeSMatthew G. Knepley ierr = PetscStrallocpy(lname, (char **) &b->lname);CHKERRQ(ierr); 342545480ffeSMatthew G. Knepley b->type = type; 342645480ffeSMatthew G. Knepley b->label = NULL; 342745480ffeSMatthew G. Knepley b->Nv = Nv; 342845480ffeSMatthew G. Knepley b->field = field; 342945480ffeSMatthew G. Knepley b->Nc = Nc; 343045480ffeSMatthew G. Knepley b->func = bcFunc; 343145480ffeSMatthew G. Knepley b->func_t = bcFunc_t; 343245480ffeSMatthew G. Knepley b->ctx = ctx; 343345480ffeSMatthew G. Knepley b->next = NULL; 343445480ffeSMatthew G. Knepley /* Append to linked list so that we can preserve the order */ 343545480ffeSMatthew G. Knepley if (!head) ds->boundary = b; 343645480ffeSMatthew G. Knepley while (head) { 343745480ffeSMatthew G. Knepley if (!head->next) { 343845480ffeSMatthew G. Knepley head->next = b; 343945480ffeSMatthew G. Knepley head = b; 344045480ffeSMatthew G. Knepley } 344145480ffeSMatthew G. Knepley head = head->next; 344245480ffeSMatthew G. Knepley ++n; 344345480ffeSMatthew G. Knepley } 3444064a246eSJacob Faibussowitsch if (bd) {PetscValidIntPointer(bd, 13); *bd = n;} 344558ebd649SToby Isaac PetscFunctionReturn(0); 344658ebd649SToby Isaac } 344758ebd649SToby Isaac 3448b67eacb3SMatthew G. Knepley /*@C 344956cf3b9cSMatthew 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(). 3450b67eacb3SMatthew G. Knepley 3451b67eacb3SMatthew G. Knepley Input Parameters: 3452b67eacb3SMatthew G. Knepley + ds - The PetscDS object 3453b67eacb3SMatthew G. Knepley . bd - The boundary condition number 3454b67eacb3SMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 3455b67eacb3SMatthew G. Knepley . name - The BC name 345645480ffeSMatthew G. Knepley . label - The label defining constrained points 345745480ffeSMatthew G. Knepley . Nv - The number of DMLabel ids for constrained points 345845480ffeSMatthew G. Knepley . values - An array of ids for constrained points 3459b67eacb3SMatthew G. Knepley . field - The field to constrain 346045480ffeSMatthew G. Knepley . Nc - The number of constrained field components 3461b67eacb3SMatthew G. Knepley . comps - An array of constrained component numbers 3462b67eacb3SMatthew G. Knepley . bcFunc - A pointwise function giving boundary values 3463a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values, or NULL 3464b67eacb3SMatthew G. Knepley - ctx - An optional user context for bcFunc 3465b67eacb3SMatthew G. Knepley 346656cf3b9cSMatthew G. Knepley Note: 346756cf3b9cSMatthew 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. 34689a6efb6aSMatthew G. Knepley 3469b67eacb3SMatthew G. Knepley Level: developer 3470b67eacb3SMatthew G. Knepley 34719a6efb6aSMatthew G. Knepley .seealso: PetscDSAddBoundary(), PetscDSGetBoundary(), PetscDSGetNumBoundary() 3472b67eacb3SMatthew G. Knepley @*/ 347345480ffeSMatthew 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) 3474b67eacb3SMatthew G. Knepley { 3475b67eacb3SMatthew G. Knepley DSBoundary b = ds->boundary; 3476b67eacb3SMatthew G. Knepley PetscInt n = 0; 3477b67eacb3SMatthew G. Knepley PetscErrorCode ierr; 3478b67eacb3SMatthew G. Knepley 3479b67eacb3SMatthew G. Knepley PetscFunctionBegin; 3480b67eacb3SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3481b67eacb3SMatthew G. Knepley while (b) { 3482b67eacb3SMatthew G. Knepley if (n == bd) break; 3483b67eacb3SMatthew G. Knepley b = b->next; 3484b67eacb3SMatthew G. Knepley ++n; 3485b67eacb3SMatthew G. Knepley } 3486b67eacb3SMatthew G. Knepley if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 3487b67eacb3SMatthew G. Knepley if (name) { 3488b67eacb3SMatthew G. Knepley ierr = PetscFree(b->name);CHKERRQ(ierr); 3489b67eacb3SMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 3490b67eacb3SMatthew G. Knepley } 3491b67eacb3SMatthew G. Knepley b->type = type; 349245480ffeSMatthew G. Knepley if (label) { 349345480ffeSMatthew G. Knepley const char *name; 349445480ffeSMatthew G. Knepley 349545480ffeSMatthew G. Knepley b->label = label; 349645480ffeSMatthew G. Knepley ierr = PetscFree(b->lname);CHKERRQ(ierr); 349745480ffeSMatthew G. Knepley ierr = PetscObjectGetName((PetscObject) label, &name);CHKERRQ(ierr); 349845480ffeSMatthew G. Knepley ierr = PetscStrallocpy(name, (char **) &b->lname);CHKERRQ(ierr); 349945480ffeSMatthew G. Knepley } 350045480ffeSMatthew G. Knepley if (Nv >= 0) { 350145480ffeSMatthew G. Knepley b->Nv = Nv; 350245480ffeSMatthew G. Knepley ierr = PetscFree(b->values);CHKERRQ(ierr); 350345480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nv, &b->values);CHKERRQ(ierr); 350445480ffeSMatthew G. Knepley if (Nv) {ierr = PetscArraycpy(b->values, values, Nv);CHKERRQ(ierr);} 350545480ffeSMatthew G. Knepley } 350645480ffeSMatthew G. Knepley if (field >= 0) b->field = field; 350745480ffeSMatthew G. Knepley if (Nc >= 0) { 350845480ffeSMatthew G. Knepley b->Nc = Nc; 350945480ffeSMatthew G. Knepley ierr = PetscFree(b->comps);CHKERRQ(ierr); 351045480ffeSMatthew G. Knepley ierr = PetscMalloc1(Nc, &b->comps);CHKERRQ(ierr); 351145480ffeSMatthew G. Knepley if (Nc) {ierr = PetscArraycpy(b->comps, comps, Nc);CHKERRQ(ierr);} 351245480ffeSMatthew G. Knepley } 351345480ffeSMatthew G. Knepley if (bcFunc) b->func = bcFunc; 351445480ffeSMatthew G. Knepley if (bcFunc_t) b->func_t = bcFunc_t; 351545480ffeSMatthew G. Knepley if (ctx) b->ctx = ctx; 3516b67eacb3SMatthew G. Knepley PetscFunctionReturn(0); 3517b67eacb3SMatthew G. Knepley } 3518b67eacb3SMatthew G. Knepley 351958ebd649SToby Isaac /*@ 352058ebd649SToby Isaac PetscDSGetNumBoundary - Get the number of registered BC 352158ebd649SToby Isaac 352258ebd649SToby Isaac Input Parameters: 352358ebd649SToby Isaac . ds - The PetscDS object 352458ebd649SToby Isaac 352558ebd649SToby Isaac Output Parameters: 352658ebd649SToby Isaac . numBd - The number of BC 352758ebd649SToby Isaac 352858ebd649SToby Isaac Level: intermediate 352958ebd649SToby Isaac 353058ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary() 353158ebd649SToby Isaac @*/ 353258ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd) 353358ebd649SToby Isaac { 353458ebd649SToby Isaac DSBoundary b = ds->boundary; 353558ebd649SToby Isaac 353658ebd649SToby Isaac PetscFunctionBegin; 353758ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 353858ebd649SToby Isaac PetscValidPointer(numBd, 2); 353958ebd649SToby Isaac *numBd = 0; 354058ebd649SToby Isaac while (b) {++(*numBd); b = b->next;} 354158ebd649SToby Isaac PetscFunctionReturn(0); 354258ebd649SToby Isaac } 354358ebd649SToby Isaac 354458ebd649SToby Isaac /*@C 35459a6efb6aSMatthew G. Knepley PetscDSGetBoundary - Gets a boundary condition to the model 354658ebd649SToby Isaac 354758ebd649SToby Isaac Input Parameters: 354858ebd649SToby Isaac + ds - The PetscDS object 354958ebd649SToby Isaac - bd - The BC number 355058ebd649SToby Isaac 355158ebd649SToby Isaac Output Parameters: 355245480ffeSMatthew G. Knepley + wf - The PetscWeakForm holding the pointwise functions 355345480ffeSMatthew G. Knepley . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 355458ebd649SToby Isaac . name - The BC name 355545480ffeSMatthew G. Knepley . label - The label defining constrained points 355645480ffeSMatthew G. Knepley . Nv - The number of DMLabel ids for constrained points 355745480ffeSMatthew G. Knepley . values - An array of ids for constrained points 355858ebd649SToby Isaac . field - The field to constrain 355945480ffeSMatthew G. Knepley . Nc - The number of constrained field components 356058ebd649SToby Isaac . comps - An array of constrained component numbers 356158ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 3562a5b23f4aSJose E. Roman . bcFunc_t - A pointwise function giving the time derivative of the boundary values 356358ebd649SToby Isaac - ctx - An optional user context for bcFunc 356458ebd649SToby Isaac 356558ebd649SToby Isaac Options Database Keys: 356658ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 356758ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 356858ebd649SToby Isaac 356958ebd649SToby Isaac Level: developer 357058ebd649SToby Isaac 357158ebd649SToby Isaac .seealso: PetscDSAddBoundary() 357258ebd649SToby Isaac @*/ 357345480ffeSMatthew 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) 357458ebd649SToby Isaac { 357558ebd649SToby Isaac DSBoundary b = ds->boundary; 357658ebd649SToby Isaac PetscInt n = 0; 357758ebd649SToby Isaac 357858ebd649SToby Isaac PetscFunctionBegin; 357958ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 358058ebd649SToby Isaac while (b) { 358158ebd649SToby Isaac if (n == bd) break; 358258ebd649SToby Isaac b = b->next; 358358ebd649SToby Isaac ++n; 358458ebd649SToby Isaac } 358558ebd649SToby Isaac if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 358645480ffeSMatthew G. Knepley if (wf) { 358745480ffeSMatthew G. Knepley PetscValidPointer(wf, 3); 358845480ffeSMatthew G. Knepley *wf = b->wf; 358945480ffeSMatthew G. Knepley } 3590f971fd6bSMatthew G. Knepley if (type) { 359145480ffeSMatthew G. Knepley PetscValidPointer(type, 4); 3592f971fd6bSMatthew G. Knepley *type = b->type; 359358ebd649SToby Isaac } 359458ebd649SToby Isaac if (name) { 359545480ffeSMatthew G. Knepley PetscValidPointer(name, 5); 359658ebd649SToby Isaac *name = b->name; 359758ebd649SToby Isaac } 359845480ffeSMatthew G. Knepley if (label) { 359945480ffeSMatthew G. Knepley PetscValidPointer(label, 6); 360045480ffeSMatthew G. Knepley *label = b->label; 360145480ffeSMatthew G. Knepley } 360245480ffeSMatthew G. Knepley if (Nv) { 360345480ffeSMatthew G. Knepley PetscValidIntPointer(Nv, 7); 360445480ffeSMatthew G. Knepley *Nv = b->Nv; 360545480ffeSMatthew G. Knepley } 360645480ffeSMatthew G. Knepley if (values) { 360745480ffeSMatthew G. Knepley PetscValidPointer(values, 8); 360845480ffeSMatthew G. Knepley *values = b->values; 360958ebd649SToby Isaac } 361058ebd649SToby Isaac if (field) { 361145480ffeSMatthew G. Knepley PetscValidIntPointer(field, 9); 361258ebd649SToby Isaac *field = b->field; 361358ebd649SToby Isaac } 361445480ffeSMatthew G. Knepley if (Nc) { 361545480ffeSMatthew G. Knepley PetscValidIntPointer(Nc, 10); 361645480ffeSMatthew G. Knepley *Nc = b->Nc; 361758ebd649SToby Isaac } 361858ebd649SToby Isaac if (comps) { 361945480ffeSMatthew G. Knepley PetscValidPointer(comps, 11); 362058ebd649SToby Isaac *comps = b->comps; 362158ebd649SToby Isaac } 362258ebd649SToby Isaac if (func) { 362345480ffeSMatthew G. Knepley PetscValidPointer(func, 12); 362458ebd649SToby Isaac *func = b->func; 362558ebd649SToby Isaac } 362656cf3b9cSMatthew G. Knepley if (func_t) { 362745480ffeSMatthew G. Knepley PetscValidPointer(func_t, 13); 362856cf3b9cSMatthew G. Knepley *func_t = b->func_t; 362956cf3b9cSMatthew G. Knepley } 363058ebd649SToby Isaac if (ctx) { 363145480ffeSMatthew G. Knepley PetscValidPointer(ctx, 14); 363258ebd649SToby Isaac *ctx = b->ctx; 363358ebd649SToby Isaac } 363458ebd649SToby Isaac PetscFunctionReturn(0); 363558ebd649SToby Isaac } 363658ebd649SToby Isaac 363745480ffeSMatthew G. Knepley static PetscErrorCode DSBoundaryDuplicate_Internal(DSBoundary b, DSBoundary *bNew) 363845480ffeSMatthew G. Knepley { 363945480ffeSMatthew G. Knepley PetscErrorCode ierr; 364045480ffeSMatthew G. Knepley 364145480ffeSMatthew G. Knepley PetscFunctionBegin; 364245480ffeSMatthew G. Knepley ierr = PetscNew(bNew);CHKERRQ(ierr); 364345480ffeSMatthew G. Knepley ierr = PetscWeakFormCreate(PETSC_COMM_SELF, &(*bNew)->wf);CHKERRQ(ierr); 364445480ffeSMatthew G. Knepley ierr = PetscWeakFormCopy(b->wf, (*bNew)->wf);CHKERRQ(ierr); 364545480ffeSMatthew G. Knepley ierr = PetscStrallocpy(b->name,(char **) &((*bNew)->name));CHKERRQ(ierr); 364645480ffeSMatthew G. Knepley ierr = PetscStrallocpy(b->lname,(char **) &((*bNew)->lname));CHKERRQ(ierr); 364745480ffeSMatthew G. Knepley (*bNew)->type = b->type; 364845480ffeSMatthew G. Knepley (*bNew)->label = b->label; 364945480ffeSMatthew G. Knepley (*bNew)->Nv = b->Nv; 365045480ffeSMatthew G. Knepley ierr = PetscMalloc1(b->Nv, &(*bNew)->values);CHKERRQ(ierr); 365145480ffeSMatthew G. Knepley ierr = PetscArraycpy((*bNew)->values, b->values, b->Nv);CHKERRQ(ierr); 365245480ffeSMatthew G. Knepley (*bNew)->field = b->field; 365345480ffeSMatthew G. Knepley (*bNew)->Nc = b->Nc; 365445480ffeSMatthew G. Knepley ierr = PetscMalloc1(b->Nc, &(*bNew)->comps);CHKERRQ(ierr); 365545480ffeSMatthew G. Knepley ierr = PetscArraycpy((*bNew)->comps, b->comps, b->Nc);CHKERRQ(ierr); 365645480ffeSMatthew G. Knepley (*bNew)->func = b->func; 365745480ffeSMatthew G. Knepley (*bNew)->func_t = b->func_t; 365845480ffeSMatthew G. Knepley (*bNew)->ctx = b->ctx; 365945480ffeSMatthew G. Knepley PetscFunctionReturn(0); 366045480ffeSMatthew G. Knepley } 366145480ffeSMatthew G. Knepley 36629252d075SMatthew G. Knepley /*@ 36639252d075SMatthew G. Knepley PetscDSCopyBoundary - Copy all boundary condition objects to the new problem 36649252d075SMatthew G. Knepley 36659252d075SMatthew G. Knepley Not collective 36669252d075SMatthew G. Knepley 366736951cb5SMatthew G. Knepley Input Parameters: 366836951cb5SMatthew G. Knepley + ds - The source PetscDS object 366936951cb5SMatthew G. Knepley . numFields - The number of selected fields, or PETSC_DEFAULT for all fields 367036951cb5SMatthew G. Knepley - fields - The selected fields, or NULL for all fields 36719252d075SMatthew G. Knepley 36729252d075SMatthew G. Knepley Output Parameter: 367336951cb5SMatthew G. Knepley . newds - The target PetscDS, now with a copy of the boundary conditions 36749252d075SMatthew G. Knepley 36759252d075SMatthew G. Knepley Level: intermediate 36769252d075SMatthew G. Knepley 36779252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 36789252d075SMatthew G. Knepley @*/ 367936951cb5SMatthew G. Knepley PetscErrorCode PetscDSCopyBoundary(PetscDS ds, PetscInt numFields, const PetscInt fields[], PetscDS newds) 3680dff059c6SToby Isaac { 368145480ffeSMatthew G. Knepley DSBoundary b, *lastnext; 3682dff059c6SToby Isaac PetscErrorCode ierr; 3683dff059c6SToby Isaac 3684dff059c6SToby Isaac PetscFunctionBegin; 368536951cb5SMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 368636951cb5SMatthew G. Knepley PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 4); 368736951cb5SMatthew G. Knepley if (ds == newds) PetscFunctionReturn(0); 368845480ffeSMatthew G. Knepley ierr = PetscDSDestroyBoundary(newds);CHKERRQ(ierr); 368936951cb5SMatthew G. Knepley lastnext = &(newds->boundary); 369036951cb5SMatthew G. Knepley for (b = ds->boundary; b; b = b->next) { 3691dff059c6SToby Isaac DSBoundary bNew; 369236951cb5SMatthew G. Knepley PetscInt fieldNew = -1; 3693dff059c6SToby Isaac 369436951cb5SMatthew G. Knepley if (numFields > 0 && fields) { 369536951cb5SMatthew G. Knepley PetscInt f; 369636951cb5SMatthew G. Knepley 369736951cb5SMatthew G. Knepley for (f = 0; f < numFields; ++f) if (b->field == fields[f]) break; 369836951cb5SMatthew G. Knepley if (f == numFields) continue; 369936951cb5SMatthew G. Knepley fieldNew = f; 370036951cb5SMatthew G. Knepley } 370145480ffeSMatthew G. Knepley ierr = DSBoundaryDuplicate_Internal(b, &bNew);CHKERRQ(ierr); 370236951cb5SMatthew G. Knepley bNew->field = fieldNew < 0 ? b->field : fieldNew; 3703dff059c6SToby Isaac *lastnext = bNew; 3704dff059c6SToby Isaac lastnext = &(bNew->next); 3705dff059c6SToby Isaac } 3706dff059c6SToby Isaac PetscFunctionReturn(0); 3707dff059c6SToby Isaac } 3708dff059c6SToby Isaac 37096c1eb96dSMatthew G. Knepley /*@ 371045480ffeSMatthew G. Knepley PetscDSDestroyBoundary - Remove all DMBoundary objects from the PetscDS 371145480ffeSMatthew G. Knepley 371245480ffeSMatthew G. Knepley Not collective 371345480ffeSMatthew G. Knepley 371445480ffeSMatthew G. Knepley Input Parameter: 371545480ffeSMatthew G. Knepley . ds - The PetscDS object 371645480ffeSMatthew G. Knepley 371745480ffeSMatthew G. Knepley Level: intermediate 371845480ffeSMatthew G. Knepley 371945480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations() 372045480ffeSMatthew G. Knepley @*/ 372145480ffeSMatthew G. Knepley PetscErrorCode PetscDSDestroyBoundary(PetscDS ds) 372245480ffeSMatthew G. Knepley { 372345480ffeSMatthew G. Knepley DSBoundary next = ds->boundary; 372445480ffeSMatthew G. Knepley PetscErrorCode ierr; 372545480ffeSMatthew G. Knepley 372645480ffeSMatthew G. Knepley PetscFunctionBegin; 372745480ffeSMatthew G. Knepley while (next) { 372845480ffeSMatthew G. Knepley DSBoundary b = next; 372945480ffeSMatthew G. Knepley 373045480ffeSMatthew G. Knepley next = b->next; 373145480ffeSMatthew G. Knepley ierr = PetscWeakFormDestroy(&b->wf);CHKERRQ(ierr); 373245480ffeSMatthew G. Knepley ierr = PetscFree(b->name);CHKERRQ(ierr); 373345480ffeSMatthew G. Knepley ierr = PetscFree(b->lname);CHKERRQ(ierr); 373445480ffeSMatthew G. Knepley ierr = PetscFree(b->values);CHKERRQ(ierr); 373545480ffeSMatthew G. Knepley ierr = PetscFree(b->comps);CHKERRQ(ierr); 373645480ffeSMatthew G. Knepley ierr = PetscFree(b);CHKERRQ(ierr); 373745480ffeSMatthew G. Knepley } 373845480ffeSMatthew G. Knepley PetscFunctionReturn(0); 373945480ffeSMatthew G. Knepley } 374045480ffeSMatthew G. Knepley 374145480ffeSMatthew G. Knepley /*@ 37426c1eb96dSMatthew G. Knepley PetscDSSelectDiscretizations - Copy discretizations to the new problem with different field layout 37436c1eb96dSMatthew G. Knepley 37446c1eb96dSMatthew G. Knepley Not collective 37456c1eb96dSMatthew G. Knepley 3746d8d19677SJose E. Roman Input Parameters: 37476c1eb96dSMatthew G. Knepley + prob - The PetscDS object 37486c1eb96dSMatthew G. Knepley . numFields - Number of new fields 37496c1eb96dSMatthew G. Knepley - fields - Old field number for each new field 37506c1eb96dSMatthew G. Knepley 37516c1eb96dSMatthew G. Knepley Output Parameter: 37526c1eb96dSMatthew G. Knepley . newprob - The PetscDS copy 37536c1eb96dSMatthew G. Knepley 37546c1eb96dSMatthew G. Knepley Level: intermediate 37556c1eb96dSMatthew G. Knepley 37566c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectEquations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 37576c1eb96dSMatthew G. Knepley @*/ 37586c1eb96dSMatthew G. Knepley PetscErrorCode PetscDSSelectDiscretizations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 37596c1eb96dSMatthew G. Knepley { 37606c1eb96dSMatthew G. Knepley PetscInt Nf, Nfn, fn; 37616c1eb96dSMatthew G. Knepley PetscErrorCode ierr; 37626c1eb96dSMatthew G. Knepley 37636c1eb96dSMatthew G. Knepley PetscFunctionBegin; 37646c1eb96dSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 37656c1eb96dSMatthew G. Knepley if (fields) PetscValidPointer(fields, 3); 37666c1eb96dSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 37676c1eb96dSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 37686c1eb96dSMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr); 376945480ffeSMatthew G. Knepley numFields = numFields < 0 ? Nf : numFields; 37706c1eb96dSMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 37716c1eb96dSMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 37726c1eb96dSMatthew G. Knepley PetscObject disc; 37736c1eb96dSMatthew G. Knepley 37746c1eb96dSMatthew G. Knepley if (f >= Nf) continue; 37756c1eb96dSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &disc);CHKERRQ(ierr); 37766c1eb96dSMatthew G. Knepley ierr = PetscDSSetDiscretization(newprob, fn, disc);CHKERRQ(ierr); 37776c1eb96dSMatthew G. Knepley } 37786c1eb96dSMatthew G. Knepley PetscFunctionReturn(0); 37796c1eb96dSMatthew G. Knepley } 37806c1eb96dSMatthew G. Knepley 37816c1eb96dSMatthew G. Knepley /*@ 37829252d075SMatthew G. Knepley PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout 37839252d075SMatthew G. Knepley 37849252d075SMatthew G. Knepley Not collective 37859252d075SMatthew G. Knepley 3786d8d19677SJose E. Roman Input Parameters: 37879252d075SMatthew G. Knepley + prob - The PetscDS object 37889252d075SMatthew G. Knepley . numFields - Number of new fields 37899252d075SMatthew G. Knepley - fields - Old field number for each new field 37909252d075SMatthew G. Knepley 37919252d075SMatthew G. Knepley Output Parameter: 37929252d075SMatthew G. Knepley . newprob - The PetscDS copy 37939252d075SMatthew G. Knepley 37949252d075SMatthew G. Knepley Level: intermediate 37959252d075SMatthew G. Knepley 37966c1eb96dSMatthew G. Knepley .seealso: PetscDSSelectDiscretizations(), PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 37979252d075SMatthew G. Knepley @*/ 37989252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob) 37999252d075SMatthew G. Knepley { 38009252d075SMatthew G. Knepley PetscInt Nf, Nfn, fn, gn; 38019252d075SMatthew G. Knepley PetscErrorCode ierr; 38029252d075SMatthew G. Knepley 38039252d075SMatthew G. Knepley PetscFunctionBegin; 38049252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 38059252d075SMatthew G. Knepley if (fields) PetscValidPointer(fields, 3); 38069252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4); 38079252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 38089252d075SMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr); 38099252d075SMatthew 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); 38109252d075SMatthew G. Knepley for (fn = 0; fn < numFields; ++fn) { 38119252d075SMatthew G. Knepley const PetscInt f = fields ? fields[fn] : fn; 38129252d075SMatthew G. Knepley PetscPointFunc obj; 38139252d075SMatthew G. Knepley PetscPointFunc f0, f1; 38149252d075SMatthew G. Knepley PetscBdPointFunc f0Bd, f1Bd; 38159252d075SMatthew G. Knepley PetscRiemannFunc r; 38169252d075SMatthew G. Knepley 3817c52f1e13SMatthew G. Knepley if (f >= Nf) continue; 38189252d075SMatthew G. Knepley ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr); 38199252d075SMatthew G. Knepley ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr); 38209252d075SMatthew G. Knepley ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr); 38219252d075SMatthew G. Knepley ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr); 38229252d075SMatthew G. Knepley ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr); 38239252d075SMatthew G. Knepley ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr); 38249252d075SMatthew G. Knepley ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr); 38259252d075SMatthew G. Knepley ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr); 38269252d075SMatthew G. Knepley for (gn = 0; gn < numFields; ++gn) { 38279252d075SMatthew G. Knepley const PetscInt g = fields ? fields[gn] : gn; 38289252d075SMatthew G. Knepley PetscPointJac g0, g1, g2, g3; 38299252d075SMatthew G. Knepley PetscPointJac g0p, g1p, g2p, g3p; 38309252d075SMatthew G. Knepley PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd; 38319252d075SMatthew G. Knepley 3832c52f1e13SMatthew G. Knepley if (g >= Nf) continue; 38339252d075SMatthew G. Knepley ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr); 38349252d075SMatthew G. Knepley ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr); 38359252d075SMatthew G. Knepley ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr); 38369252d075SMatthew G. Knepley ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr); 38376c1eb96dSMatthew G. Knepley ierr = PetscDSSetJacobianPreconditioner(newprob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr); 38389252d075SMatthew G. Knepley ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr); 38399252d075SMatthew G. Knepley } 38409252d075SMatthew G. Knepley } 38419252d075SMatthew G. Knepley PetscFunctionReturn(0); 38429252d075SMatthew G. Knepley } 38439252d075SMatthew G. Knepley 3844da51fcedSMatthew G. Knepley /*@ 3845da51fcedSMatthew G. Knepley PetscDSCopyEquations - Copy all pointwise function pointers to the new problem 3846da51fcedSMatthew G. Knepley 3847da51fcedSMatthew G. Knepley Not collective 3848da51fcedSMatthew G. Knepley 3849da51fcedSMatthew G. Knepley Input Parameter: 3850da51fcedSMatthew G. Knepley . prob - The PetscDS object 3851da51fcedSMatthew G. Knepley 3852da51fcedSMatthew G. Knepley Output Parameter: 3853da51fcedSMatthew G. Knepley . newprob - The PetscDS copy 3854da51fcedSMatthew G. Knepley 3855da51fcedSMatthew G. Knepley Level: intermediate 3856da51fcedSMatthew G. Knepley 38579252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 3858da51fcedSMatthew G. Knepley @*/ 3859da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob) 3860da51fcedSMatthew G. Knepley { 3861b8025e53SMatthew G. Knepley PetscWeakForm wf, newwf; 38629252d075SMatthew G. Knepley PetscInt Nf, Ng; 3863da51fcedSMatthew G. Knepley PetscErrorCode ierr; 3864da51fcedSMatthew G. Knepley 3865da51fcedSMatthew G. Knepley PetscFunctionBegin; 3866da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3867da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 3868da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3869da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr); 387013903a91SSatish Balay if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng); 3871b8025e53SMatthew G. Knepley ierr = PetscDSGetWeakForm(prob, &wf);CHKERRQ(ierr); 3872b8025e53SMatthew G. Knepley ierr = PetscDSGetWeakForm(newprob, &newwf);CHKERRQ(ierr); 3873b8025e53SMatthew G. Knepley ierr = PetscWeakFormCopy(wf, newwf);CHKERRQ(ierr); 38749252d075SMatthew G. Knepley PetscFunctionReturn(0); 38759252d075SMatthew G. Knepley } 387645480ffeSMatthew G. Knepley 38779252d075SMatthew G. Knepley /*@ 38789252d075SMatthew G. Knepley PetscDSCopyConstants - Copy all constants to the new problem 3879da51fcedSMatthew G. Knepley 38809252d075SMatthew G. Knepley Not collective 38819252d075SMatthew G. Knepley 38829252d075SMatthew G. Knepley Input Parameter: 38839252d075SMatthew G. Knepley . prob - The PetscDS object 38849252d075SMatthew G. Knepley 38859252d075SMatthew G. Knepley Output Parameter: 38869252d075SMatthew G. Knepley . newprob - The PetscDS copy 38879252d075SMatthew G. Knepley 38889252d075SMatthew G. Knepley Level: intermediate 38899252d075SMatthew G. Knepley 38909252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 38919252d075SMatthew G. Knepley @*/ 38929252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob) 38939252d075SMatthew G. Knepley { 38949252d075SMatthew G. Knepley PetscInt Nc; 38959252d075SMatthew G. Knepley const PetscScalar *constants; 38969252d075SMatthew G. Knepley PetscErrorCode ierr; 38979252d075SMatthew G. Knepley 38989252d075SMatthew G. Knepley PetscFunctionBegin; 38999252d075SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 39009252d075SMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 39019252d075SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr); 39029252d075SMatthew G. Knepley ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr); 3903da51fcedSMatthew G. Knepley PetscFunctionReturn(0); 3904da51fcedSMatthew G. Knepley } 3905da51fcedSMatthew G. Knepley 390645480ffeSMatthew G. Knepley /*@ 390745480ffeSMatthew G. Knepley PetscDSCopyExactSolutions - Copy all exact solutions to the new problem 390845480ffeSMatthew G. Knepley 390945480ffeSMatthew G. Knepley Not collective 391045480ffeSMatthew G. Knepley 391145480ffeSMatthew G. Knepley Input Parameter: 391245480ffeSMatthew G. Knepley . ds - The PetscDS object 391345480ffeSMatthew G. Knepley 391445480ffeSMatthew G. Knepley Output Parameter: 391545480ffeSMatthew G. Knepley . newds - The PetscDS copy 391645480ffeSMatthew G. Knepley 391745480ffeSMatthew G. Knepley Level: intermediate 391845480ffeSMatthew G. Knepley 391945480ffeSMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 392045480ffeSMatthew G. Knepley @*/ 392145480ffeSMatthew G. Knepley PetscErrorCode PetscDSCopyExactSolutions(PetscDS ds, PetscDS newds) 392245480ffeSMatthew G. Knepley { 392345480ffeSMatthew G. Knepley PetscSimplePointFunc sol; 392445480ffeSMatthew G. Knepley void *ctx; 392545480ffeSMatthew G. Knepley PetscInt Nf, f; 392645480ffeSMatthew G. Knepley PetscErrorCode ierr; 392745480ffeSMatthew G. Knepley 392845480ffeSMatthew G. Knepley PetscFunctionBegin; 392945480ffeSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 393045480ffeSMatthew G. Knepley PetscValidHeaderSpecific(newds, PETSCDS_CLASSID, 2); 393145480ffeSMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 393245480ffeSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 393345480ffeSMatthew G. Knepley ierr = PetscDSGetExactSolution(ds, f, &sol, &ctx);CHKERRQ(ierr); 393445480ffeSMatthew G. Knepley ierr = PetscDSSetExactSolution(newds, f, sol, ctx);CHKERRQ(ierr); 393545480ffeSMatthew G. Knepley ierr = PetscDSGetExactSolutionTimeDerivative(ds, f, &sol, &ctx);CHKERRQ(ierr); 393645480ffeSMatthew G. Knepley ierr = PetscDSSetExactSolutionTimeDerivative(newds, f, sol, ctx);CHKERRQ(ierr); 393745480ffeSMatthew G. Knepley } 393845480ffeSMatthew G. Knepley PetscFunctionReturn(0); 393945480ffeSMatthew G. Knepley } 394045480ffeSMatthew G. Knepley 3941b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob) 3942b1353e8eSMatthew G. Knepley { 3943df3a45bdSMatthew G. Knepley PetscInt dim, Nf, f; 3944b1353e8eSMatthew G. Knepley PetscErrorCode ierr; 3945b1353e8eSMatthew G. Knepley 3946b1353e8eSMatthew G. Knepley PetscFunctionBegin; 3947b1353e8eSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 3948b1353e8eSMatthew G. Knepley PetscValidPointer(subprob, 3); 3949b1353e8eSMatthew G. Knepley if (height == 0) {*subprob = prob; PetscFunctionReturn(0);} 3950b1353e8eSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 3951df3a45bdSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 3952df3a45bdSMatthew 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); 3953df3a45bdSMatthew G. Knepley if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);} 3954df3a45bdSMatthew G. Knepley if (!prob->subprobs[height-1]) { 3955b1353e8eSMatthew G. Knepley PetscInt cdim; 3956b1353e8eSMatthew G. Knepley 3957df3a45bdSMatthew G. Knepley ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr); 3958b1353e8eSMatthew G. Knepley ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr); 3959df3a45bdSMatthew G. Knepley ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr); 3960b1353e8eSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3961b1353e8eSMatthew G. Knepley PetscFE subfe; 3962b1353e8eSMatthew G. Knepley PetscObject obj; 3963b1353e8eSMatthew G. Knepley PetscClassId id; 3964b1353e8eSMatthew G. Knepley 3965b1353e8eSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 3966b1353e8eSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3967b1353e8eSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);} 3968b1353e8eSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f); 3969df3a45bdSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr); 3970b1353e8eSMatthew G. Knepley } 3971b1353e8eSMatthew G. Knepley } 3972df3a45bdSMatthew G. Knepley *subprob = prob->subprobs[height-1]; 3973b1353e8eSMatthew G. Knepley PetscFunctionReturn(0); 3974b1353e8eSMatthew G. Knepley } 3975b1353e8eSMatthew G. Knepley 3976665f567fSMatthew G. Knepley PetscErrorCode PetscDSGetDiscType_Internal(PetscDS ds, PetscInt f, PetscDiscType *disctype) 3977c7bd5f0bSMatthew G. Knepley { 3978c7bd5f0bSMatthew G. Knepley PetscObject obj; 3979c7bd5f0bSMatthew G. Knepley PetscClassId id; 3980c7bd5f0bSMatthew G. Knepley PetscInt Nf; 3981c7bd5f0bSMatthew G. Knepley PetscErrorCode ierr; 3982c7bd5f0bSMatthew G. Knepley 3983c7bd5f0bSMatthew G. Knepley PetscFunctionBegin; 3984c7bd5f0bSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 3985665f567fSMatthew G. Knepley PetscValidPointer(disctype, 3); 3986665f567fSMatthew G. Knepley *disctype = PETSC_DISC_NONE; 3987c7bd5f0bSMatthew G. Knepley ierr = PetscDSGetNumFields(ds, &Nf);CHKERRQ(ierr); 3988c7bd5f0bSMatthew G. Knepley if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) ds), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf); 3989c7bd5f0bSMatthew G. Knepley ierr = PetscDSGetDiscretization(ds, f, &obj);CHKERRQ(ierr); 3990665f567fSMatthew G. Knepley if (obj) { 3991c7bd5f0bSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3992665f567fSMatthew G. Knepley if (id == PETSCFE_CLASSID) *disctype = PETSC_DISC_FE; 3993665f567fSMatthew G. Knepley else *disctype = PETSC_DISC_FV; 3994665f567fSMatthew G. Knepley } 3995c7bd5f0bSMatthew G. Knepley PetscFunctionReturn(0); 3996c7bd5f0bSMatthew G. Knepley } 3997c7bd5f0bSMatthew G. Knepley 39986528b96dSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS ds) 39992764a2aaSMatthew G. Knepley { 4000931fb3b8SToby Isaac PetscErrorCode ierr; 4001931fb3b8SToby Isaac 40022764a2aaSMatthew G. Knepley PetscFunctionBegin; 40036528b96dSMatthew G. Knepley ierr = PetscFree(ds->data);CHKERRQ(ierr); 40042764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 40052764a2aaSMatthew G. Knepley } 40062764a2aaSMatthew G. Knepley 40076528b96dSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS ds) 40082764a2aaSMatthew G. Knepley { 40092764a2aaSMatthew G. Knepley PetscFunctionBegin; 40106528b96dSMatthew G. Knepley ds->ops->setfromoptions = NULL; 40116528b96dSMatthew G. Knepley ds->ops->setup = NULL; 40126528b96dSMatthew G. Knepley ds->ops->view = NULL; 40136528b96dSMatthew G. Knepley ds->ops->destroy = PetscDSDestroy_Basic; 40142764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 40152764a2aaSMatthew G. Knepley } 40162764a2aaSMatthew G. Knepley 40172764a2aaSMatthew G. Knepley /*MC 40182764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 40192764a2aaSMatthew G. Knepley 40202764a2aaSMatthew G. Knepley Level: intermediate 40212764a2aaSMatthew G. Knepley 40222764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType() 40232764a2aaSMatthew G. Knepley M*/ 40242764a2aaSMatthew G. Knepley 40256528b96dSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS ds) 40262764a2aaSMatthew G. Knepley { 40272764a2aaSMatthew G. Knepley PetscDS_Basic *b; 40282764a2aaSMatthew G. Knepley PetscErrorCode ierr; 40292764a2aaSMatthew G. Knepley 40302764a2aaSMatthew G. Knepley PetscFunctionBegin; 40316528b96dSMatthew G. Knepley PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 40326528b96dSMatthew G. Knepley ierr = PetscNewLog(ds, &b);CHKERRQ(ierr); 40336528b96dSMatthew G. Knepley ds->data = b; 40342764a2aaSMatthew G. Knepley 40356528b96dSMatthew G. Knepley ierr = PetscDSInitialize_Basic(ds);CHKERRQ(ierr); 40362764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 40372764a2aaSMatthew G. Knepley } 4038