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 82764a2aaSMatthew G. Knepley /*@C 92764a2aaSMatthew G. Knepley PetscDSRegister - Adds a new PetscDS implementation 102764a2aaSMatthew G. Knepley 112764a2aaSMatthew G. Knepley Not Collective 122764a2aaSMatthew G. Knepley 132764a2aaSMatthew G. Knepley Input Parameters: 142764a2aaSMatthew G. Knepley + name - The name of a new user-defined creation routine 152764a2aaSMatthew G. Knepley - create_func - The creation routine itself 162764a2aaSMatthew G. Knepley 172764a2aaSMatthew G. Knepley Notes: 182764a2aaSMatthew G. Knepley PetscDSRegister() may be called multiple times to add several user-defined PetscDSs 192764a2aaSMatthew G. Knepley 202764a2aaSMatthew G. Knepley Sample usage: 212764a2aaSMatthew G. Knepley .vb 222764a2aaSMatthew G. Knepley PetscDSRegister("my_ds", MyPetscDSCreate); 232764a2aaSMatthew G. Knepley .ve 242764a2aaSMatthew G. Knepley 252764a2aaSMatthew G. Knepley Then, your PetscDS type can be chosen with the procedural interface via 262764a2aaSMatthew G. Knepley .vb 272764a2aaSMatthew G. Knepley PetscDSCreate(MPI_Comm, PetscDS *); 282764a2aaSMatthew G. Knepley PetscDSSetType(PetscDS, "my_ds"); 292764a2aaSMatthew G. Knepley .ve 302764a2aaSMatthew G. Knepley or at runtime via the option 312764a2aaSMatthew G. Knepley .vb 322764a2aaSMatthew G. Knepley -petscds_type my_ds 332764a2aaSMatthew G. Knepley .ve 342764a2aaSMatthew G. Knepley 352764a2aaSMatthew G. Knepley Level: advanced 362764a2aaSMatthew G. Knepley 372764a2aaSMatthew G. Knepley .keywords: PetscDS, register 382764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy() 392764a2aaSMatthew G. Knepley 402764a2aaSMatthew G. Knepley @*/ 412764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS)) 422764a2aaSMatthew G. Knepley { 432764a2aaSMatthew G. Knepley PetscErrorCode ierr; 442764a2aaSMatthew G. Knepley 452764a2aaSMatthew G. Knepley PetscFunctionBegin; 462764a2aaSMatthew G. Knepley ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr); 472764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 482764a2aaSMatthew G. Knepley } 492764a2aaSMatthew G. Knepley 502764a2aaSMatthew G. Knepley /*@C 512764a2aaSMatthew G. Knepley PetscDSSetType - Builds a particular PetscDS 522764a2aaSMatthew G. Knepley 532764a2aaSMatthew G. Knepley Collective on PetscDS 542764a2aaSMatthew G. Knepley 552764a2aaSMatthew G. Knepley Input Parameters: 562764a2aaSMatthew G. Knepley + prob - The PetscDS object 572764a2aaSMatthew G. Knepley - name - The kind of system 582764a2aaSMatthew G. Knepley 592764a2aaSMatthew G. Knepley Options Database Key: 602764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types 612764a2aaSMatthew G. Knepley 622764a2aaSMatthew G. Knepley Level: intermediate 632764a2aaSMatthew G. Knepley 642764a2aaSMatthew G. Knepley .keywords: PetscDS, set, type 652764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate() 662764a2aaSMatthew G. Knepley @*/ 672764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name) 682764a2aaSMatthew G. Knepley { 692764a2aaSMatthew G. Knepley PetscErrorCode (*r)(PetscDS); 702764a2aaSMatthew G. Knepley PetscBool match; 712764a2aaSMatthew G. Knepley PetscErrorCode ierr; 722764a2aaSMatthew G. Knepley 732764a2aaSMatthew G. Knepley PetscFunctionBegin; 742764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 752764a2aaSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr); 762764a2aaSMatthew G. Knepley if (match) PetscFunctionReturn(0); 772764a2aaSMatthew G. Knepley 780f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 792764a2aaSMatthew G. Knepley ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr); 802764a2aaSMatthew G. Knepley if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name); 812764a2aaSMatthew G. Knepley 822764a2aaSMatthew G. Knepley if (prob->ops->destroy) { 832764a2aaSMatthew G. Knepley ierr = (*prob->ops->destroy)(prob);CHKERRQ(ierr); 842764a2aaSMatthew G. Knepley prob->ops->destroy = NULL; 852764a2aaSMatthew G. Knepley } 862764a2aaSMatthew G. Knepley ierr = (*r)(prob);CHKERRQ(ierr); 872764a2aaSMatthew G. Knepley ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr); 882764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 892764a2aaSMatthew G. Knepley } 902764a2aaSMatthew G. Knepley 912764a2aaSMatthew G. Knepley /*@C 922764a2aaSMatthew G. Knepley PetscDSGetType - Gets the PetscDS type name (as a string) from the object. 932764a2aaSMatthew G. Knepley 942764a2aaSMatthew G. Knepley Not Collective 952764a2aaSMatthew G. Knepley 962764a2aaSMatthew G. Knepley Input Parameter: 972764a2aaSMatthew G. Knepley . prob - The PetscDS 982764a2aaSMatthew G. Knepley 992764a2aaSMatthew G. Knepley Output Parameter: 1002764a2aaSMatthew G. Knepley . name - The PetscDS type name 1012764a2aaSMatthew G. Knepley 1022764a2aaSMatthew G. Knepley Level: intermediate 1032764a2aaSMatthew G. Knepley 1042764a2aaSMatthew G. Knepley .keywords: PetscDS, get, type, name 1052764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate() 1062764a2aaSMatthew G. Knepley @*/ 1072764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name) 1082764a2aaSMatthew G. Knepley { 1092764a2aaSMatthew G. Knepley PetscErrorCode ierr; 1102764a2aaSMatthew G. Knepley 1112764a2aaSMatthew G. Knepley PetscFunctionBegin; 1122764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 113c959eef4SJed Brown PetscValidPointer(name, 2); 1140f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 1152764a2aaSMatthew G. Knepley *name = ((PetscObject) prob)->type_name; 1162764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 1172764a2aaSMatthew G. Knepley } 1182764a2aaSMatthew G. Knepley 1197d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer) 1207d8a60eaSMatthew G. Knepley { 1217d8a60eaSMatthew G. Knepley PetscViewerFormat format; 12297b6e6e8SMatthew G. Knepley const PetscScalar *constants; 12397b6e6e8SMatthew G. Knepley PetscInt numConstants, f; 1247d8a60eaSMatthew G. Knepley PetscErrorCode ierr; 1257d8a60eaSMatthew G. Knepley 1267d8a60eaSMatthew G. Knepley PetscFunctionBegin; 1277d8a60eaSMatthew G. Knepley ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr); 1287d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr); 1297d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 1307d8a60eaSMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1317d8a60eaSMatthew G. Knepley PetscObject obj; 1327d8a60eaSMatthew G. Knepley PetscClassId id; 1337d8a60eaSMatthew G. Knepley const char *name; 1347d8a60eaSMatthew G. Knepley PetscInt Nc; 1357d8a60eaSMatthew G. Knepley 1367d8a60eaSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 1377d8a60eaSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 1387d8a60eaSMatthew G. Knepley ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr); 1397d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr); 1407d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 1417d8a60eaSMatthew G. Knepley ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr); 1427d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr); 1437d8a60eaSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 1447d8a60eaSMatthew G. Knepley ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr); 1457d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr); 1467d8a60eaSMatthew G. Knepley } 14797b6e6e8SMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f); 14897b6e6e8SMatthew G. Knepley if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%D components", Nc);CHKERRQ(ierr);} 14997b6e6e8SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, "%D component ", Nc);CHKERRQ(ierr);} 150249df284SMatthew G. Knepley if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);} 151249df284SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);} 152a6cbbb48SMatthew G. Knepley if (prob->adjacency[f*2+0]) { 153a6cbbb48SMatthew G. Knepley if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM++)");CHKERRQ(ierr);} 154a6cbbb48SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM)");CHKERRQ(ierr);} 155a6cbbb48SMatthew G. Knepley } else { 156a6cbbb48SMatthew G. Knepley if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FEM)");CHKERRQ(ierr);} 157a6cbbb48SMatthew G. Knepley else {ierr = PetscViewerASCIIPrintf(viewer, " (adj FUNKY)");CHKERRQ(ierr);} 158a6cbbb48SMatthew G. Knepley } 1597d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr); 1607d8a60eaSMatthew G. Knepley if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 1617d8a60eaSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);} 1627d8a60eaSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);} 1637d8a60eaSMatthew G. Knepley } 1647d8a60eaSMatthew G. Knepley } 16597b6e6e8SMatthew G. Knepley ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr); 16697b6e6e8SMatthew G. Knepley if (numConstants) { 16797b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr); 16897b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 16997b6e6e8SMatthew G. Knepley for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", constants[f]);CHKERRQ(ierr);} 17097b6e6e8SMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 17197b6e6e8SMatthew G. Knepley } 1727d8a60eaSMatthew G. Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 1737d8a60eaSMatthew G. Knepley PetscFunctionReturn(0); 1747d8a60eaSMatthew G. Knepley } 1757d8a60eaSMatthew G. Knepley 1762764a2aaSMatthew G. Knepley /*@C 1772764a2aaSMatthew G. Knepley PetscDSView - Views a PetscDS 1782764a2aaSMatthew G. Knepley 1792764a2aaSMatthew G. Knepley Collective on PetscDS 1802764a2aaSMatthew G. Knepley 1812764a2aaSMatthew G. Knepley Input Parameter: 1822764a2aaSMatthew G. Knepley + prob - the PetscDS object to view 1832764a2aaSMatthew G. Knepley - v - the viewer 1842764a2aaSMatthew G. Knepley 1852764a2aaSMatthew G. Knepley Level: developer 1862764a2aaSMatthew G. Knepley 1872764a2aaSMatthew G. Knepley .seealso PetscDSDestroy() 1882764a2aaSMatthew G. Knepley @*/ 1892764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v) 1902764a2aaSMatthew G. Knepley { 1917d8a60eaSMatthew G. Knepley PetscBool iascii; 1922764a2aaSMatthew G. Knepley PetscErrorCode ierr; 1932764a2aaSMatthew G. Knepley 1942764a2aaSMatthew G. Knepley PetscFunctionBegin; 1952764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1962764a2aaSMatthew G. Knepley if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);} 1977d8a60eaSMatthew G. Knepley else {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);} 1987d8a60eaSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr); 1997d8a60eaSMatthew G. Knepley if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);} 2002764a2aaSMatthew G. Knepley if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);} 2012764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 2022764a2aaSMatthew G. Knepley } 2032764a2aaSMatthew G. Knepley 2042764a2aaSMatthew G. Knepley /*@ 2052764a2aaSMatthew G. Knepley PetscDSSetFromOptions - sets parameters in a PetscDS from the options database 2062764a2aaSMatthew G. Knepley 2072764a2aaSMatthew G. Knepley Collective on PetscDS 2082764a2aaSMatthew G. Knepley 2092764a2aaSMatthew G. Knepley Input Parameter: 2102764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for 2112764a2aaSMatthew G. Knepley 2122764a2aaSMatthew G. Knepley Options Database: 2132764a2aaSMatthew G. Knepley 2142764a2aaSMatthew G. Knepley Level: developer 2152764a2aaSMatthew G. Knepley 2162764a2aaSMatthew G. Knepley .seealso PetscDSView() 2172764a2aaSMatthew G. Knepley @*/ 2182764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob) 2192764a2aaSMatthew G. Knepley { 220f1fd5e65SToby Isaac DSBoundary b; 2212764a2aaSMatthew G. Knepley const char *defaultType; 2222764a2aaSMatthew G. Knepley char name[256]; 2232764a2aaSMatthew G. Knepley PetscBool flg; 2242764a2aaSMatthew G. Knepley PetscErrorCode ierr; 2252764a2aaSMatthew G. Knepley 2262764a2aaSMatthew G. Knepley PetscFunctionBegin; 2272764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2282764a2aaSMatthew G. Knepley if (!((PetscObject) prob)->type_name) { 2292764a2aaSMatthew G. Knepley defaultType = PETSCDSBASIC; 2302764a2aaSMatthew G. Knepley } else { 2312764a2aaSMatthew G. Knepley defaultType = ((PetscObject) prob)->type_name; 2322764a2aaSMatthew G. Knepley } 2330f51fdf8SToby Isaac ierr = PetscDSRegisterAll();CHKERRQ(ierr); 2342764a2aaSMatthew G. Knepley 2352764a2aaSMatthew G. Knepley ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr); 236f1fd5e65SToby Isaac for (b = prob->boundary; b; b = b->next) { 237f1fd5e65SToby Isaac char optname[1024]; 238f1fd5e65SToby Isaac PetscInt ids[1024], len = 1024; 239f1fd5e65SToby Isaac PetscBool flg; 240f1fd5e65SToby Isaac 241f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr); 242f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 243f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr); 244f1fd5e65SToby Isaac if (flg) { 245f1fd5e65SToby Isaac b->numids = len; 246f1fd5e65SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 247f1fd5e65SToby Isaac ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr); 248f1fd5e65SToby Isaac ierr = PetscMemcpy(b->ids, ids, len*sizeof(PetscInt));CHKERRQ(ierr); 249f1fd5e65SToby Isaac } 250e7b0402cSSander Arens len = 1024; 251f1fd5e65SToby Isaac ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr); 252f1fd5e65SToby Isaac ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr); 253f1fd5e65SToby Isaac ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr); 254f1fd5e65SToby Isaac if (flg) { 255f1fd5e65SToby Isaac b->numcomps = len; 256f1fd5e65SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 257f1fd5e65SToby Isaac ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr); 258f1fd5e65SToby Isaac ierr = PetscMemcpy(b->comps, ids, len*sizeof(PetscInt));CHKERRQ(ierr); 259f1fd5e65SToby Isaac } 260f1fd5e65SToby Isaac } 2612764a2aaSMatthew G. Knepley ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr); 2622764a2aaSMatthew G. Knepley if (flg) { 2632764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, name);CHKERRQ(ierr); 2642764a2aaSMatthew G. Knepley } else if (!((PetscObject) prob)->type_name) { 2652764a2aaSMatthew G. Knepley ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr); 2662764a2aaSMatthew G. Knepley } 2672764a2aaSMatthew G. Knepley if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);} 2682764a2aaSMatthew G. Knepley /* process any options handlers added with PetscObjectAddOptionsHandler() */ 2690633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr); 2702764a2aaSMatthew G. Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 2712764a2aaSMatthew G. Knepley ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr); 2722764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 2732764a2aaSMatthew G. Knepley } 2742764a2aaSMatthew G. Knepley 2752764a2aaSMatthew G. Knepley /*@C 2762764a2aaSMatthew G. Knepley PetscDSSetUp - Construct data structures for the PetscDS 2772764a2aaSMatthew G. Knepley 2782764a2aaSMatthew G. Knepley Collective on PetscDS 2792764a2aaSMatthew G. Knepley 2802764a2aaSMatthew G. Knepley Input Parameter: 2812764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup 2822764a2aaSMatthew G. Knepley 2832764a2aaSMatthew G. Knepley Level: developer 2842764a2aaSMatthew G. Knepley 2852764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy() 2862764a2aaSMatthew G. Knepley @*/ 2872764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob) 2882764a2aaSMatthew G. Knepley { 2892764a2aaSMatthew G. Knepley const PetscInt Nf = prob->Nf; 2902764a2aaSMatthew G. Knepley PetscInt dim, work, NcMax = 0, NqMax = 0, f; 2912764a2aaSMatthew G. Knepley PetscErrorCode ierr; 2922764a2aaSMatthew G. Knepley 2932764a2aaSMatthew G. Knepley PetscFunctionBegin; 2942764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2952764a2aaSMatthew G. Knepley if (prob->setup) PetscFunctionReturn(0); 2962764a2aaSMatthew G. Knepley /* Calculate sizes */ 2972764a2aaSMatthew G. Knepley ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr); 298f744cafaSSander Arens prob->totDim = prob->totComp = 0; 29947e57110SSander Arens ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr); 300f744cafaSSander Arens ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr); 301f744cafaSSander Arens ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisFace,Nf,&prob->basisDerFace);CHKERRQ(ierr); 3022764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 3039de99aefSMatthew G. Knepley PetscObject obj; 3049de99aefSMatthew G. Knepley PetscClassId id; 3052764a2aaSMatthew G. Knepley PetscQuadrature q; 3069de99aefSMatthew G. Knepley PetscInt Nq = 0, Nb, Nc; 3072764a2aaSMatthew G. Knepley 3089de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr); 3099de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 3109de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) { 3119de99aefSMatthew G. Knepley PetscFE fe = (PetscFE) obj; 3129de99aefSMatthew G. Knepley 3132764a2aaSMatthew G. Knepley ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr); 3142764a2aaSMatthew G. Knepley ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr); 3152764a2aaSMatthew G. Knepley ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr); 3162764a2aaSMatthew G. Knepley ierr = PetscFEGetDefaultTabulation(fe, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr); 3174d0b9603SSander Arens ierr = PetscFEGetFaceTabulation(fe, &prob->basisFace[f], &prob->basisDerFace[f], NULL);CHKERRQ(ierr); 3189de99aefSMatthew G. Knepley } else if (id == PETSCFV_CLASSID) { 3199de99aefSMatthew G. Knepley PetscFV fv = (PetscFV) obj; 3209de99aefSMatthew G. Knepley 3219de99aefSMatthew G. Knepley ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr); 3229de99aefSMatthew G. Knepley ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr); 3239c3cf19fSMatthew G. Knepley Nb = Nc; 3246c1a3d01SMatthew G. Knepley ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr); 3254d0b9603SSander Arens /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */ 326abac5ca0SMatthew G. Knepley } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f); 32747e57110SSander Arens prob->Nc[f] = Nc; 32847e57110SSander Arens prob->Nb[f] = Nb; 329194d53e6SMatthew G. Knepley prob->off[f+1] = Nc + prob->off[f]; 330194d53e6SMatthew G. Knepley prob->offDer[f+1] = Nc*dim + prob->offDer[f]; 331a6b92713SMatthew G. Knepley if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);} 3322764a2aaSMatthew G. Knepley NqMax = PetscMax(NqMax, Nq); 3332764a2aaSMatthew G. Knepley NcMax = PetscMax(NcMax, Nc); 3349c3cf19fSMatthew G. Knepley prob->totDim += Nb; 3352764a2aaSMatthew G. Knepley prob->totComp += Nc; 3362764a2aaSMatthew G. Knepley } 3372764a2aaSMatthew G. Knepley work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim)); 3382764a2aaSMatthew G. Knepley /* Allocate works space */ 3392764a2aaSMatthew G. Knepley ierr = PetscMalloc5(prob->totComp,&prob->u,prob->totComp,&prob->u_t,prob->totComp*dim,&prob->u_x,dim,&prob->x,work,&prob->refSpaceDer);CHKERRQ(ierr); 3402764a2aaSMatthew G. Knepley ierr = PetscMalloc6(NqMax*NcMax,&prob->f0,NqMax*NcMax*dim,&prob->f1,NqMax*NcMax*NcMax,&prob->g0,NqMax*NcMax*NcMax*dim,&prob->g1,NqMax*NcMax*NcMax*dim,&prob->g2,NqMax*NcMax*NcMax*dim*dim,&prob->g3);CHKERRQ(ierr); 3412764a2aaSMatthew G. Knepley if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);} 3422764a2aaSMatthew G. Knepley prob->setup = PETSC_TRUE; 3432764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 3442764a2aaSMatthew G. Knepley } 3452764a2aaSMatthew G. Knepley 3462764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob) 3472764a2aaSMatthew G. Knepley { 3482764a2aaSMatthew G. Knepley PetscErrorCode ierr; 3492764a2aaSMatthew G. Knepley 3502764a2aaSMatthew G. Knepley PetscFunctionBegin; 35147e57110SSander Arens ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr); 352f744cafaSSander Arens ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr); 353f744cafaSSander Arens ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisFace,prob->basisDerFace);CHKERRQ(ierr); 3542764a2aaSMatthew G. Knepley ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr); 3552764a2aaSMatthew G. Knepley ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr); 3562764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 3572764a2aaSMatthew G. Knepley } 3582764a2aaSMatthew G. Knepley 3592764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew) 3602764a2aaSMatthew G. Knepley { 361f744cafaSSander Arens PetscObject *tmpd; 362a6cbbb48SMatthew G. Knepley PetscBool *tmpi, *tmpa; 3632aa1fc23SMatthew G. Knepley PetscPointFunc *tmpobj, *tmpf; 364b7e05686SMatthew G. Knepley PetscPointJac *tmpg, *tmpgp, *tmpgt; 3652aa1fc23SMatthew G. Knepley PetscBdPointFunc *tmpfbd; 3662aa1fc23SMatthew G. Knepley PetscBdPointJac *tmpgbd; 367194d53e6SMatthew G. Knepley PetscRiemannFunc *tmpr; 368c371a6d1SMatthew G. Knepley PetscSimplePointFunc *tmpexactSol; 3690c2f2876SMatthew G. Knepley void **tmpctx; 370a6cbbb48SMatthew G. Knepley PetscInt Nf = prob->Nf, f, i; 3712764a2aaSMatthew G. Knepley PetscErrorCode ierr; 3722764a2aaSMatthew G. Knepley 3732764a2aaSMatthew G. Knepley PetscFunctionBegin; 3742764a2aaSMatthew G. Knepley if (Nf >= NfNew) PetscFunctionReturn(0); 3752764a2aaSMatthew G. Knepley prob->setup = PETSC_FALSE; 3762764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr); 377f744cafaSSander Arens ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr); 378f744cafaSSander Arens for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; for (i = 0; i < 2; ++i) tmpa[f*2+i] = prob->adjacency[f*2+i];} 379f744cafaSSander Arens for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpa[f*2+0] = PETSC_FALSE; tmpa[f*2+1] = PETSC_TRUE;} 380f744cafaSSander Arens ierr = PetscFree3(prob->disc, prob->implicit, prob->adjacency);CHKERRQ(ierr); 3812764a2aaSMatthew G. Knepley prob->Nf = NfNew; 3822764a2aaSMatthew G. Knepley prob->disc = tmpd; 383249df284SMatthew G. Knepley prob->implicit = tmpi; 384a6cbbb48SMatthew G. Knepley prob->adjacency = tmpa; 385b7e05686SMatthew G. Knepley ierr = PetscCalloc7(NfNew, &tmpobj, NfNew*2, &tmpf, NfNew*NfNew*4, &tmpg, NfNew*NfNew*4, &tmpgp, NfNew*NfNew*4, &tmpgt, NfNew, &tmpr, NfNew, &tmpctx);CHKERRQ(ierr); 3862764a2aaSMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f]; 3872764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f]; 3882764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f]; 389475e0ac9SMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f]; 3900c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f]; 3910c2f2876SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f]; 3922764a2aaSMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL; 3932764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL; 3942764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL; 395475e0ac9SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL; 396b7e05686SMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL; 3970c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL; 3980c2f2876SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL; 399b7e05686SMatthew G. Knepley ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr); 4002764a2aaSMatthew G. Knepley prob->obj = tmpobj; 4012764a2aaSMatthew G. Knepley prob->f = tmpf; 4022764a2aaSMatthew G. Knepley prob->g = tmpg; 403475e0ac9SMatthew G. Knepley prob->gp = tmpgp; 404b7e05686SMatthew G. Knepley prob->gt = tmpgt; 4050c2f2876SMatthew G. Knepley prob->r = tmpr; 4060c2f2876SMatthew G. Knepley prob->ctx = tmpctx; 407c371a6d1SMatthew G. Knepley ierr = PetscCalloc3(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew, &tmpexactSol);CHKERRQ(ierr); 4082764a2aaSMatthew G. Knepley for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f]; 4092764a2aaSMatthew G. Knepley for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f]; 410c371a6d1SMatthew G. Knepley for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f]; 4112764a2aaSMatthew G. Knepley for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL; 4122764a2aaSMatthew G. Knepley for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL; 413c371a6d1SMatthew G. Knepley for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL; 414c371a6d1SMatthew G. Knepley ierr = PetscFree3(prob->fBd, prob->gBd, prob->exactSol);CHKERRQ(ierr); 4152764a2aaSMatthew G. Knepley prob->fBd = tmpfbd; 4162764a2aaSMatthew G. Knepley prob->gBd = tmpgbd; 417c371a6d1SMatthew G. Knepley prob->exactSol = tmpexactSol; 4182764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4192764a2aaSMatthew G. Knepley } 4202764a2aaSMatthew G. Knepley 4212764a2aaSMatthew G. Knepley /*@ 4222764a2aaSMatthew G. Knepley PetscDSDestroy - Destroys a PetscDS object 4232764a2aaSMatthew G. Knepley 4242764a2aaSMatthew G. Knepley Collective on PetscDS 4252764a2aaSMatthew G. Knepley 4262764a2aaSMatthew G. Knepley Input Parameter: 4272764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy 4282764a2aaSMatthew G. Knepley 4292764a2aaSMatthew G. Knepley Level: developer 4302764a2aaSMatthew G. Knepley 4312764a2aaSMatthew G. Knepley .seealso PetscDSView() 4322764a2aaSMatthew G. Knepley @*/ 4332764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob) 4342764a2aaSMatthew G. Knepley { 4352764a2aaSMatthew G. Knepley PetscInt f; 43658ebd649SToby Isaac DSBoundary next; 4372764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4382764a2aaSMatthew G. Knepley 4392764a2aaSMatthew G. Knepley PetscFunctionBegin; 4402764a2aaSMatthew G. Knepley if (!*prob) PetscFunctionReturn(0); 4412764a2aaSMatthew G. Knepley PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1); 4422764a2aaSMatthew G. Knepley 4432764a2aaSMatthew G. Knepley if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);} 4442764a2aaSMatthew G. Knepley ((PetscObject) (*prob))->refct = 0; 4452764a2aaSMatthew G. Knepley ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr); 4462764a2aaSMatthew G. Knepley for (f = 0; f < (*prob)->Nf; ++f) { 4472764a2aaSMatthew G. Knepley ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr); 4482764a2aaSMatthew G. Knepley } 449f744cafaSSander Arens ierr = PetscFree3((*prob)->disc, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr); 450b7e05686SMatthew G. Knepley ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr); 451c371a6d1SMatthew G. Knepley ierr = PetscFree3((*prob)->fBd,(*prob)->gBd,(*prob)->exactSol);CHKERRQ(ierr); 4522764a2aaSMatthew G. Knepley if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);} 45358ebd649SToby Isaac next = (*prob)->boundary; 45458ebd649SToby Isaac while (next) { 45558ebd649SToby Isaac DSBoundary b = next; 45658ebd649SToby Isaac 45758ebd649SToby Isaac next = b->next; 45858ebd649SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 45958ebd649SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 46058ebd649SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 46158ebd649SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 46258ebd649SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 46358ebd649SToby Isaac } 46497b6e6e8SMatthew G. Knepley ierr = PetscFree((*prob)->constants);CHKERRQ(ierr); 4652764a2aaSMatthew G. Knepley ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr); 4662764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 4672764a2aaSMatthew G. Knepley } 4682764a2aaSMatthew G. Knepley 4692764a2aaSMatthew G. Knepley /*@ 4702764a2aaSMatthew G. Knepley PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType(). 4712764a2aaSMatthew G. Knepley 4722764a2aaSMatthew G. Knepley Collective on MPI_Comm 4732764a2aaSMatthew G. Knepley 4742764a2aaSMatthew G. Knepley Input Parameter: 4752764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object 4762764a2aaSMatthew G. Knepley 4772764a2aaSMatthew G. Knepley Output Parameter: 4782764a2aaSMatthew G. Knepley . prob - The PetscDS object 4792764a2aaSMatthew G. Knepley 4802764a2aaSMatthew G. Knepley Level: beginner 4812764a2aaSMatthew G. Knepley 4822764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC 4832764a2aaSMatthew G. Knepley @*/ 4842764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob) 4852764a2aaSMatthew G. Knepley { 4862764a2aaSMatthew G. Knepley PetscDS p; 4872764a2aaSMatthew G. Knepley PetscErrorCode ierr; 4882764a2aaSMatthew G. Knepley 4892764a2aaSMatthew G. Knepley PetscFunctionBegin; 4902764a2aaSMatthew G. Knepley PetscValidPointer(prob, 2); 4912764a2aaSMatthew G. Knepley *prob = NULL; 4922764a2aaSMatthew G. Knepley ierr = PetscDSInitializePackage();CHKERRQ(ierr); 4932764a2aaSMatthew G. Knepley 49473107ff1SLisandro Dalcin ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr); 4952764a2aaSMatthew G. Knepley 4962764a2aaSMatthew G. Knepley p->Nf = 0; 4972764a2aaSMatthew G. Knepley p->setup = PETSC_FALSE; 49897b6e6e8SMatthew G. Knepley p->numConstants = 0; 49997b6e6e8SMatthew G. Knepley p->constants = NULL; 5002764a2aaSMatthew G. Knepley 5012764a2aaSMatthew G. Knepley *prob = p; 5022764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5032764a2aaSMatthew G. Knepley } 5042764a2aaSMatthew G. Knepley 505bc4ae4beSMatthew G. Knepley /*@ 506bc4ae4beSMatthew G. Knepley PetscDSGetNumFields - Returns the number of fields in the DS 507bc4ae4beSMatthew G. Knepley 508bc4ae4beSMatthew G. Knepley Not collective 509bc4ae4beSMatthew G. Knepley 510bc4ae4beSMatthew G. Knepley Input Parameter: 511bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 512bc4ae4beSMatthew G. Knepley 513bc4ae4beSMatthew G. Knepley Output Parameter: 514bc4ae4beSMatthew G. Knepley . Nf - The number of fields 515bc4ae4beSMatthew G. Knepley 516bc4ae4beSMatthew G. Knepley Level: beginner 517bc4ae4beSMatthew G. Knepley 518bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate() 519bc4ae4beSMatthew G. Knepley @*/ 5202764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf) 5212764a2aaSMatthew G. Knepley { 5222764a2aaSMatthew G. Knepley PetscFunctionBegin; 5232764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 5242764a2aaSMatthew G. Knepley PetscValidPointer(Nf, 2); 5252764a2aaSMatthew G. Knepley *Nf = prob->Nf; 5262764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5272764a2aaSMatthew G. Knepley } 5282764a2aaSMatthew G. Knepley 529bc4ae4beSMatthew G. Knepley /*@ 530bc4ae4beSMatthew G. Knepley PetscDSGetSpatialDimension - Returns the spatial dimension of the DS 531bc4ae4beSMatthew G. Knepley 532bc4ae4beSMatthew G. Knepley Not collective 533bc4ae4beSMatthew G. Knepley 534bc4ae4beSMatthew G. Knepley Input Parameter: 535bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 536bc4ae4beSMatthew G. Knepley 537bc4ae4beSMatthew G. Knepley Output Parameter: 538bc4ae4beSMatthew G. Knepley . dim - The spatial dimension 539bc4ae4beSMatthew G. Knepley 540bc4ae4beSMatthew G. Knepley Level: beginner 541bc4ae4beSMatthew G. Knepley 542bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 543bc4ae4beSMatthew G. Knepley @*/ 5442764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim) 5452764a2aaSMatthew G. Knepley { 5462764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5472764a2aaSMatthew G. Knepley 5482764a2aaSMatthew G. Knepley PetscFunctionBegin; 5492764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 5502764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 5512764a2aaSMatthew G. Knepley *dim = 0; 5529de99aefSMatthew G. Knepley if (prob->Nf) { 5539de99aefSMatthew G. Knepley PetscObject obj; 5549de99aefSMatthew G. Knepley PetscClassId id; 5559de99aefSMatthew G. Knepley 5569de99aefSMatthew G. Knepley ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr); 5579de99aefSMatthew G. Knepley ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr); 5589de99aefSMatthew G. Knepley if (id == PETSCFE_CLASSID) {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);} 5599de99aefSMatthew G. Knepley else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);} 5609de99aefSMatthew G. Knepley else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0); 5619de99aefSMatthew G. Knepley } 5622764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5632764a2aaSMatthew G. Knepley } 5642764a2aaSMatthew G. Knepley 565bc4ae4beSMatthew G. Knepley /*@ 566bc4ae4beSMatthew G. Knepley PetscDSGetTotalDimension - Returns the total size of the approximation space for this system 567bc4ae4beSMatthew G. Knepley 568bc4ae4beSMatthew G. Knepley Not collective 569bc4ae4beSMatthew G. Knepley 570bc4ae4beSMatthew G. Knepley Input Parameter: 571bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 572bc4ae4beSMatthew G. Knepley 573bc4ae4beSMatthew G. Knepley Output Parameter: 574bc4ae4beSMatthew G. Knepley . dim - The total problem dimension 575bc4ae4beSMatthew G. Knepley 576bc4ae4beSMatthew G. Knepley Level: beginner 577bc4ae4beSMatthew G. Knepley 578bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 579bc4ae4beSMatthew G. Knepley @*/ 5802764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim) 5812764a2aaSMatthew G. Knepley { 5822764a2aaSMatthew G. Knepley PetscErrorCode ierr; 5832764a2aaSMatthew G. Knepley 5842764a2aaSMatthew G. Knepley PetscFunctionBegin; 5852764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 5862764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 5872764a2aaSMatthew G. Knepley PetscValidPointer(dim, 2); 5882764a2aaSMatthew G. Knepley *dim = prob->totDim; 5892764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 5902764a2aaSMatthew G. Knepley } 5912764a2aaSMatthew G. Knepley 592bc4ae4beSMatthew G. Knepley /*@ 593bc4ae4beSMatthew G. Knepley PetscDSGetTotalComponents - Returns the total number of components in this system 594bc4ae4beSMatthew G. Knepley 595bc4ae4beSMatthew G. Knepley Not collective 596bc4ae4beSMatthew G. Knepley 597bc4ae4beSMatthew G. Knepley Input Parameter: 598bc4ae4beSMatthew G. Knepley . prob - The PetscDS object 599bc4ae4beSMatthew G. Knepley 600bc4ae4beSMatthew G. Knepley Output Parameter: 601bc4ae4beSMatthew G. Knepley . dim - The total number of components 602bc4ae4beSMatthew G. Knepley 603bc4ae4beSMatthew G. Knepley Level: beginner 604bc4ae4beSMatthew G. Knepley 605bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate() 606bc4ae4beSMatthew G. Knepley @*/ 6072764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc) 6082764a2aaSMatthew G. Knepley { 6092764a2aaSMatthew G. Knepley PetscErrorCode ierr; 6102764a2aaSMatthew G. Knepley 6112764a2aaSMatthew G. Knepley PetscFunctionBegin; 6122764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6132764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 6142764a2aaSMatthew G. Knepley PetscValidPointer(Nc, 2); 6152764a2aaSMatthew G. Knepley *Nc = prob->totComp; 6162764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6172764a2aaSMatthew G. Knepley } 6182764a2aaSMatthew G. Knepley 619bc4ae4beSMatthew G. Knepley /*@ 620bc4ae4beSMatthew G. Knepley PetscDSGetDiscretization - Returns the discretization object for the given field 621bc4ae4beSMatthew G. Knepley 622bc4ae4beSMatthew G. Knepley Not collective 623bc4ae4beSMatthew G. Knepley 624bc4ae4beSMatthew G. Knepley Input Parameters: 625bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 626bc4ae4beSMatthew G. Knepley - f - The field number 627bc4ae4beSMatthew G. Knepley 628bc4ae4beSMatthew G. Knepley Output Parameter: 629bc4ae4beSMatthew G. Knepley . disc - The discretization object 630bc4ae4beSMatthew G. Knepley 631bc4ae4beSMatthew G. Knepley Level: beginner 632bc4ae4beSMatthew G. Knepley 633f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 634bc4ae4beSMatthew G. Knepley @*/ 6352764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc) 6362764a2aaSMatthew G. Knepley { 6372764a2aaSMatthew G. Knepley PetscFunctionBegin; 6382764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6392764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 6402764a2aaSMatthew 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); 6412764a2aaSMatthew G. Knepley *disc = prob->disc[f]; 6422764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6432764a2aaSMatthew G. Knepley } 6442764a2aaSMatthew G. Knepley 645bc4ae4beSMatthew G. Knepley /*@ 646bc4ae4beSMatthew G. Knepley PetscDSSetDiscretization - Sets the discretization object for the given field 647bc4ae4beSMatthew G. Knepley 648bc4ae4beSMatthew G. Knepley Not collective 649bc4ae4beSMatthew G. Knepley 650bc4ae4beSMatthew G. Knepley Input Parameters: 651bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 652bc4ae4beSMatthew G. Knepley . f - The field number 653bc4ae4beSMatthew G. Knepley - disc - The discretization object 654bc4ae4beSMatthew G. Knepley 655bc4ae4beSMatthew G. Knepley Level: beginner 656bc4ae4beSMatthew G. Knepley 657bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 658bc4ae4beSMatthew G. Knepley @*/ 6592764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc) 6602764a2aaSMatthew G. Knepley { 6612764a2aaSMatthew G. Knepley PetscErrorCode ierr; 6622764a2aaSMatthew G. Knepley 6632764a2aaSMatthew G. Knepley PetscFunctionBegin; 6642764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 6652764a2aaSMatthew G. Knepley PetscValidPointer(disc, 3); 6662764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 6672764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 6682764a2aaSMatthew G. Knepley if (prob->disc[f]) {ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);} 6692764a2aaSMatthew G. Knepley prob->disc[f] = disc; 6702764a2aaSMatthew G. Knepley ierr = PetscObjectReference(disc);CHKERRQ(ierr); 671249df284SMatthew G. Knepley { 672249df284SMatthew G. Knepley PetscClassId id; 673249df284SMatthew G. Knepley 674249df284SMatthew G. Knepley ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr); 675a6cbbb48SMatthew G. Knepley if (id == PETSCFV_CLASSID) { 676a6cbbb48SMatthew G. Knepley prob->implicit[f] = PETSC_FALSE; 677a6cbbb48SMatthew G. Knepley prob->adjacency[f*2+0] = PETSC_TRUE; 678a6cbbb48SMatthew G. Knepley prob->adjacency[f*2+1] = PETSC_FALSE; 679a6cbbb48SMatthew G. Knepley } 680249df284SMatthew G. Knepley } 6812764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 6822764a2aaSMatthew G. Knepley } 6832764a2aaSMatthew G. Knepley 684bc4ae4beSMatthew G. Knepley /*@ 685bc4ae4beSMatthew G. Knepley PetscDSAddDiscretization - Adds a discretization object 686bc4ae4beSMatthew G. Knepley 687bc4ae4beSMatthew G. Knepley Not collective 688bc4ae4beSMatthew G. Knepley 689bc4ae4beSMatthew G. Knepley Input Parameters: 690bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 691bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object 692bc4ae4beSMatthew G. Knepley 693bc4ae4beSMatthew G. Knepley Level: beginner 694bc4ae4beSMatthew G. Knepley 695bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 696bc4ae4beSMatthew G. Knepley @*/ 6972764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc) 6982764a2aaSMatthew G. Knepley { 6992764a2aaSMatthew G. Knepley PetscErrorCode ierr; 7002764a2aaSMatthew G. Knepley 7012764a2aaSMatthew G. Knepley PetscFunctionBegin; 7022764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr); 7032764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 7042764a2aaSMatthew G. Knepley } 7052764a2aaSMatthew G. Knepley 706249df284SMatthew G. Knepley /*@ 707249df284SMatthew G. Knepley PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX 708249df284SMatthew G. Knepley 709249df284SMatthew G. Knepley Not collective 710249df284SMatthew G. Knepley 711249df284SMatthew G. Knepley Input Parameters: 712249df284SMatthew G. Knepley + prob - The PetscDS object 713249df284SMatthew G. Knepley - f - The field number 714249df284SMatthew G. Knepley 715249df284SMatthew G. Knepley Output Parameter: 716249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field 717249df284SMatthew G. Knepley 718249df284SMatthew G. Knepley Level: developer 719249df284SMatthew G. Knepley 720f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 721249df284SMatthew G. Knepley @*/ 722249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit) 723249df284SMatthew G. Knepley { 724249df284SMatthew G. Knepley PetscFunctionBegin; 725249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 726249df284SMatthew G. Knepley PetscValidPointer(implicit, 3); 727249df284SMatthew 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); 728249df284SMatthew G. Knepley *implicit = prob->implicit[f]; 729249df284SMatthew G. Knepley PetscFunctionReturn(0); 730249df284SMatthew G. Knepley } 731249df284SMatthew G. Knepley 732249df284SMatthew G. Knepley /*@ 733249df284SMatthew G. Knepley PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX 734249df284SMatthew G. Knepley 735249df284SMatthew G. Knepley Not collective 736249df284SMatthew G. Knepley 737249df284SMatthew G. Knepley Input Parameters: 738249df284SMatthew G. Knepley + prob - The PetscDS object 739249df284SMatthew G. Knepley . f - The field number 740249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field 741249df284SMatthew G. Knepley 742249df284SMatthew G. Knepley Level: developer 743249df284SMatthew G. Knepley 744f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 745249df284SMatthew G. Knepley @*/ 746249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit) 747249df284SMatthew G. Knepley { 748249df284SMatthew G. Knepley PetscFunctionBegin; 749249df284SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 750249df284SMatthew 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); 751249df284SMatthew G. Knepley prob->implicit[f] = implicit; 752249df284SMatthew G. Knepley PetscFunctionReturn(0); 753249df284SMatthew G. Knepley } 754249df284SMatthew G. Knepley 755a6cbbb48SMatthew G. Knepley /*@ 756a6cbbb48SMatthew G. Knepley PetscDSGetAdjacency - Returns the flags for determining variable influence 757a6cbbb48SMatthew G. Knepley 758a6cbbb48SMatthew G. Knepley Not collective 759a6cbbb48SMatthew G. Knepley 760a6cbbb48SMatthew G. Knepley Input Parameters: 761a6cbbb48SMatthew G. Knepley + prob - The PetscDS object 762a6cbbb48SMatthew G. Knepley - f - The field number 763a6cbbb48SMatthew G. Knepley 764a6cbbb48SMatthew G. Knepley Output Parameter: 765a6cbbb48SMatthew G. Knepley + useCone - Flag for variable influence starting with the cone operation 766a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure 767a6cbbb48SMatthew G. Knepley 768a6cbbb48SMatthew G. Knepley Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure() 769a6cbbb48SMatthew G. Knepley 770a6cbbb48SMatthew G. Knepley Level: developer 771a6cbbb48SMatthew G. Knepley 772f744cafaSSander Arens .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 773a6cbbb48SMatthew G. Knepley @*/ 774a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure) 775a6cbbb48SMatthew G. Knepley { 776a6cbbb48SMatthew G. Knepley PetscFunctionBegin; 777a6cbbb48SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 778a6cbbb48SMatthew G. Knepley PetscValidPointer(useCone, 3); 779a6cbbb48SMatthew G. Knepley PetscValidPointer(useClosure, 4); 780a6cbbb48SMatthew 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); 781a6cbbb48SMatthew G. Knepley *useCone = prob->adjacency[f*2+0]; 782a6cbbb48SMatthew G. Knepley *useClosure = prob->adjacency[f*2+1]; 783a6cbbb48SMatthew G. Knepley PetscFunctionReturn(0); 784a6cbbb48SMatthew G. Knepley } 785a6cbbb48SMatthew G. Knepley 786a6cbbb48SMatthew G. Knepley /*@ 787a6cbbb48SMatthew G. Knepley PetscDSSetAdjacency - Set the flags for determining variable influence 788a6cbbb48SMatthew G. Knepley 789a6cbbb48SMatthew G. Knepley Not collective 790a6cbbb48SMatthew G. Knepley 791a6cbbb48SMatthew G. Knepley Input Parameters: 792a6cbbb48SMatthew G. Knepley + prob - The PetscDS object 793a6cbbb48SMatthew G. Knepley . f - The field number 794a6cbbb48SMatthew G. Knepley . useCone - Flag for variable influence starting with the cone operation 795a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure 796a6cbbb48SMatthew G. Knepley 797a6cbbb48SMatthew G. Knepley Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure() 798a6cbbb48SMatthew G. Knepley 799a6cbbb48SMatthew G. Knepley Level: developer 800a6cbbb48SMatthew G. Knepley 801f744cafaSSander Arens .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 802a6cbbb48SMatthew G. Knepley @*/ 803a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure) 804a6cbbb48SMatthew G. Knepley { 805a6cbbb48SMatthew G. Knepley PetscFunctionBegin; 806a6cbbb48SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 807a6cbbb48SMatthew 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); 808a6cbbb48SMatthew G. Knepley prob->adjacency[f*2+0] = useCone; 809a6cbbb48SMatthew G. Knepley prob->adjacency[f*2+1] = useClosure; 810a6cbbb48SMatthew G. Knepley PetscFunctionReturn(0); 811a6cbbb48SMatthew G. Knepley } 812a6cbbb48SMatthew G. Knepley 8132764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f, 81430b9ff8bSMatthew G. Knepley void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 815194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 816194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 81797b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 8182764a2aaSMatthew G. Knepley { 8192764a2aaSMatthew G. Knepley PetscFunctionBegin; 8202764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 8212764a2aaSMatthew G. Knepley PetscValidPointer(obj, 2); 8222764a2aaSMatthew 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); 8232764a2aaSMatthew G. Knepley *obj = prob->obj[f]; 8242764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8252764a2aaSMatthew G. Knepley } 8262764a2aaSMatthew G. Knepley 8272764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f, 82830b9ff8bSMatthew G. Knepley void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 829194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 830194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 83197b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[])) 8322764a2aaSMatthew G. Knepley { 8332764a2aaSMatthew G. Knepley PetscErrorCode ierr; 8342764a2aaSMatthew G. Knepley 8352764a2aaSMatthew G. Knepley PetscFunctionBegin; 8362764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 837de716cbcSToby Isaac if (obj) PetscValidFunction(obj, 2); 8382764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 8392764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 8402764a2aaSMatthew G. Knepley prob->obj[f] = obj; 8412764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 8422764a2aaSMatthew G. Knepley } 8432764a2aaSMatthew G. Knepley 844194d53e6SMatthew G. Knepley /*@C 845194d53e6SMatthew G. Knepley PetscDSGetResidual - Get the pointwise residual function for a given test field 846194d53e6SMatthew G. Knepley 847194d53e6SMatthew G. Knepley Not collective 848194d53e6SMatthew G. Knepley 849194d53e6SMatthew G. Knepley Input Parameters: 850194d53e6SMatthew G. Knepley + prob - The PetscDS 851194d53e6SMatthew G. Knepley - f - The test field number 852194d53e6SMatthew G. Knepley 853194d53e6SMatthew G. Knepley Output Parameters: 854194d53e6SMatthew G. Knepley + f0 - integrand for the test function term 855194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 856194d53e6SMatthew G. Knepley 857194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 858194d53e6SMatthew G. Knepley 859194d53e6SMatthew 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) 860194d53e6SMatthew G. Knepley 861194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 862194d53e6SMatthew G. Knepley 86330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 864194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 865194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 86630b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 867194d53e6SMatthew G. Knepley 868194d53e6SMatthew G. Knepley + dim - the spatial dimension 869194d53e6SMatthew G. Knepley . Nf - the number of fields 870194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 871194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 872194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 873194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 874194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 875194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 876194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 877194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 878194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 879194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 880194d53e6SMatthew G. Knepley . t - current time 881194d53e6SMatthew G. Knepley . x - coordinates of the current point 88297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 88397b6e6e8SMatthew G. Knepley . constants - constant parameters 884194d53e6SMatthew G. Knepley - f0 - output values at the current point 885194d53e6SMatthew G. Knepley 886194d53e6SMatthew G. Knepley Level: intermediate 887194d53e6SMatthew G. Knepley 888194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual() 889194d53e6SMatthew G. Knepley @*/ 8902764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f, 89130b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 892194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 893194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 89497b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 89530b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 896194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 897194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 89897b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 8992764a2aaSMatthew G. Knepley { 9002764a2aaSMatthew G. Knepley PetscFunctionBegin; 9012764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 9022764a2aaSMatthew 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); 9032764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];} 9042764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];} 9052764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9062764a2aaSMatthew G. Knepley } 9072764a2aaSMatthew G. Knepley 908194d53e6SMatthew G. Knepley /*@C 909194d53e6SMatthew G. Knepley PetscDSSetResidual - Set the pointwise residual function for a given test field 910194d53e6SMatthew G. Knepley 911194d53e6SMatthew G. Knepley Not collective 912194d53e6SMatthew G. Knepley 913194d53e6SMatthew G. Knepley Input Parameters: 914194d53e6SMatthew G. Knepley + prob - The PetscDS 915194d53e6SMatthew G. Knepley . f - The test field number 916194d53e6SMatthew G. Knepley . f0 - integrand for the test function term 917194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term 918194d53e6SMatthew G. Knepley 919194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 920194d53e6SMatthew G. Knepley 921194d53e6SMatthew 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) 922194d53e6SMatthew G. Knepley 923194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 924194d53e6SMatthew G. Knepley 92530b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 926194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 927194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 92830b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar f0[]) 929194d53e6SMatthew G. Knepley 930194d53e6SMatthew G. Knepley + dim - the spatial dimension 931194d53e6SMatthew G. Knepley . Nf - the number of fields 932194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 933194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 934194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 935194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 936194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 937194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 938194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 939194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 940194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 941194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 942194d53e6SMatthew G. Knepley . t - current time 943194d53e6SMatthew G. Knepley . x - coordinates of the current point 94497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 94597b6e6e8SMatthew G. Knepley . constants - constant parameters 946194d53e6SMatthew G. Knepley - f0 - output values at the current point 947194d53e6SMatthew G. Knepley 948194d53e6SMatthew G. Knepley Level: intermediate 949194d53e6SMatthew G. Knepley 950194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual() 951194d53e6SMatthew G. Knepley @*/ 9522764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f, 95330b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 954194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 955194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 95697b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 95730b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 958194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 959194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 96097b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 9612764a2aaSMatthew G. Knepley { 9622764a2aaSMatthew G. Knepley PetscErrorCode ierr; 9632764a2aaSMatthew G. Knepley 9642764a2aaSMatthew G. Knepley PetscFunctionBegin; 9652764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 966f866a1d0SMatthew G. Knepley if (f0) PetscValidFunction(f0, 3); 967f866a1d0SMatthew G. Knepley if (f1) PetscValidFunction(f1, 4); 9682764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 9692764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 9702764a2aaSMatthew G. Knepley prob->f[f*2+0] = f0; 9712764a2aaSMatthew G. Knepley prob->f[f*2+1] = f1; 9722764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 9732764a2aaSMatthew G. Knepley } 9742764a2aaSMatthew G. Knepley 9753e75805dSMatthew G. Knepley /*@C 9763e75805dSMatthew G. Knepley PetscDSHasJacobian - Signals that Jacobian functions have been set 9773e75805dSMatthew G. Knepley 9783e75805dSMatthew G. Knepley Not collective 9793e75805dSMatthew G. Knepley 9803e75805dSMatthew G. Knepley Input Parameter: 9813e75805dSMatthew G. Knepley . prob - The PetscDS 9823e75805dSMatthew G. Knepley 9833e75805dSMatthew G. Knepley Output Parameter: 9843e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set 9853e75805dSMatthew G. Knepley 9863e75805dSMatthew G. Knepley Level: intermediate 9873e75805dSMatthew G. Knepley 9883e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 9893e75805dSMatthew G. Knepley @*/ 9903e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac) 9913e75805dSMatthew G. Knepley { 9923e75805dSMatthew G. Knepley PetscInt f, g, h; 9933e75805dSMatthew G. Knepley 9943e75805dSMatthew G. Knepley PetscFunctionBegin; 9953e75805dSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 9963e75805dSMatthew G. Knepley *hasJac = PETSC_FALSE; 9973e75805dSMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 9983e75805dSMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 9993e75805dSMatthew G. Knepley for (h = 0; h < 4; ++h) { 10003e75805dSMatthew G. Knepley if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE; 10013e75805dSMatthew G. Knepley } 10023e75805dSMatthew G. Knepley } 10033e75805dSMatthew G. Knepley } 10043e75805dSMatthew G. Knepley PetscFunctionReturn(0); 10053e75805dSMatthew G. Knepley } 10063e75805dSMatthew G. Knepley 1007194d53e6SMatthew G. Knepley /*@C 1008194d53e6SMatthew G. Knepley PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field 1009194d53e6SMatthew G. Knepley 1010194d53e6SMatthew G. Knepley Not collective 1011194d53e6SMatthew G. Knepley 1012194d53e6SMatthew G. Knepley Input Parameters: 1013194d53e6SMatthew G. Knepley + prob - The PetscDS 1014194d53e6SMatthew G. Knepley . f - The test field number 1015194d53e6SMatthew G. Knepley - g - The field number 1016194d53e6SMatthew G. Knepley 1017194d53e6SMatthew G. Knepley Output Parameters: 1018194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1019194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1020194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1021194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1022194d53e6SMatthew G. Knepley 1023194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1024194d53e6SMatthew G. Knepley 1025194d53e6SMatthew 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 1026194d53e6SMatthew G. Knepley 1027194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1028194d53e6SMatthew G. Knepley 102930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1030194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1031194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 103230b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1033194d53e6SMatthew G. Knepley 1034194d53e6SMatthew G. Knepley + dim - the spatial dimension 1035194d53e6SMatthew G. Knepley . Nf - the number of fields 1036194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1037194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1038194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1039194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1040194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1041194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1042194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1043194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1044194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1045194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1046194d53e6SMatthew G. Knepley . t - current time 10472aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1048194d53e6SMatthew G. Knepley . x - coordinates of the current point 104997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 105097b6e6e8SMatthew G. Knepley . constants - constant parameters 1051194d53e6SMatthew G. Knepley - g0 - output values at the current point 1052194d53e6SMatthew G. Knepley 1053194d53e6SMatthew G. Knepley Level: intermediate 1054194d53e6SMatthew G. Knepley 1055194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1056194d53e6SMatthew G. Knepley @*/ 10572764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g, 105830b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1059194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1060194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 106197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 106230b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1063194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1064194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 106597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 106630b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1067194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1068194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 106997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 107030b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1071194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1072194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 107397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 10742764a2aaSMatthew G. Knepley { 10752764a2aaSMatthew G. Knepley PetscFunctionBegin; 10762764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 10772764a2aaSMatthew 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); 10782764a2aaSMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 10792764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];} 10802764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];} 10812764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];} 10822764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];} 10832764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 10842764a2aaSMatthew G. Knepley } 10852764a2aaSMatthew G. Knepley 1086194d53e6SMatthew G. Knepley /*@C 1087194d53e6SMatthew G. Knepley PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields 1088194d53e6SMatthew G. Knepley 1089194d53e6SMatthew G. Knepley Not collective 1090194d53e6SMatthew G. Knepley 1091194d53e6SMatthew G. Knepley Input Parameters: 1092194d53e6SMatthew G. Knepley + prob - The PetscDS 1093194d53e6SMatthew G. Knepley . f - The test field number 1094194d53e6SMatthew G. Knepley . g - The field number 1095194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1096194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1097194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1098194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1099194d53e6SMatthew G. Knepley 1100194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1101194d53e6SMatthew G. Knepley 1102194d53e6SMatthew 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 1103194d53e6SMatthew G. Knepley 1104194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1105194d53e6SMatthew G. Knepley 110630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1107194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1108194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 110930b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1110194d53e6SMatthew G. Knepley 1111194d53e6SMatthew G. Knepley + dim - the spatial dimension 1112194d53e6SMatthew G. Knepley . Nf - the number of fields 1113194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1114194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1115194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1116194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1117194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1118194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1119194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1120194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1121194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1122194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1123194d53e6SMatthew G. Knepley . t - current time 11242aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1125194d53e6SMatthew G. Knepley . x - coordinates of the current point 112697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 112797b6e6e8SMatthew G. Knepley . constants - constant parameters 1128194d53e6SMatthew G. Knepley - g0 - output values at the current point 1129194d53e6SMatthew G. Knepley 1130194d53e6SMatthew G. Knepley Level: intermediate 1131194d53e6SMatthew G. Knepley 1132194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1133194d53e6SMatthew G. Knepley @*/ 11342764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g, 113530b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1136194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1137194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 113897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 113930b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1140194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1141194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 114297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 114330b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1144194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1145194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 114697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 114730b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1148194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1149194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 115097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 11512764a2aaSMatthew G. Knepley { 11522764a2aaSMatthew G. Knepley PetscErrorCode ierr; 11532764a2aaSMatthew G. Knepley 11542764a2aaSMatthew G. Knepley PetscFunctionBegin; 11552764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 11562764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 11572764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 11582764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 11592764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 11602764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 11612764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 11622764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 11632764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+0] = g0; 11642764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+1] = g1; 11652764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+2] = g2; 11662764a2aaSMatthew G. Knepley prob->g[(f*prob->Nf + g)*4+3] = g3; 11672764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 11682764a2aaSMatthew G. Knepley } 11692764a2aaSMatthew G. Knepley 1170475e0ac9SMatthew G. Knepley /*@C 1171475e0ac9SMatthew G. Knepley PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set 1172475e0ac9SMatthew G. Knepley 1173475e0ac9SMatthew G. Knepley Not collective 1174475e0ac9SMatthew G. Knepley 1175475e0ac9SMatthew G. Knepley Input Parameter: 1176475e0ac9SMatthew G. Knepley . prob - The PetscDS 1177475e0ac9SMatthew G. Knepley 1178475e0ac9SMatthew G. Knepley Output Parameter: 1179475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set 1180475e0ac9SMatthew G. Knepley 1181475e0ac9SMatthew G. Knepley Level: intermediate 1182475e0ac9SMatthew G. Knepley 1183475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1184475e0ac9SMatthew G. Knepley @*/ 1185475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre) 1186475e0ac9SMatthew G. Knepley { 1187475e0ac9SMatthew G. Knepley PetscInt f, g, h; 1188475e0ac9SMatthew G. Knepley 1189475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1190475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1191475e0ac9SMatthew G. Knepley *hasJacPre = PETSC_FALSE; 1192475e0ac9SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1193475e0ac9SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1194475e0ac9SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1195475e0ac9SMatthew G. Knepley if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE; 1196475e0ac9SMatthew G. Knepley } 1197475e0ac9SMatthew G. Knepley } 1198475e0ac9SMatthew G. Knepley } 1199475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1200475e0ac9SMatthew G. Knepley } 1201475e0ac9SMatthew G. Knepley 1202475e0ac9SMatthew G. Knepley /*@C 1203475e0ac9SMatthew 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. 1204475e0ac9SMatthew G. Knepley 1205475e0ac9SMatthew G. Knepley Not collective 1206475e0ac9SMatthew G. Knepley 1207475e0ac9SMatthew G. Knepley Input Parameters: 1208475e0ac9SMatthew G. Knepley + prob - The PetscDS 1209475e0ac9SMatthew G. Knepley . f - The test field number 1210475e0ac9SMatthew G. Knepley - g - The field number 1211475e0ac9SMatthew G. Knepley 1212475e0ac9SMatthew G. Knepley Output Parameters: 1213475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term 1214475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1215475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1216475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1217475e0ac9SMatthew G. Knepley 1218475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1219475e0ac9SMatthew G. Knepley 1220475e0ac9SMatthew 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 1221475e0ac9SMatthew G. Knepley 1222475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1223475e0ac9SMatthew G. Knepley 1224475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1225475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1226475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1227475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1228475e0ac9SMatthew G. Knepley 1229475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1230475e0ac9SMatthew G. Knepley . Nf - the number of fields 1231475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1232475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1233475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1234475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1235475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1236475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1237475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1238475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1239475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1240475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1241475e0ac9SMatthew G. Knepley . t - current time 1242475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1243475e0ac9SMatthew G. Knepley . x - coordinates of the current point 124497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 124597b6e6e8SMatthew G. Knepley . constants - constant parameters 1246475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1247475e0ac9SMatthew G. Knepley 1248475e0ac9SMatthew G. Knepley Level: intermediate 1249475e0ac9SMatthew G. Knepley 1250475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian() 1251475e0ac9SMatthew G. Knepley @*/ 1252475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1253475e0ac9SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1254475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1255475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 125697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1257475e0ac9SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1258475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1259475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 126097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1261475e0ac9SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1262475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1263475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 126497b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1265475e0ac9SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1266475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1267475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 126897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1269475e0ac9SMatthew G. Knepley { 1270475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1271475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1272475e0ac9SMatthew 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); 1273475e0ac9SMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 1274475e0ac9SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];} 1275475e0ac9SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];} 1276475e0ac9SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];} 1277475e0ac9SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];} 1278475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1279475e0ac9SMatthew G. Knepley } 1280475e0ac9SMatthew G. Knepley 1281475e0ac9SMatthew G. Knepley /*@C 1282475e0ac9SMatthew 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. 1283475e0ac9SMatthew G. Knepley 1284475e0ac9SMatthew G. Knepley Not collective 1285475e0ac9SMatthew G. Knepley 1286475e0ac9SMatthew G. Knepley Input Parameters: 1287475e0ac9SMatthew G. Knepley + prob - The PetscDS 1288475e0ac9SMatthew G. Knepley . f - The test field number 1289475e0ac9SMatthew G. Knepley . g - The field number 1290475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term 1291475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1292475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1293475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1294475e0ac9SMatthew G. Knepley 1295475e0ac9SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1296475e0ac9SMatthew G. Knepley 1297475e0ac9SMatthew 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 1298475e0ac9SMatthew G. Knepley 1299475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1300475e0ac9SMatthew G. Knepley 1301475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1302475e0ac9SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1303475e0ac9SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1304475e0ac9SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1305475e0ac9SMatthew G. Knepley 1306475e0ac9SMatthew G. Knepley + dim - the spatial dimension 1307475e0ac9SMatthew G. Knepley . Nf - the number of fields 1308475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1309475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1310475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point 1311475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1312475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1313475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1314475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1315475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1316475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1317475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1318475e0ac9SMatthew G. Knepley . t - current time 1319475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1320475e0ac9SMatthew G. Knepley . x - coordinates of the current point 132197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 132297b6e6e8SMatthew G. Knepley . constants - constant parameters 1323475e0ac9SMatthew G. Knepley - g0 - output values at the current point 1324475e0ac9SMatthew G. Knepley 1325475e0ac9SMatthew G. Knepley Level: intermediate 1326475e0ac9SMatthew G. Knepley 1327475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian() 1328475e0ac9SMatthew G. Knepley @*/ 1329475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g, 1330475e0ac9SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1331475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1332475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 133397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1334475e0ac9SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1335475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1336475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 133797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1338475e0ac9SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1339475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1340475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 134197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1342475e0ac9SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1343475e0ac9SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1344475e0ac9SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 134597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1346475e0ac9SMatthew G. Knepley { 1347475e0ac9SMatthew G. Knepley PetscErrorCode ierr; 1348475e0ac9SMatthew G. Knepley 1349475e0ac9SMatthew G. Knepley PetscFunctionBegin; 1350475e0ac9SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1351475e0ac9SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1352475e0ac9SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1353475e0ac9SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1354475e0ac9SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1355475e0ac9SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1356475e0ac9SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1357475e0ac9SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1358475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+0] = g0; 1359475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+1] = g1; 1360475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+2] = g2; 1361475e0ac9SMatthew G. Knepley prob->gp[(f*prob->Nf + g)*4+3] = g3; 1362475e0ac9SMatthew G. Knepley PetscFunctionReturn(0); 1363475e0ac9SMatthew G. Knepley } 1364475e0ac9SMatthew G. Knepley 1365b7e05686SMatthew G. Knepley /*@C 1366b7e05686SMatthew G. Knepley PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set 1367b7e05686SMatthew G. Knepley 1368b7e05686SMatthew G. Knepley Not collective 1369b7e05686SMatthew G. Knepley 1370b7e05686SMatthew G. Knepley Input Parameter: 1371b7e05686SMatthew G. Knepley . prob - The PetscDS 1372b7e05686SMatthew G. Knepley 1373b7e05686SMatthew G. Knepley Output Parameter: 1374b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set 1375b7e05686SMatthew G. Knepley 1376b7e05686SMatthew G. Knepley Level: intermediate 1377b7e05686SMatthew G. Knepley 1378b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian() 1379b7e05686SMatthew G. Knepley @*/ 1380b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac) 1381b7e05686SMatthew G. Knepley { 1382b7e05686SMatthew G. Knepley PetscInt f, g, h; 1383b7e05686SMatthew G. Knepley 1384b7e05686SMatthew G. Knepley PetscFunctionBegin; 1385b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1386b7e05686SMatthew G. Knepley *hasDynJac = PETSC_FALSE; 1387b7e05686SMatthew G. Knepley for (f = 0; f < prob->Nf; ++f) { 1388b7e05686SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) { 1389b7e05686SMatthew G. Knepley for (h = 0; h < 4; ++h) { 1390b7e05686SMatthew G. Knepley if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE; 1391b7e05686SMatthew G. Knepley } 1392b7e05686SMatthew G. Knepley } 1393b7e05686SMatthew G. Knepley } 1394b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1395b7e05686SMatthew G. Knepley } 1396b7e05686SMatthew G. Knepley 1397b7e05686SMatthew G. Knepley /*@C 1398b7e05686SMatthew G. Knepley PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field 1399b7e05686SMatthew G. Knepley 1400b7e05686SMatthew G. Knepley Not collective 1401b7e05686SMatthew G. Knepley 1402b7e05686SMatthew G. Knepley Input Parameters: 1403b7e05686SMatthew G. Knepley + prob - The PetscDS 1404b7e05686SMatthew G. Knepley . f - The test field number 1405b7e05686SMatthew G. Knepley - g - The field number 1406b7e05686SMatthew G. Knepley 1407b7e05686SMatthew G. Knepley Output Parameters: 1408b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term 1409b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1410b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1411b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1412b7e05686SMatthew G. Knepley 1413b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1414b7e05686SMatthew G. Knepley 1415b7e05686SMatthew 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 1416b7e05686SMatthew G. Knepley 1417b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1418b7e05686SMatthew G. Knepley 1419b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1420b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1421b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1422b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]) 1423b7e05686SMatthew G. Knepley 1424b7e05686SMatthew G. Knepley + dim - the spatial dimension 1425b7e05686SMatthew G. Knepley . Nf - the number of fields 1426b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1427b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1428b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1429b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1430b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1431b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1432b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1433b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1434b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1435b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1436b7e05686SMatthew G. Knepley . t - current time 1437b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1438b7e05686SMatthew G. Knepley . x - coordinates of the current point 143997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 144097b6e6e8SMatthew G. Knepley . constants - constant parameters 1441b7e05686SMatthew G. Knepley - g0 - output values at the current point 1442b7e05686SMatthew G. Knepley 1443b7e05686SMatthew G. Knepley Level: intermediate 1444b7e05686SMatthew G. Knepley 1445b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian() 1446b7e05686SMatthew G. Knepley @*/ 1447b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1448b7e05686SMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1449b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1450b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 145197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1452b7e05686SMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1453b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1454b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 145597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1456b7e05686SMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1457b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1458b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 145997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1460b7e05686SMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1461b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1462b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 146397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1464b7e05686SMatthew G. Knepley { 1465b7e05686SMatthew G. Knepley PetscFunctionBegin; 1466b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1467b7e05686SMatthew 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); 1468b7e05686SMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 1469b7e05686SMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];} 1470b7e05686SMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];} 1471b7e05686SMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];} 1472b7e05686SMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];} 1473b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1474b7e05686SMatthew G. Knepley } 1475b7e05686SMatthew G. Knepley 1476b7e05686SMatthew G. Knepley /*@C 1477b7e05686SMatthew G. Knepley PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields 1478b7e05686SMatthew G. Knepley 1479b7e05686SMatthew G. Knepley Not collective 1480b7e05686SMatthew G. Knepley 1481b7e05686SMatthew G. Knepley Input Parameters: 1482b7e05686SMatthew G. Knepley + prob - The PetscDS 1483b7e05686SMatthew G. Knepley . f - The test field number 1484b7e05686SMatthew G. Knepley . g - The field number 1485b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term 1486b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1487b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1488b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1489b7e05686SMatthew G. Knepley 1490b7e05686SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1491b7e05686SMatthew G. Knepley 1492b7e05686SMatthew 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 1493b7e05686SMatthew G. Knepley 1494b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1495b7e05686SMatthew G. Knepley 1496b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1497b7e05686SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1498b7e05686SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 1499b7e05686SMatthew G. Knepley $ PetscReal t, const PetscReal x[], PetscScalar g0[]) 1500b7e05686SMatthew G. Knepley 1501b7e05686SMatthew G. Knepley + dim - the spatial dimension 1502b7e05686SMatthew G. Knepley . Nf - the number of fields 1503b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1504b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1505b7e05686SMatthew G. Knepley . u - each field evaluated at the current point 1506b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1507b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1508b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1509b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1510b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1511b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1512b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1513b7e05686SMatthew G. Knepley . t - current time 1514b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1515b7e05686SMatthew G. Knepley . x - coordinates of the current point 151697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 151797b6e6e8SMatthew G. Knepley . constants - constant parameters 1518b7e05686SMatthew G. Knepley - g0 - output values at the current point 1519b7e05686SMatthew G. Knepley 1520b7e05686SMatthew G. Knepley Level: intermediate 1521b7e05686SMatthew G. Knepley 1522b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian() 1523b7e05686SMatthew G. Knepley @*/ 1524b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g, 1525b7e05686SMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1526b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1527b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 152897b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 1529b7e05686SMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1530b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1531b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 153297b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 1533b7e05686SMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1534b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1535b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 153697b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 1537b7e05686SMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1538b7e05686SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1539b7e05686SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 154097b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 1541b7e05686SMatthew G. Knepley { 1542b7e05686SMatthew G. Knepley PetscErrorCode ierr; 1543b7e05686SMatthew G. Knepley 1544b7e05686SMatthew G. Knepley PetscFunctionBegin; 1545b7e05686SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1546b7e05686SMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 1547b7e05686SMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 1548b7e05686SMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 1549b7e05686SMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 1550b7e05686SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 1551b7e05686SMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 1552b7e05686SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 1553b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+0] = g0; 1554b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+1] = g1; 1555b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+2] = g2; 1556b7e05686SMatthew G. Knepley prob->gt[(f*prob->Nf + g)*4+3] = g3; 1557b7e05686SMatthew G. Knepley PetscFunctionReturn(0); 1558b7e05686SMatthew G. Knepley } 1559b7e05686SMatthew G. Knepley 15600c2f2876SMatthew G. Knepley /*@C 15610c2f2876SMatthew G. Knepley PetscDSGetRiemannSolver - Returns the Riemann solver for the given field 15620c2f2876SMatthew G. Knepley 15630c2f2876SMatthew G. Knepley Not collective 15640c2f2876SMatthew G. Knepley 15650c2f2876SMatthew G. Knepley Input Arguments: 15660c2f2876SMatthew G. Knepley + prob - The PetscDS object 15670c2f2876SMatthew G. Knepley - f - The field number 15680c2f2876SMatthew G. Knepley 15690c2f2876SMatthew G. Knepley Output Argument: 15700c2f2876SMatthew G. Knepley . r - Riemann solver 15710c2f2876SMatthew G. Knepley 15720c2f2876SMatthew G. Knepley Calling sequence for r: 15730c2f2876SMatthew G. Knepley 15745db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 15750c2f2876SMatthew G. Knepley 15765db36cf9SMatthew G. Knepley + dim - The spatial dimension 15775db36cf9SMatthew G. Knepley . Nf - The number of fields 15785db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 15790c2f2876SMatthew G. Knepley . n - The normal vector to the interface 15800c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 15810c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 15820c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 158397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 158497b6e6e8SMatthew G. Knepley . constants - constant parameters 15850c2f2876SMatthew G. Knepley - ctx - optional user context 15860c2f2876SMatthew G. Knepley 15870c2f2876SMatthew G. Knepley Level: intermediate 15880c2f2876SMatthew G. Knepley 15890c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver() 15900c2f2876SMatthew G. Knepley @*/ 15910c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f, 159297b6e6e8SMatthew 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)) 15930c2f2876SMatthew G. Knepley { 15940c2f2876SMatthew G. Knepley PetscFunctionBegin; 15950c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 15960c2f2876SMatthew 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); 15970c2f2876SMatthew G. Knepley PetscValidPointer(r, 3); 15980c2f2876SMatthew G. Knepley *r = prob->r[f]; 15990c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 16000c2f2876SMatthew G. Knepley } 16010c2f2876SMatthew G. Knepley 16020c2f2876SMatthew G. Knepley /*@C 16030c2f2876SMatthew G. Knepley PetscDSSetRiemannSolver - Sets the Riemann solver for the given field 16040c2f2876SMatthew G. Knepley 16050c2f2876SMatthew G. Knepley Not collective 16060c2f2876SMatthew G. Knepley 16070c2f2876SMatthew G. Knepley Input Arguments: 16080c2f2876SMatthew G. Knepley + prob - The PetscDS object 16090c2f2876SMatthew G. Knepley . f - The field number 16100c2f2876SMatthew G. Knepley - r - Riemann solver 16110c2f2876SMatthew G. Knepley 16120c2f2876SMatthew G. Knepley Calling sequence for r: 16130c2f2876SMatthew G. Knepley 16145db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx) 16150c2f2876SMatthew G. Knepley 16165db36cf9SMatthew G. Knepley + dim - The spatial dimension 16175db36cf9SMatthew G. Knepley . Nf - The number of fields 16185db36cf9SMatthew G. Knepley . x - The coordinates at a point on the interface 16190c2f2876SMatthew G. Knepley . n - The normal vector to the interface 16200c2f2876SMatthew G. Knepley . uL - The state vector to the left of the interface 16210c2f2876SMatthew G. Knepley . uR - The state vector to the right of the interface 16220c2f2876SMatthew G. Knepley . flux - output array of flux through the interface 162397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 162497b6e6e8SMatthew G. Knepley . constants - constant parameters 16250c2f2876SMatthew G. Knepley - ctx - optional user context 16260c2f2876SMatthew G. Knepley 16270c2f2876SMatthew G. Knepley Level: intermediate 16280c2f2876SMatthew G. Knepley 16290c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver() 16300c2f2876SMatthew G. Knepley @*/ 16310c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f, 163297b6e6e8SMatthew 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)) 16330c2f2876SMatthew G. Knepley { 16340c2f2876SMatthew G. Knepley PetscErrorCode ierr; 16350c2f2876SMatthew G. Knepley 16360c2f2876SMatthew G. Knepley PetscFunctionBegin; 16370c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1638de716cbcSToby Isaac if (r) PetscValidFunction(r, 3); 16390c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 16400c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 16410c2f2876SMatthew G. Knepley prob->r[f] = r; 16420c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 16430c2f2876SMatthew G. Knepley } 16440c2f2876SMatthew G. Knepley 16450c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx) 16460c2f2876SMatthew G. Knepley { 16470c2f2876SMatthew G. Knepley PetscFunctionBegin; 16480c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 16490c2f2876SMatthew 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); 16500c2f2876SMatthew G. Knepley PetscValidPointer(ctx, 3); 16510c2f2876SMatthew G. Knepley *ctx = prob->ctx[f]; 16520c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 16530c2f2876SMatthew G. Knepley } 16540c2f2876SMatthew G. Knepley 16550c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx) 16560c2f2876SMatthew G. Knepley { 16570c2f2876SMatthew G. Knepley PetscErrorCode ierr; 16580c2f2876SMatthew G. Knepley 16590c2f2876SMatthew G. Knepley PetscFunctionBegin; 16600c2f2876SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 16610c2f2876SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 16620c2f2876SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 16630c2f2876SMatthew G. Knepley prob->ctx[f] = ctx; 16640c2f2876SMatthew G. Knepley PetscFunctionReturn(0); 16650c2f2876SMatthew G. Knepley } 16660c2f2876SMatthew G. Knepley 1667194d53e6SMatthew G. Knepley /*@C 1668194d53e6SMatthew G. Knepley PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field 1669194d53e6SMatthew G. Knepley 1670194d53e6SMatthew G. Knepley Not collective 1671194d53e6SMatthew G. Knepley 1672194d53e6SMatthew G. Knepley Input Parameters: 1673194d53e6SMatthew G. Knepley + prob - The PetscDS 1674194d53e6SMatthew G. Knepley - f - The test field number 1675194d53e6SMatthew G. Knepley 1676194d53e6SMatthew G. Knepley Output Parameters: 1677194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term 1678194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 1679194d53e6SMatthew G. Knepley 1680194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1681194d53e6SMatthew G. Knepley 1682194d53e6SMatthew 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 1683194d53e6SMatthew G. Knepley 1684194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1685194d53e6SMatthew G. Knepley 168630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1687194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1688194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 168930b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 1690194d53e6SMatthew G. Knepley 1691194d53e6SMatthew G. Knepley + dim - the spatial dimension 1692194d53e6SMatthew G. Knepley . Nf - the number of fields 1693194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1694194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1695194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1696194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1697194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1698194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1699194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1700194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1701194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1702194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1703194d53e6SMatthew G. Knepley . t - current time 1704194d53e6SMatthew G. Knepley . x - coordinates of the current point 1705194d53e6SMatthew G. Knepley . n - unit normal at the current point 170697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 170797b6e6e8SMatthew G. Knepley . constants - constant parameters 1708194d53e6SMatthew G. Knepley - f0 - output values at the current point 1709194d53e6SMatthew G. Knepley 1710194d53e6SMatthew G. Knepley Level: intermediate 1711194d53e6SMatthew G. Knepley 1712194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual() 1713194d53e6SMatthew G. Knepley @*/ 17142764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f, 171530b9ff8bSMatthew G. Knepley void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1716194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1717194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 171897b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 171930b9ff8bSMatthew G. Knepley void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1720194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1721194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 172297b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 17232764a2aaSMatthew G. Knepley { 17242764a2aaSMatthew G. Knepley PetscFunctionBegin; 17252764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 17262764a2aaSMatthew 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); 17272764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];} 17282764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];} 17292764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 17302764a2aaSMatthew G. Knepley } 17312764a2aaSMatthew G. Knepley 1732194d53e6SMatthew G. Knepley /*@C 1733194d53e6SMatthew G. Knepley PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field 1734194d53e6SMatthew G. Knepley 1735194d53e6SMatthew G. Knepley Not collective 1736194d53e6SMatthew G. Knepley 1737194d53e6SMatthew G. Knepley Input Parameters: 1738194d53e6SMatthew G. Knepley + prob - The PetscDS 1739194d53e6SMatthew G. Knepley . f - The test field number 1740194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term 1741194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term 1742194d53e6SMatthew G. Knepley 1743194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1744194d53e6SMatthew G. Knepley 1745194d53e6SMatthew 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 1746194d53e6SMatthew G. Knepley 1747194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by: 1748194d53e6SMatthew G. Knepley 174930b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1750194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1751194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 175230b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]) 1753194d53e6SMatthew G. Knepley 1754194d53e6SMatthew G. Knepley + dim - the spatial dimension 1755194d53e6SMatthew G. Knepley . Nf - the number of fields 1756194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1757194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1758194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1759194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1760194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1761194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1762194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1763194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1764194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1765194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1766194d53e6SMatthew G. Knepley . t - current time 1767194d53e6SMatthew G. Knepley . x - coordinates of the current point 1768194d53e6SMatthew G. Knepley . n - unit normal at the current point 176997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 177097b6e6e8SMatthew G. Knepley . constants - constant parameters 1771194d53e6SMatthew G. Knepley - f0 - output values at the current point 1772194d53e6SMatthew G. Knepley 1773194d53e6SMatthew G. Knepley Level: intermediate 1774194d53e6SMatthew G. Knepley 1775194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual() 1776194d53e6SMatthew G. Knepley @*/ 17772764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f, 177830b9ff8bSMatthew G. Knepley void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1779194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1780194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 178197b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]), 178230b9ff8bSMatthew G. Knepley void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1783194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1784194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 178597b6e6e8SMatthew G. Knepley PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])) 17862764a2aaSMatthew G. Knepley { 17872764a2aaSMatthew G. Knepley PetscErrorCode ierr; 17882764a2aaSMatthew G. Knepley 17892764a2aaSMatthew G. Knepley PetscFunctionBegin; 17902764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 17912764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 17922764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 17932764a2aaSMatthew G. Knepley if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;} 17942764a2aaSMatthew G. Knepley if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;} 17952764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 17962764a2aaSMatthew G. Knepley } 17972764a2aaSMatthew G. Knepley 1798194d53e6SMatthew G. Knepley /*@C 1799194d53e6SMatthew G. Knepley PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field 1800194d53e6SMatthew G. Knepley 1801194d53e6SMatthew G. Knepley Not collective 1802194d53e6SMatthew G. Knepley 1803194d53e6SMatthew G. Knepley Input Parameters: 1804194d53e6SMatthew G. Knepley + prob - The PetscDS 1805194d53e6SMatthew G. Knepley . f - The test field number 1806194d53e6SMatthew G. Knepley - g - The field number 1807194d53e6SMatthew G. Knepley 1808194d53e6SMatthew G. Knepley Output Parameters: 1809194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term 1810194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1811194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1812194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1813194d53e6SMatthew G. Knepley 1814194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1815194d53e6SMatthew G. Knepley 1816194d53e6SMatthew 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 1817194d53e6SMatthew G. Knepley 1818194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1819194d53e6SMatthew G. Knepley 182030b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1821194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1822194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 182330b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 1824194d53e6SMatthew G. Knepley 1825194d53e6SMatthew G. Knepley + dim - the spatial dimension 1826194d53e6SMatthew G. Knepley . Nf - the number of fields 1827194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1828194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1829194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1830194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1831194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1832194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1833194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1834194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1835194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1836194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1837194d53e6SMatthew G. Knepley . t - current time 18382aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1839194d53e6SMatthew G. Knepley . x - coordinates of the current point 1840194d53e6SMatthew G. Knepley . n - normal at the current point 184197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 184297b6e6e8SMatthew G. Knepley . constants - constant parameters 1843194d53e6SMatthew G. Knepley - g0 - output values at the current point 1844194d53e6SMatthew G. Knepley 1845194d53e6SMatthew G. Knepley Level: intermediate 1846194d53e6SMatthew G. Knepley 1847194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian() 1848194d53e6SMatthew G. Knepley @*/ 18492764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 185030b9ff8bSMatthew G. Knepley void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1851194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1852194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 185397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 185430b9ff8bSMatthew G. Knepley void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1855194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1856194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 185797b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 185830b9ff8bSMatthew G. Knepley void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1859194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1860194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 186197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 186230b9ff8bSMatthew G. Knepley void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1863194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1864194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 186597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 18662764a2aaSMatthew G. Knepley { 18672764a2aaSMatthew G. Knepley PetscFunctionBegin; 18682764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 18692764a2aaSMatthew 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); 18702764a2aaSMatthew G. Knepley if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf); 18712764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];} 18722764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];} 18732764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];} 18742764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];} 18752764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 18762764a2aaSMatthew G. Knepley } 18772764a2aaSMatthew G. Knepley 1878194d53e6SMatthew G. Knepley /*@C 1879194d53e6SMatthew G. Knepley PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field 1880194d53e6SMatthew G. Knepley 1881194d53e6SMatthew G. Knepley Not collective 1882194d53e6SMatthew G. Knepley 1883194d53e6SMatthew G. Knepley Input Parameters: 1884194d53e6SMatthew G. Knepley + prob - The PetscDS 1885194d53e6SMatthew G. Knepley . f - The test field number 1886194d53e6SMatthew G. Knepley . g - The field number 1887194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term 1888194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term 1889194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term 1890194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term 1891194d53e6SMatthew G. Knepley 1892194d53e6SMatthew G. Knepley Note: We are using a first order FEM model for the weak form: 1893194d53e6SMatthew G. Knepley 1894194d53e6SMatthew 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 1895194d53e6SMatthew G. Knepley 1896194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by: 1897194d53e6SMatthew G. Knepley 189830b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1899194d53e6SMatthew G. Knepley $ const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1900194d53e6SMatthew G. Knepley $ const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 190130b9ff8bSMatthew G. Knepley $ PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[]) 1902194d53e6SMatthew G. Knepley 1903194d53e6SMatthew G. Knepley + dim - the spatial dimension 1904194d53e6SMatthew G. Knepley . Nf - the number of fields 1905194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field 1906194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field 1907194d53e6SMatthew G. Knepley . u - each field evaluated at the current point 1908194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point 1909194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point 1910194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field 1911194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field 1912194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point 1913194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point 1914194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point 1915194d53e6SMatthew G. Knepley . t - current time 19162aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t 1917194d53e6SMatthew G. Knepley . x - coordinates of the current point 1918194d53e6SMatthew G. Knepley . n - normal at the current point 191997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters 192097b6e6e8SMatthew G. Knepley . constants - constant parameters 1921194d53e6SMatthew G. Knepley - g0 - output values at the current point 1922194d53e6SMatthew G. Knepley 1923194d53e6SMatthew G. Knepley Level: intermediate 1924194d53e6SMatthew G. Knepley 1925194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian() 1926194d53e6SMatthew G. Knepley @*/ 19272764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g, 192830b9ff8bSMatthew G. Knepley void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1929194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1930194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 193197b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]), 193230b9ff8bSMatthew G. Knepley void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1933194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1934194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 193597b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]), 193630b9ff8bSMatthew G. Knepley void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1937194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1938194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 193997b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]), 194030b9ff8bSMatthew G. Knepley void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux, 1941194d53e6SMatthew G. Knepley const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 1942194d53e6SMatthew G. Knepley const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 194397b6e6e8SMatthew G. Knepley PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])) 19442764a2aaSMatthew G. Knepley { 19452764a2aaSMatthew G. Knepley PetscErrorCode ierr; 19462764a2aaSMatthew G. Knepley 19472764a2aaSMatthew G. Knepley PetscFunctionBegin; 19482764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 19492764a2aaSMatthew G. Knepley if (g0) PetscValidFunction(g0, 4); 19502764a2aaSMatthew G. Knepley if (g1) PetscValidFunction(g1, 5); 19512764a2aaSMatthew G. Knepley if (g2) PetscValidFunction(g2, 6); 19522764a2aaSMatthew G. Knepley if (g3) PetscValidFunction(g3, 7); 19532764a2aaSMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 19542764a2aaSMatthew G. Knepley if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g); 19552764a2aaSMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr); 19562764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+0] = g0; 19572764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+1] = g1; 19582764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+2] = g2; 19592764a2aaSMatthew G. Knepley prob->gBd[(f*prob->Nf + g)*4+3] = g3; 19602764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 19612764a2aaSMatthew G. Knepley } 19622764a2aaSMatthew G. Knepley 1963c371a6d1SMatthew G. Knepley /*@C 1964c371a6d1SMatthew G. Knepley PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field 1965c371a6d1SMatthew G. Knepley 1966c371a6d1SMatthew G. Knepley Not collective 1967c371a6d1SMatthew G. Knepley 1968c371a6d1SMatthew G. Knepley Input Parameters: 1969c371a6d1SMatthew G. Knepley + prob - The PetscDS 1970c371a6d1SMatthew G. Knepley - f - The test field number 1971c371a6d1SMatthew G. Knepley 1972c371a6d1SMatthew G. Knepley Output Parameter: 1973c371a6d1SMatthew G. Knepley . exactSol - exact solution for the test field 1974c371a6d1SMatthew G. Knepley 1975c371a6d1SMatthew G. Knepley Note: The calling sequence for the solution functions is given by: 1976c371a6d1SMatthew G. Knepley 1977c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 1978c371a6d1SMatthew G. Knepley 1979c371a6d1SMatthew G. Knepley + dim - the spatial dimension 1980c371a6d1SMatthew G. Knepley . t - current time 1981c371a6d1SMatthew G. Knepley . x - coordinates of the current point 1982c371a6d1SMatthew G. Knepley . Nc - the number of field components 1983c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 1984c371a6d1SMatthew G. Knepley - ctx - a user context 1985c371a6d1SMatthew G. Knepley 1986c371a6d1SMatthew G. Knepley Level: intermediate 1987c371a6d1SMatthew G. Knepley 1988c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution() 1989c371a6d1SMatthew G. Knepley @*/ 1990c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)) 1991c371a6d1SMatthew G. Knepley { 1992c371a6d1SMatthew G. Knepley PetscFunctionBegin; 1993c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 1994c371a6d1SMatthew 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); 1995c371a6d1SMatthew G. Knepley if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];} 1996c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 1997c371a6d1SMatthew G. Knepley } 1998c371a6d1SMatthew G. Knepley 1999c371a6d1SMatthew G. Knepley /*@C 2000c371a6d1SMatthew G. Knepley PetscDSSetExactSolution - Get the pointwise exact solution function for a given test field 2001c371a6d1SMatthew G. Knepley 2002c371a6d1SMatthew G. Knepley Not collective 2003c371a6d1SMatthew G. Knepley 2004c371a6d1SMatthew G. Knepley Input Parameters: 2005c371a6d1SMatthew G. Knepley + prob - The PetscDS 2006c371a6d1SMatthew G. Knepley . f - The test field number 2007c371a6d1SMatthew G. Knepley - sol - solution function for the test fields 2008c371a6d1SMatthew G. Knepley 2009c371a6d1SMatthew G. Knepley Note: The calling sequence for solution functions is given by: 2010c371a6d1SMatthew G. Knepley 2011c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) 2012c371a6d1SMatthew G. Knepley 2013c371a6d1SMatthew G. Knepley + dim - the spatial dimension 2014c371a6d1SMatthew G. Knepley . t - current time 2015c371a6d1SMatthew G. Knepley . x - coordinates of the current point 2016c371a6d1SMatthew G. Knepley . Nc - the number of field components 2017c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point 2018c371a6d1SMatthew G. Knepley - ctx - a user context 2019c371a6d1SMatthew G. Knepley 2020c371a6d1SMatthew G. Knepley Level: intermediate 2021c371a6d1SMatthew G. Knepley 2022c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution() 2023c371a6d1SMatthew G. Knepley @*/ 2024c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)) 2025c371a6d1SMatthew G. Knepley { 2026c371a6d1SMatthew G. Knepley PetscErrorCode ierr; 2027c371a6d1SMatthew G. Knepley 2028c371a6d1SMatthew G. Knepley PetscFunctionBegin; 2029c371a6d1SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2030c371a6d1SMatthew G. Knepley if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f); 2031c371a6d1SMatthew G. Knepley ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr); 2032c371a6d1SMatthew G. Knepley if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;} 2033c371a6d1SMatthew G. Knepley PetscFunctionReturn(0); 2034c371a6d1SMatthew G. Knepley } 2035c371a6d1SMatthew G. Knepley 2036*5638fd0eSMatthew G. Knepley /*@C 203797b6e6e8SMatthew G. Knepley PetscDSGetConstants - Returns the array of constants passed to point functions 203897b6e6e8SMatthew G. Knepley 203997b6e6e8SMatthew G. Knepley Not collective 204097b6e6e8SMatthew G. Knepley 204197b6e6e8SMatthew G. Knepley Input Parameter: 204297b6e6e8SMatthew G. Knepley . prob - The PetscDS object 204397b6e6e8SMatthew G. Knepley 204497b6e6e8SMatthew G. Knepley Output Parameters: 204597b6e6e8SMatthew G. Knepley + numConstants - The number of constants 204697b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 204797b6e6e8SMatthew G. Knepley 204897b6e6e8SMatthew G. Knepley Level: intermediate 204997b6e6e8SMatthew G. Knepley 205097b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate() 205197b6e6e8SMatthew G. Knepley @*/ 205297b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[]) 205397b6e6e8SMatthew G. Knepley { 205497b6e6e8SMatthew G. Knepley PetscFunctionBegin; 205597b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 205697b6e6e8SMatthew G. Knepley if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;} 205797b6e6e8SMatthew G. Knepley if (constants) {PetscValidPointer(constants, 3); *constants = prob->constants;} 205897b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 205997b6e6e8SMatthew G. Knepley } 206097b6e6e8SMatthew G. Knepley 20610d3e9b51SMatthew G. Knepley /*@C 206297b6e6e8SMatthew G. Knepley PetscDSSetConstants - Set the array of constants passed to point functions 206397b6e6e8SMatthew G. Knepley 206497b6e6e8SMatthew G. Knepley Not collective 206597b6e6e8SMatthew G. Knepley 206697b6e6e8SMatthew G. Knepley Input Parameters: 206797b6e6e8SMatthew G. Knepley + prob - The PetscDS object 206897b6e6e8SMatthew G. Knepley . numConstants - The number of constants 206997b6e6e8SMatthew G. Knepley - constants - The array of constants, NULL if there are none 207097b6e6e8SMatthew G. Knepley 207197b6e6e8SMatthew G. Knepley Level: intermediate 207297b6e6e8SMatthew G. Knepley 207397b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate() 207497b6e6e8SMatthew G. Knepley @*/ 207597b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[]) 207697b6e6e8SMatthew G. Knepley { 207797b6e6e8SMatthew G. Knepley PetscErrorCode ierr; 207897b6e6e8SMatthew G. Knepley 207997b6e6e8SMatthew G. Knepley PetscFunctionBegin; 208097b6e6e8SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 208197b6e6e8SMatthew G. Knepley if (numConstants != prob->numConstants) { 208297b6e6e8SMatthew G. Knepley ierr = PetscFree(prob->constants);CHKERRQ(ierr); 208397b6e6e8SMatthew G. Knepley prob->constants = NULL; 208497b6e6e8SMatthew G. Knepley } 208597b6e6e8SMatthew G. Knepley prob->numConstants = numConstants; 208697b6e6e8SMatthew G. Knepley if (prob->numConstants) { 208797b6e6e8SMatthew G. Knepley PetscValidPointer(constants, 3); 208897b6e6e8SMatthew G. Knepley ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr); 208997b6e6e8SMatthew G. Knepley ierr = PetscMemcpy(prob->constants, constants, prob->numConstants * sizeof(PetscScalar));CHKERRQ(ierr); 209097b6e6e8SMatthew G. Knepley } 209197b6e6e8SMatthew G. Knepley PetscFunctionReturn(0); 209297b6e6e8SMatthew G. Knepley } 209397b6e6e8SMatthew G. Knepley 20944cd1e086SMatthew G. Knepley /*@ 20954cd1e086SMatthew G. Knepley PetscDSGetFieldIndex - Returns the index of the given field 20964cd1e086SMatthew G. Knepley 20974cd1e086SMatthew G. Knepley Not collective 20984cd1e086SMatthew G. Knepley 20994cd1e086SMatthew G. Knepley Input Parameters: 21004cd1e086SMatthew G. Knepley + prob - The PetscDS object 21014cd1e086SMatthew G. Knepley - disc - The discretization object 21024cd1e086SMatthew G. Knepley 21034cd1e086SMatthew G. Knepley Output Parameter: 21044cd1e086SMatthew G. Knepley . f - The field number 21054cd1e086SMatthew G. Knepley 21064cd1e086SMatthew G. Knepley Level: beginner 21074cd1e086SMatthew G. Knepley 2108f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate() 21094cd1e086SMatthew G. Knepley @*/ 21104cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f) 21114cd1e086SMatthew G. Knepley { 21124cd1e086SMatthew G. Knepley PetscInt g; 21134cd1e086SMatthew G. Knepley 21144cd1e086SMatthew G. Knepley PetscFunctionBegin; 21154cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 21164cd1e086SMatthew G. Knepley PetscValidPointer(f, 3); 21174cd1e086SMatthew G. Knepley *f = -1; 21184cd1e086SMatthew G. Knepley for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;} 21194cd1e086SMatthew G. Knepley if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS."); 21204cd1e086SMatthew G. Knepley *f = g; 21214cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 21224cd1e086SMatthew G. Knepley } 21234cd1e086SMatthew G. Knepley 21244cd1e086SMatthew G. Knepley /*@ 21254cd1e086SMatthew G. Knepley PetscDSGetFieldSize - Returns the size of the given field in the full space basis 21264cd1e086SMatthew G. Knepley 21274cd1e086SMatthew G. Knepley Not collective 21284cd1e086SMatthew G. Knepley 21294cd1e086SMatthew G. Knepley Input Parameters: 21304cd1e086SMatthew G. Knepley + prob - The PetscDS object 21314cd1e086SMatthew G. Knepley - f - The field number 21324cd1e086SMatthew G. Knepley 21334cd1e086SMatthew G. Knepley Output Parameter: 21344cd1e086SMatthew G. Knepley . size - The size 21354cd1e086SMatthew G. Knepley 21364cd1e086SMatthew G. Knepley Level: beginner 21374cd1e086SMatthew G. Knepley 2138f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate() 21394cd1e086SMatthew G. Knepley @*/ 21404cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size) 21414cd1e086SMatthew G. Knepley { 21422166fd64SMatthew G. Knepley PetscErrorCode ierr; 21432166fd64SMatthew G. Knepley 21444cd1e086SMatthew G. Knepley PetscFunctionBegin; 21454cd1e086SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 21464cd1e086SMatthew G. Knepley PetscValidPointer(size, 3); 21474cd1e086SMatthew 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); 21482166fd64SMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 2149d4742ddaSMatthew G. Knepley *size = prob->Nb[f]; 21504cd1e086SMatthew G. Knepley PetscFunctionReturn(0); 21514cd1e086SMatthew G. Knepley } 21524cd1e086SMatthew G. Knepley 2153bc4ae4beSMatthew G. Knepley /*@ 2154bc4ae4beSMatthew G. Knepley PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis 2155bc4ae4beSMatthew G. Knepley 2156bc4ae4beSMatthew G. Knepley Not collective 2157bc4ae4beSMatthew G. Knepley 2158bc4ae4beSMatthew G. Knepley Input Parameters: 2159bc4ae4beSMatthew G. Knepley + prob - The PetscDS object 2160bc4ae4beSMatthew G. Knepley - f - The field number 2161bc4ae4beSMatthew G. Knepley 2162bc4ae4beSMatthew G. Knepley Output Parameter: 2163bc4ae4beSMatthew G. Knepley . off - The offset 2164bc4ae4beSMatthew G. Knepley 2165bc4ae4beSMatthew G. Knepley Level: beginner 2166bc4ae4beSMatthew G. Knepley 2167f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate() 2168bc4ae4beSMatthew G. Knepley @*/ 21692764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off) 21702764a2aaSMatthew G. Knepley { 21714cd1e086SMatthew G. Knepley PetscInt size, g; 21722764a2aaSMatthew G. Knepley PetscErrorCode ierr; 21732764a2aaSMatthew G. Knepley 21742764a2aaSMatthew G. Knepley PetscFunctionBegin; 21752764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 21762764a2aaSMatthew G. Knepley PetscValidPointer(off, 3); 21772764a2aaSMatthew 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); 21782764a2aaSMatthew G. Knepley *off = 0; 21792764a2aaSMatthew G. Knepley for (g = 0; g < f; ++g) { 21804cd1e086SMatthew G. Knepley ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr); 21814cd1e086SMatthew G. Knepley *off += size; 21822764a2aaSMatthew G. Knepley } 21832764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 21842764a2aaSMatthew G. Knepley } 21852764a2aaSMatthew G. Knepley 2186bc4ae4beSMatthew G. Knepley /*@ 218747e57110SSander Arens PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point 2188bc4ae4beSMatthew G. Knepley 2189bc4ae4beSMatthew G. Knepley Not collective 2190bc4ae4beSMatthew G. Knepley 219147e57110SSander Arens Input Parameter: 219247e57110SSander Arens . prob - The PetscDS object 2193bc4ae4beSMatthew G. Knepley 2194bc4ae4beSMatthew G. Knepley Output Parameter: 219547e57110SSander Arens . dimensions - The number of dimensions 2196bc4ae4beSMatthew G. Knepley 2197bc4ae4beSMatthew G. Knepley Level: beginner 2198bc4ae4beSMatthew G. Knepley 219947e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 2200bc4ae4beSMatthew G. Knepley @*/ 220147e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[]) 22022764a2aaSMatthew G. Knepley { 22032764a2aaSMatthew G. Knepley PetscErrorCode ierr; 22042764a2aaSMatthew G. Knepley 22052764a2aaSMatthew G. Knepley PetscFunctionBegin; 22062764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 220747e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 220847e57110SSander Arens PetscValidPointer(dimensions, 2); 220947e57110SSander Arens *dimensions = prob->Nb; 221047e57110SSander Arens PetscFunctionReturn(0); 22116ce16762SMatthew G. Knepley } 221247e57110SSander Arens 221347e57110SSander Arens /*@ 221447e57110SSander Arens PetscDSGetComponents - Returns the number of components for each field on an evaluation point 221547e57110SSander Arens 221647e57110SSander Arens Not collective 221747e57110SSander Arens 221847e57110SSander Arens Input Parameter: 221947e57110SSander Arens . prob - The PetscDS object 222047e57110SSander Arens 222147e57110SSander Arens Output Parameter: 222247e57110SSander Arens . components - The number of components 222347e57110SSander Arens 222447e57110SSander Arens Level: beginner 222547e57110SSander Arens 222647e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate() 222747e57110SSander Arens @*/ 222847e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[]) 222947e57110SSander Arens { 223047e57110SSander Arens PetscErrorCode ierr; 223147e57110SSander Arens 223247e57110SSander Arens PetscFunctionBegin; 223347e57110SSander Arens PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 223447e57110SSander Arens ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 223547e57110SSander Arens PetscValidPointer(components, 2); 223647e57110SSander Arens *components = prob->Nc; 22376ce16762SMatthew G. Knepley PetscFunctionReturn(0); 22386ce16762SMatthew G. Knepley } 22396ce16762SMatthew G. Knepley 22406ce16762SMatthew G. Knepley /*@ 22416ce16762SMatthew G. Knepley PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point 22426ce16762SMatthew G. Knepley 22436ce16762SMatthew G. Knepley Not collective 22446ce16762SMatthew G. Knepley 22456ce16762SMatthew G. Knepley Input Parameters: 22466ce16762SMatthew G. Knepley + prob - The PetscDS object 22476ce16762SMatthew G. Knepley - f - The field number 22486ce16762SMatthew G. Knepley 22496ce16762SMatthew G. Knepley Output Parameter: 22506ce16762SMatthew G. Knepley . off - The offset 22516ce16762SMatthew G. Knepley 22526ce16762SMatthew G. Knepley Level: beginner 22536ce16762SMatthew G. Knepley 2254f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 22556ce16762SMatthew G. Knepley @*/ 22566ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off) 22576ce16762SMatthew G. Knepley { 22586ce16762SMatthew G. Knepley PetscFunctionBegin; 22596ce16762SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 22606ce16762SMatthew G. Knepley PetscValidPointer(off, 3); 22616ce16762SMatthew 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); 226247e57110SSander Arens *off = prob->off[f]; 22632764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 22642764a2aaSMatthew G. Knepley } 22652764a2aaSMatthew G. Knepley 2266194d53e6SMatthew G. Knepley /*@ 2267194d53e6SMatthew G. Knepley PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point 2268194d53e6SMatthew G. Knepley 2269194d53e6SMatthew G. Knepley Not collective 2270194d53e6SMatthew G. Knepley 2271194d53e6SMatthew G. Knepley Input Parameter: 2272194d53e6SMatthew G. Knepley . prob - The PetscDS object 2273194d53e6SMatthew G. Knepley 2274194d53e6SMatthew G. Knepley Output Parameter: 2275194d53e6SMatthew G. Knepley . offsets - The offsets 2276194d53e6SMatthew G. Knepley 2277194d53e6SMatthew G. Knepley Level: beginner 2278194d53e6SMatthew G. Knepley 2279f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2280194d53e6SMatthew G. Knepley @*/ 2281194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[]) 2282194d53e6SMatthew G. Knepley { 2283194d53e6SMatthew G. Knepley PetscFunctionBegin; 2284194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2285194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2286194d53e6SMatthew G. Knepley *offsets = prob->off; 2287194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2288194d53e6SMatthew G. Knepley } 2289194d53e6SMatthew G. Knepley 2290194d53e6SMatthew G. Knepley /*@ 2291194d53e6SMatthew G. Knepley PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point 2292194d53e6SMatthew G. Knepley 2293194d53e6SMatthew G. Knepley Not collective 2294194d53e6SMatthew G. Knepley 2295194d53e6SMatthew G. Knepley Input Parameter: 2296194d53e6SMatthew G. Knepley . prob - The PetscDS object 2297194d53e6SMatthew G. Knepley 2298194d53e6SMatthew G. Knepley Output Parameter: 2299194d53e6SMatthew G. Knepley . offsets - The offsets 2300194d53e6SMatthew G. Knepley 2301194d53e6SMatthew G. Knepley Level: beginner 2302194d53e6SMatthew G. Knepley 2303f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate() 2304194d53e6SMatthew G. Knepley @*/ 2305194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[]) 2306194d53e6SMatthew G. Knepley { 2307194d53e6SMatthew G. Knepley PetscFunctionBegin; 2308194d53e6SMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2309194d53e6SMatthew G. Knepley PetscValidPointer(offsets, 2); 2310194d53e6SMatthew G. Knepley *offsets = prob->offDer; 2311194d53e6SMatthew G. Knepley PetscFunctionReturn(0); 2312194d53e6SMatthew G. Knepley } 2313194d53e6SMatthew G. Knepley 231468c9edb9SMatthew G. Knepley /*@C 231568c9edb9SMatthew G. Knepley PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization 231668c9edb9SMatthew G. Knepley 231768c9edb9SMatthew G. Knepley Not collective 231868c9edb9SMatthew G. Knepley 231968c9edb9SMatthew G. Knepley Input Parameter: 232068c9edb9SMatthew G. Knepley . prob - The PetscDS object 232168c9edb9SMatthew G. Knepley 232268c9edb9SMatthew G. Knepley Output Parameters: 232368c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points 232468c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points 232568c9edb9SMatthew G. Knepley 232668c9edb9SMatthew G. Knepley Level: intermediate 232768c9edb9SMatthew G. Knepley 2328f744cafaSSander Arens .seealso: PetscDSCreate() 232968c9edb9SMatthew G. Knepley @*/ 23302764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer) 23312764a2aaSMatthew G. Knepley { 23322764a2aaSMatthew G. Knepley PetscErrorCode ierr; 23332764a2aaSMatthew G. Knepley 23342764a2aaSMatthew G. Knepley PetscFunctionBegin; 23352764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 23362764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 23372764a2aaSMatthew G. Knepley if (basis) {PetscValidPointer(basis, 2); *basis = prob->basis;} 23382764a2aaSMatthew G. Knepley if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;} 23392764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 23402764a2aaSMatthew G. Knepley } 23412764a2aaSMatthew G. Knepley 234268c9edb9SMatthew G. Knepley /*@C 23434d0b9603SSander Arens PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces 234468c9edb9SMatthew G. Knepley 234568c9edb9SMatthew G. Knepley Not collective 234668c9edb9SMatthew G. Knepley 234768c9edb9SMatthew G. Knepley Input Parameter: 234868c9edb9SMatthew G. Knepley . prob - The PetscDS object 234968c9edb9SMatthew G. Knepley 235068c9edb9SMatthew G. Knepley Output Parameters: 23514d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points 23524d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points 235368c9edb9SMatthew G. Knepley 235468c9edb9SMatthew G. Knepley Level: intermediate 235568c9edb9SMatthew G. Knepley 235668c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate() 235768c9edb9SMatthew G. Knepley @*/ 23584d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer) 23592764a2aaSMatthew G. Knepley { 23602764a2aaSMatthew G. Knepley PetscErrorCode ierr; 23612764a2aaSMatthew G. Knepley 23622764a2aaSMatthew G. Knepley PetscFunctionBegin; 23632764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 23642764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 23654d0b9603SSander Arens if (basis) {PetscValidPointer(basis, 2); *basis = prob->basisFace;} 23664d0b9603SSander Arens if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;} 23672764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 23682764a2aaSMatthew G. Knepley } 23692764a2aaSMatthew G. Knepley 23702764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x) 23712764a2aaSMatthew G. Knepley { 23722764a2aaSMatthew G. Knepley PetscErrorCode ierr; 23732764a2aaSMatthew G. Knepley 23742764a2aaSMatthew G. Knepley PetscFunctionBegin; 23752764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 23762764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 23772764a2aaSMatthew G. Knepley if (u) {PetscValidPointer(u, 2); *u = prob->u;} 23782764a2aaSMatthew G. Knepley if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;} 23792764a2aaSMatthew G. Knepley if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;} 23802764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 23812764a2aaSMatthew G. Knepley } 23822764a2aaSMatthew G. Knepley 23832764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3) 23842764a2aaSMatthew G. Knepley { 23852764a2aaSMatthew G. Knepley PetscErrorCode ierr; 23862764a2aaSMatthew G. Knepley 23872764a2aaSMatthew G. Knepley PetscFunctionBegin; 23882764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 23892764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 23902764a2aaSMatthew G. Knepley if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;} 23912764a2aaSMatthew G. Knepley if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;} 23922764a2aaSMatthew G. Knepley if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;} 23932764a2aaSMatthew G. Knepley if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;} 23942764a2aaSMatthew G. Knepley if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;} 23952764a2aaSMatthew G. Knepley if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;} 23962764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 23972764a2aaSMatthew G. Knepley } 23982764a2aaSMatthew G. Knepley 23992764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer) 24002764a2aaSMatthew G. Knepley { 24012764a2aaSMatthew G. Knepley PetscErrorCode ierr; 24022764a2aaSMatthew G. Knepley 24032764a2aaSMatthew G. Knepley PetscFunctionBegin; 24042764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 24052764a2aaSMatthew G. Knepley ierr = PetscDSSetUp(prob);CHKERRQ(ierr); 24062764a2aaSMatthew G. Knepley if (x) {PetscValidPointer(x, 2); *x = prob->x;} 24072764a2aaSMatthew G. Knepley if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;} 24082764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 24092764a2aaSMatthew G. Knepley } 24102764a2aaSMatthew G. Knepley 241158ebd649SToby Isaac /*@C 241258ebd649SToby Isaac PetscDSAddBoundary - Add a boundary condition to the model 241358ebd649SToby Isaac 241458ebd649SToby Isaac Input Parameters: 241558ebd649SToby Isaac + ds - The PetscDS object 24162d47a189SJulian Andrej . type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 241758ebd649SToby Isaac . name - The BC name 241858ebd649SToby Isaac . labelname - The label defining constrained points 241958ebd649SToby Isaac . field - The field to constrain 242058ebd649SToby Isaac . numcomps - The number of constrained field components 242158ebd649SToby Isaac . comps - An array of constrained component numbers 242258ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 242358ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 242458ebd649SToby Isaac . ids - An array of ids for constrained points 242558ebd649SToby Isaac - ctx - An optional user context for bcFunc 242658ebd649SToby Isaac 242758ebd649SToby Isaac Options Database Keys: 242858ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 242958ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 243058ebd649SToby Isaac 243158ebd649SToby Isaac Level: developer 243258ebd649SToby Isaac 243358ebd649SToby Isaac .seealso: PetscDSGetBoundary() 243458ebd649SToby Isaac @*/ 2435a30ec4eaSSatish Balay PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), PetscInt numids, const PetscInt *ids, void *ctx) 243658ebd649SToby Isaac { 243758ebd649SToby Isaac DSBoundary b; 243858ebd649SToby Isaac PetscErrorCode ierr; 243958ebd649SToby Isaac 244058ebd649SToby Isaac PetscFunctionBegin; 244158ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 244258ebd649SToby Isaac ierr = PetscNew(&b);CHKERRQ(ierr); 244358ebd649SToby Isaac ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 244458ebd649SToby Isaac ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 244558ebd649SToby Isaac ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 244658ebd649SToby Isaac if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);} 244758ebd649SToby Isaac ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 244858ebd649SToby Isaac if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);} 2449f971fd6bSMatthew G. Knepley b->type = type; 245058ebd649SToby Isaac b->field = field; 245158ebd649SToby Isaac b->numcomps = numcomps; 245258ebd649SToby Isaac b->func = bcFunc; 245358ebd649SToby Isaac b->numids = numids; 245458ebd649SToby Isaac b->ctx = ctx; 245558ebd649SToby Isaac b->next = ds->boundary; 245658ebd649SToby Isaac ds->boundary = b; 245758ebd649SToby Isaac PetscFunctionReturn(0); 245858ebd649SToby Isaac } 245958ebd649SToby Isaac 246058ebd649SToby Isaac /*@ 246158ebd649SToby Isaac PetscDSGetNumBoundary - Get the number of registered BC 246258ebd649SToby Isaac 246358ebd649SToby Isaac Input Parameters: 246458ebd649SToby Isaac . ds - The PetscDS object 246558ebd649SToby Isaac 246658ebd649SToby Isaac Output Parameters: 246758ebd649SToby Isaac . numBd - The number of BC 246858ebd649SToby Isaac 246958ebd649SToby Isaac Level: intermediate 247058ebd649SToby Isaac 247158ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary() 247258ebd649SToby Isaac @*/ 247358ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd) 247458ebd649SToby Isaac { 247558ebd649SToby Isaac DSBoundary b = ds->boundary; 247658ebd649SToby Isaac 247758ebd649SToby Isaac PetscFunctionBegin; 247858ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 247958ebd649SToby Isaac PetscValidPointer(numBd, 2); 248058ebd649SToby Isaac *numBd = 0; 248158ebd649SToby Isaac while (b) {++(*numBd); b = b->next;} 248258ebd649SToby Isaac PetscFunctionReturn(0); 248358ebd649SToby Isaac } 248458ebd649SToby Isaac 248558ebd649SToby Isaac /*@C 248658ebd649SToby Isaac PetscDSGetBoundary - Add a boundary condition to the model 248758ebd649SToby Isaac 248858ebd649SToby Isaac Input Parameters: 248958ebd649SToby Isaac + ds - The PetscDS object 249058ebd649SToby Isaac - bd - The BC number 249158ebd649SToby Isaac 249258ebd649SToby Isaac Output Parameters: 24932d47a189SJulian Andrej + type - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann) 249458ebd649SToby Isaac . name - The BC name 249558ebd649SToby Isaac . labelname - The label defining constrained points 249658ebd649SToby Isaac . field - The field to constrain 249758ebd649SToby Isaac . numcomps - The number of constrained field components 249858ebd649SToby Isaac . comps - An array of constrained component numbers 249958ebd649SToby Isaac . bcFunc - A pointwise function giving boundary values 250058ebd649SToby Isaac . numids - The number of DMLabel ids for constrained points 250158ebd649SToby Isaac . ids - An array of ids for constrained points 250258ebd649SToby Isaac - ctx - An optional user context for bcFunc 250358ebd649SToby Isaac 250458ebd649SToby Isaac Options Database Keys: 250558ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 250658ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 250758ebd649SToby Isaac 250858ebd649SToby Isaac Level: developer 250958ebd649SToby Isaac 251058ebd649SToby Isaac .seealso: PetscDSAddBoundary() 251158ebd649SToby Isaac @*/ 2512a30ec4eaSSatish Balay PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType *type, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(void), PetscInt *numids, const PetscInt **ids, void **ctx) 251358ebd649SToby Isaac { 251458ebd649SToby Isaac DSBoundary b = ds->boundary; 251558ebd649SToby Isaac PetscInt n = 0; 251658ebd649SToby Isaac 251758ebd649SToby Isaac PetscFunctionBegin; 251858ebd649SToby Isaac PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1); 251958ebd649SToby Isaac while (b) { 252058ebd649SToby Isaac if (n == bd) break; 252158ebd649SToby Isaac b = b->next; 252258ebd649SToby Isaac ++n; 252358ebd649SToby Isaac } 252458ebd649SToby Isaac if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 2525f971fd6bSMatthew G. Knepley if (type) { 2526f971fd6bSMatthew G. Knepley PetscValidPointer(type, 3); 2527f971fd6bSMatthew G. Knepley *type = b->type; 252858ebd649SToby Isaac } 252958ebd649SToby Isaac if (name) { 253058ebd649SToby Isaac PetscValidPointer(name, 4); 253158ebd649SToby Isaac *name = b->name; 253258ebd649SToby Isaac } 253358ebd649SToby Isaac if (labelname) { 253458ebd649SToby Isaac PetscValidPointer(labelname, 5); 253558ebd649SToby Isaac *labelname = b->labelname; 253658ebd649SToby Isaac } 253758ebd649SToby Isaac if (field) { 253858ebd649SToby Isaac PetscValidPointer(field, 6); 253958ebd649SToby Isaac *field = b->field; 254058ebd649SToby Isaac } 254158ebd649SToby Isaac if (numcomps) { 254258ebd649SToby Isaac PetscValidPointer(numcomps, 7); 254358ebd649SToby Isaac *numcomps = b->numcomps; 254458ebd649SToby Isaac } 254558ebd649SToby Isaac if (comps) { 254658ebd649SToby Isaac PetscValidPointer(comps, 8); 254758ebd649SToby Isaac *comps = b->comps; 254858ebd649SToby Isaac } 254958ebd649SToby Isaac if (func) { 255058ebd649SToby Isaac PetscValidPointer(func, 9); 255158ebd649SToby Isaac *func = b->func; 255258ebd649SToby Isaac } 255358ebd649SToby Isaac if (numids) { 255458ebd649SToby Isaac PetscValidPointer(numids, 10); 255558ebd649SToby Isaac *numids = b->numids; 255658ebd649SToby Isaac } 255758ebd649SToby Isaac if (ids) { 255858ebd649SToby Isaac PetscValidPointer(ids, 11); 255958ebd649SToby Isaac *ids = b->ids; 256058ebd649SToby Isaac } 256158ebd649SToby Isaac if (ctx) { 256258ebd649SToby Isaac PetscValidPointer(ctx, 12); 256358ebd649SToby Isaac *ctx = b->ctx; 256458ebd649SToby Isaac } 256558ebd649SToby Isaac PetscFunctionReturn(0); 256658ebd649SToby Isaac } 256758ebd649SToby Isaac 2568dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB) 2569dff059c6SToby Isaac { 2570dff059c6SToby Isaac DSBoundary b, next, *lastnext; 2571dff059c6SToby Isaac PetscErrorCode ierr; 2572dff059c6SToby Isaac 2573dff059c6SToby Isaac PetscFunctionBegin; 2574dff059c6SToby Isaac PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1); 2575dff059c6SToby Isaac PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2); 2576dff059c6SToby Isaac if (probA == probB) PetscFunctionReturn(0); 2577dff059c6SToby Isaac next = probB->boundary; 2578dff059c6SToby Isaac while (next) { 2579dff059c6SToby Isaac DSBoundary b = next; 2580dff059c6SToby Isaac 2581dff059c6SToby Isaac next = b->next; 2582dff059c6SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 2583dff059c6SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 2584dff059c6SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 2585dff059c6SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 2586dff059c6SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 2587dff059c6SToby Isaac } 2588dff059c6SToby Isaac lastnext = &(probB->boundary); 2589dff059c6SToby Isaac for (b = probA->boundary; b; b = b->next) { 2590dff059c6SToby Isaac DSBoundary bNew; 2591dff059c6SToby Isaac 2592459726d8SSatish Balay ierr = PetscNew(&bNew);CHKERRQ(ierr); 2593dff059c6SToby Isaac bNew->numcomps = b->numcomps; 2594dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr); 2595dff059c6SToby Isaac ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr); 2596dff059c6SToby Isaac bNew->numids = b->numids; 2597dff059c6SToby Isaac ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr); 2598dff059c6SToby Isaac ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr); 2599dff059c6SToby Isaac ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr); 2600dff059c6SToby Isaac ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr); 2601dff059c6SToby Isaac bNew->ctx = b->ctx; 2602f971fd6bSMatthew G. Knepley bNew->type = b->type; 2603dff059c6SToby Isaac bNew->field = b->field; 2604dff059c6SToby Isaac bNew->func = b->func; 2605dff059c6SToby Isaac 2606dff059c6SToby Isaac *lastnext = bNew; 2607dff059c6SToby Isaac lastnext = &(bNew->next); 2608dff059c6SToby Isaac } 2609dff059c6SToby Isaac PetscFunctionReturn(0); 2610dff059c6SToby Isaac } 2611dff059c6SToby Isaac 2612da51fcedSMatthew G. Knepley /*@ 2613da51fcedSMatthew G. Knepley PetscDSCopyEquations - Copy all pointwise function pointers to the new problem 2614da51fcedSMatthew G. Knepley 2615da51fcedSMatthew G. Knepley Not collective 2616da51fcedSMatthew G. Knepley 2617da51fcedSMatthew G. Knepley Input Parameter: 2618da51fcedSMatthew G. Knepley . prob - The PetscDS object 2619da51fcedSMatthew G. Knepley 2620da51fcedSMatthew G. Knepley Output Parameter: 2621da51fcedSMatthew G. Knepley . newprob - The PetscDS copy 2622da51fcedSMatthew G. Knepley 2623da51fcedSMatthew G. Knepley Level: intermediate 2624da51fcedSMatthew G. Knepley 2625da51fcedSMatthew G. Knepley .seealso: PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate() 2626da51fcedSMatthew G. Knepley @*/ 2627da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob) 2628da51fcedSMatthew G. Knepley { 2629da51fcedSMatthew G. Knepley PetscInt Nf, Ng, f, g; 2630da51fcedSMatthew G. Knepley PetscErrorCode ierr; 2631da51fcedSMatthew G. Knepley 2632da51fcedSMatthew G. Knepley PetscFunctionBegin; 2633da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 2634da51fcedSMatthew G. Knepley PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2); 2635da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr); 2636da51fcedSMatthew G. Knepley ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr); 2637da51fcedSMatthew G. Knepley if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);CHKERRQ(ierr); 2638da51fcedSMatthew G. Knepley for (f = 0; f < Nf; ++f) { 2639da51fcedSMatthew G. Knepley PetscPointFunc obj; 2640da51fcedSMatthew G. Knepley PetscPointFunc f0, f1; 2641da51fcedSMatthew G. Knepley PetscPointJac g0, g1, g2, g3; 2642da51fcedSMatthew G. Knepley PetscBdPointFunc f0Bd, f1Bd; 2643da51fcedSMatthew G. Knepley PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd; 2644da51fcedSMatthew G. Knepley PetscRiemannFunc r; 2645da51fcedSMatthew G. Knepley 2646da51fcedSMatthew G. Knepley ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr); 2647da51fcedSMatthew G. Knepley ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr); 2648da51fcedSMatthew G. Knepley ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr); 2649da51fcedSMatthew G. Knepley ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr); 2650da51fcedSMatthew G. Knepley ierr = PetscDSSetObjective(newprob, f, obj);CHKERRQ(ierr); 2651da51fcedSMatthew G. Knepley ierr = PetscDSSetResidual(newprob, f, f0, f1);CHKERRQ(ierr); 2652da51fcedSMatthew G. Knepley ierr = PetscDSSetBdResidual(newprob, f, f0Bd, f1Bd);CHKERRQ(ierr); 2653da51fcedSMatthew G. Knepley ierr = PetscDSSetRiemannSolver(newprob, f, r);CHKERRQ(ierr); 2654da51fcedSMatthew G. Knepley for (g = 0; g < Nf; ++g) { 2655da51fcedSMatthew G. Knepley ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr); 2656da51fcedSMatthew G. Knepley ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr); 2657da51fcedSMatthew G. Knepley ierr = PetscDSSetJacobian(newprob, f, g, g0, g1, g2, g3);CHKERRQ(ierr); 2658da51fcedSMatthew G. Knepley ierr = PetscDSSetBdJacobian(newprob, f, g, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr); 2659da51fcedSMatthew G. Knepley } 2660da51fcedSMatthew G. Knepley } 2661da51fcedSMatthew G. Knepley PetscFunctionReturn(0); 2662da51fcedSMatthew G. Knepley } 2663da51fcedSMatthew G. Knepley 2664bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob) 26652764a2aaSMatthew G. Knepley { 2666931fb3b8SToby Isaac PetscErrorCode ierr; 2667931fb3b8SToby Isaac 26682764a2aaSMatthew G. Knepley PetscFunctionBegin; 2669931fb3b8SToby Isaac ierr = PetscFree(prob->data);CHKERRQ(ierr); 26702764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26712764a2aaSMatthew G. Knepley } 26722764a2aaSMatthew G. Knepley 2673bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob) 26742764a2aaSMatthew G. Knepley { 26752764a2aaSMatthew G. Knepley PetscFunctionBegin; 26762764a2aaSMatthew G. Knepley prob->ops->setfromoptions = NULL; 26772764a2aaSMatthew G. Knepley prob->ops->setup = NULL; 26782764a2aaSMatthew G. Knepley prob->ops->view = NULL; 26792764a2aaSMatthew G. Knepley prob->ops->destroy = PetscDSDestroy_Basic; 26802764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 26812764a2aaSMatthew G. Knepley } 26822764a2aaSMatthew G. Knepley 26832764a2aaSMatthew G. Knepley /*MC 26842764a2aaSMatthew G. Knepley PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions 26852764a2aaSMatthew G. Knepley 26862764a2aaSMatthew G. Knepley Level: intermediate 26872764a2aaSMatthew G. Knepley 26882764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType() 26892764a2aaSMatthew G. Knepley M*/ 26902764a2aaSMatthew G. Knepley 26912764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob) 26922764a2aaSMatthew G. Knepley { 26932764a2aaSMatthew G. Knepley PetscDS_Basic *b; 26942764a2aaSMatthew G. Knepley PetscErrorCode ierr; 26952764a2aaSMatthew G. Knepley 26962764a2aaSMatthew G. Knepley PetscFunctionBegin; 2697931fb3b8SToby Isaac PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1); 26982764a2aaSMatthew G. Knepley ierr = PetscNewLog(prob, &b);CHKERRQ(ierr); 26992764a2aaSMatthew G. Knepley prob->data = b; 27002764a2aaSMatthew G. Knepley 27012764a2aaSMatthew G. Knepley ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr); 27022764a2aaSMatthew G. Knepley PetscFunctionReturn(0); 27032764a2aaSMatthew G. Knepley } 2704