xref: /petsc/src/dm/dt/interface/dtds.c (revision 4d0b9603208f03c394dfdee779423082bcb528af)
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 #undef __FUNCT__
92764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSRegister"
102764a2aaSMatthew G. Knepley /*@C
112764a2aaSMatthew G. Knepley   PetscDSRegister - Adds a new PetscDS implementation
122764a2aaSMatthew G. Knepley 
132764a2aaSMatthew G. Knepley   Not Collective
142764a2aaSMatthew G. Knepley 
152764a2aaSMatthew G. Knepley   Input Parameters:
162764a2aaSMatthew G. Knepley + name        - The name of a new user-defined creation routine
172764a2aaSMatthew G. Knepley - create_func - The creation routine itself
182764a2aaSMatthew G. Knepley 
192764a2aaSMatthew G. Knepley   Notes:
202764a2aaSMatthew G. Knepley   PetscDSRegister() may be called multiple times to add several user-defined PetscDSs
212764a2aaSMatthew G. Knepley 
222764a2aaSMatthew G. Knepley   Sample usage:
232764a2aaSMatthew G. Knepley .vb
242764a2aaSMatthew G. Knepley     PetscDSRegister("my_ds", MyPetscDSCreate);
252764a2aaSMatthew G. Knepley .ve
262764a2aaSMatthew G. Knepley 
272764a2aaSMatthew G. Knepley   Then, your PetscDS type can be chosen with the procedural interface via
282764a2aaSMatthew G. Knepley .vb
292764a2aaSMatthew G. Knepley     PetscDSCreate(MPI_Comm, PetscDS *);
302764a2aaSMatthew G. Knepley     PetscDSSetType(PetscDS, "my_ds");
312764a2aaSMatthew G. Knepley .ve
322764a2aaSMatthew G. Knepley    or at runtime via the option
332764a2aaSMatthew G. Knepley .vb
342764a2aaSMatthew G. Knepley     -petscds_type my_ds
352764a2aaSMatthew G. Knepley .ve
362764a2aaSMatthew G. Knepley 
372764a2aaSMatthew G. Knepley   Level: advanced
382764a2aaSMatthew G. Knepley 
392764a2aaSMatthew G. Knepley .keywords: PetscDS, register
402764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy()
412764a2aaSMatthew G. Knepley 
422764a2aaSMatthew G. Knepley @*/
432764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
442764a2aaSMatthew G. Knepley {
452764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
462764a2aaSMatthew G. Knepley 
472764a2aaSMatthew G. Knepley   PetscFunctionBegin;
482764a2aaSMatthew G. Knepley   ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr);
492764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
502764a2aaSMatthew G. Knepley }
512764a2aaSMatthew G. Knepley 
522764a2aaSMatthew G. Knepley #undef __FUNCT__
532764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetType"
542764a2aaSMatthew G. Knepley /*@C
552764a2aaSMatthew G. Knepley   PetscDSSetType - Builds a particular PetscDS
562764a2aaSMatthew G. Knepley 
572764a2aaSMatthew G. Knepley   Collective on PetscDS
582764a2aaSMatthew G. Knepley 
592764a2aaSMatthew G. Knepley   Input Parameters:
602764a2aaSMatthew G. Knepley + prob - The PetscDS object
612764a2aaSMatthew G. Knepley - name - The kind of system
622764a2aaSMatthew G. Knepley 
632764a2aaSMatthew G. Knepley   Options Database Key:
642764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
652764a2aaSMatthew G. Knepley 
662764a2aaSMatthew G. Knepley   Level: intermediate
672764a2aaSMatthew G. Knepley 
682764a2aaSMatthew G. Knepley .keywords: PetscDS, set, type
692764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate()
702764a2aaSMatthew G. Knepley @*/
712764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
722764a2aaSMatthew G. Knepley {
732764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
742764a2aaSMatthew G. Knepley   PetscBool      match;
752764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
762764a2aaSMatthew G. Knepley 
772764a2aaSMatthew G. Knepley   PetscFunctionBegin;
782764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
792764a2aaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr);
802764a2aaSMatthew G. Knepley   if (match) PetscFunctionReturn(0);
812764a2aaSMatthew G. Knepley 
820f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
832764a2aaSMatthew G. Knepley   ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr);
842764a2aaSMatthew G. Knepley   if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
852764a2aaSMatthew G. Knepley 
862764a2aaSMatthew G. Knepley   if (prob->ops->destroy) {
872764a2aaSMatthew G. Knepley     ierr             = (*prob->ops->destroy)(prob);CHKERRQ(ierr);
882764a2aaSMatthew G. Knepley     prob->ops->destroy = NULL;
892764a2aaSMatthew G. Knepley   }
902764a2aaSMatthew G. Knepley   ierr = (*r)(prob);CHKERRQ(ierr);
912764a2aaSMatthew G. Knepley   ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr);
922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
932764a2aaSMatthew G. Knepley }
942764a2aaSMatthew G. Knepley 
952764a2aaSMatthew G. Knepley #undef __FUNCT__
962764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetType"
972764a2aaSMatthew G. Knepley /*@C
982764a2aaSMatthew G. Knepley   PetscDSGetType - Gets the PetscDS type name (as a string) from the object.
992764a2aaSMatthew G. Knepley 
1002764a2aaSMatthew G. Knepley   Not Collective
1012764a2aaSMatthew G. Knepley 
1022764a2aaSMatthew G. Knepley   Input Parameter:
1032764a2aaSMatthew G. Knepley . prob  - The PetscDS
1042764a2aaSMatthew G. Knepley 
1052764a2aaSMatthew G. Knepley   Output Parameter:
1062764a2aaSMatthew G. Knepley . name - The PetscDS type name
1072764a2aaSMatthew G. Knepley 
1082764a2aaSMatthew G. Knepley   Level: intermediate
1092764a2aaSMatthew G. Knepley 
1102764a2aaSMatthew G. Knepley .keywords: PetscDS, get, type, name
1112764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate()
1122764a2aaSMatthew G. Knepley @*/
1132764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
1142764a2aaSMatthew G. Knepley {
1152764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1162764a2aaSMatthew G. Knepley 
1172764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1182764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
119c959eef4SJed Brown   PetscValidPointer(name, 2);
1200f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
1212764a2aaSMatthew G. Knepley   *name = ((PetscObject) prob)->type_name;
1222764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1232764a2aaSMatthew G. Knepley }
1242764a2aaSMatthew G. Knepley 
1252764a2aaSMatthew G. Knepley #undef __FUNCT__
1267d8a60eaSMatthew G. Knepley #define __FUNCT__ "PetscDSView_Ascii"
1277d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer)
1287d8a60eaSMatthew G. Knepley {
1297d8a60eaSMatthew G. Knepley   PetscViewerFormat format;
1307d8a60eaSMatthew G. Knepley   PetscInt          f;
1317d8a60eaSMatthew G. Knepley   PetscErrorCode    ierr;
1327d8a60eaSMatthew G. Knepley 
1337d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1347d8a60eaSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
1357d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr);
1367d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1377d8a60eaSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1387d8a60eaSMatthew G. Knepley     PetscObject  obj;
1397d8a60eaSMatthew G. Knepley     PetscClassId id;
1407d8a60eaSMatthew G. Knepley     const char  *name;
1417d8a60eaSMatthew G. Knepley     PetscInt     Nc;
1427d8a60eaSMatthew G. Knepley 
1437d8a60eaSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
1447d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
1457d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr);
1467d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr);
1477d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
1487d8a60eaSMatthew G. Knepley       ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr);
1497d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr);
1507d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1517d8a60eaSMatthew G. Knepley       ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr);
1527d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr);
1537d8a60eaSMatthew G. Knepley     }
1547d8a60eaSMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
1557d8a60eaSMatthew G. Knepley     if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%d components", Nc);CHKERRQ(ierr);}
1567d8a60eaSMatthew G. Knepley     else        {ierr = PetscViewerASCIIPrintf(viewer, "%d component ", Nc);CHKERRQ(ierr);}
157249df284SMatthew G. Knepley     if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);}
158249df284SMatthew G. Knepley     else                   {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);}
159a6cbbb48SMatthew G. Knepley     if (prob->adjacency[f*2+0]) {
160a6cbbb48SMatthew G. Knepley       if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM++)");CHKERRQ(ierr);}
161a6cbbb48SMatthew G. Knepley       else                        {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM)");CHKERRQ(ierr);}
162a6cbbb48SMatthew G. Knepley     } else {
163a6cbbb48SMatthew G. Knepley       if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FEM)");CHKERRQ(ierr);}
164a6cbbb48SMatthew G. Knepley       else                        {ierr = PetscViewerASCIIPrintf(viewer, " (adj FUNKY)");CHKERRQ(ierr);}
165a6cbbb48SMatthew G. Knepley     }
1667d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
1677d8a60eaSMatthew G. Knepley     if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
1687d8a60eaSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);}
1697d8a60eaSMatthew G. Knepley       else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);}
1707d8a60eaSMatthew G. Knepley     }
1717d8a60eaSMatthew G. Knepley   }
1727d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
1737d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
1747d8a60eaSMatthew G. Knepley }
1757d8a60eaSMatthew G. Knepley 
1767d8a60eaSMatthew G. Knepley #undef __FUNCT__
1772764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSView"
1782764a2aaSMatthew G. Knepley /*@C
1792764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
1802764a2aaSMatthew G. Knepley 
1812764a2aaSMatthew G. Knepley   Collective on PetscDS
1822764a2aaSMatthew G. Knepley 
1832764a2aaSMatthew G. Knepley   Input Parameter:
1842764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
1852764a2aaSMatthew G. Knepley - v  - the viewer
1862764a2aaSMatthew G. Knepley 
1872764a2aaSMatthew G. Knepley   Level: developer
1882764a2aaSMatthew G. Knepley 
1892764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
1902764a2aaSMatthew G. Knepley @*/
1912764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
1922764a2aaSMatthew G. Knepley {
1937d8a60eaSMatthew G. Knepley   PetscBool      iascii;
1942764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1952764a2aaSMatthew G. Knepley 
1962764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1972764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1982764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
1997d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
2007d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
2017d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2022764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2042764a2aaSMatthew G. Knepley }
2052764a2aaSMatthew G. Knepley 
2062764a2aaSMatthew G. Knepley #undef __FUNCT__
2072764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetFromOptions"
2082764a2aaSMatthew G. Knepley /*@
2092764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2102764a2aaSMatthew G. Knepley 
2112764a2aaSMatthew G. Knepley   Collective on PetscDS
2122764a2aaSMatthew G. Knepley 
2132764a2aaSMatthew G. Knepley   Input Parameter:
2142764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2152764a2aaSMatthew G. Knepley 
2162764a2aaSMatthew G. Knepley   Options Database:
2172764a2aaSMatthew G. Knepley 
2182764a2aaSMatthew G. Knepley   Level: developer
2192764a2aaSMatthew G. Knepley 
2202764a2aaSMatthew G. Knepley .seealso PetscDSView()
2212764a2aaSMatthew G. Knepley @*/
2222764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
2232764a2aaSMatthew G. Knepley {
224f1fd5e65SToby Isaac   DSBoundary     b;
2252764a2aaSMatthew G. Knepley   const char    *defaultType;
2262764a2aaSMatthew G. Knepley   char           name[256];
2272764a2aaSMatthew G. Knepley   PetscBool      flg;
2282764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2292764a2aaSMatthew G. Knepley 
2302764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2312764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2322764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
2332764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
2342764a2aaSMatthew G. Knepley   } else {
2352764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
2362764a2aaSMatthew G. Knepley   }
2370f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
2382764a2aaSMatthew G. Knepley 
2392764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
240f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
241f1fd5e65SToby Isaac     char       optname[1024];
242f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
243f1fd5e65SToby Isaac     PetscBool  flg;
244f1fd5e65SToby Isaac 
245f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
246f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
247f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
248f1fd5e65SToby Isaac     if (flg) {
249f1fd5e65SToby Isaac       b->numids = len;
250f1fd5e65SToby Isaac       ierr = PetscFree(b->ids);CHKERRQ(ierr);
251f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr);
252f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->ids, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
253f1fd5e65SToby Isaac     }
254f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
255f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
256f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
257f1fd5e65SToby Isaac     if (flg) {
258f1fd5e65SToby Isaac       b->numcomps = len;
259f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
260f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
261f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->comps, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
262f1fd5e65SToby Isaac     }
263f1fd5e65SToby Isaac   }
2642764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
2652764a2aaSMatthew G. Knepley   if (flg) {
2662764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
2672764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
2682764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
2692764a2aaSMatthew G. Knepley   }
2702764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
2712764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
2720633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
2732764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
2742764a2aaSMatthew G. Knepley   ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);
2752764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2762764a2aaSMatthew G. Knepley }
2772764a2aaSMatthew G. Knepley 
2782764a2aaSMatthew G. Knepley #undef __FUNCT__
2792764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetUp"
2802764a2aaSMatthew G. Knepley /*@C
2812764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
2822764a2aaSMatthew G. Knepley 
2832764a2aaSMatthew G. Knepley   Collective on PetscDS
2842764a2aaSMatthew G. Knepley 
2852764a2aaSMatthew G. Knepley   Input Parameter:
2862764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
2872764a2aaSMatthew G. Knepley 
2882764a2aaSMatthew G. Knepley   Level: developer
2892764a2aaSMatthew G. Knepley 
2902764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
2912764a2aaSMatthew G. Knepley @*/
2922764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
2932764a2aaSMatthew G. Knepley {
2942764a2aaSMatthew G. Knepley   const PetscInt Nf = prob->Nf;
2952764a2aaSMatthew G. Knepley   PetscInt       dim, work, NcMax = 0, NqMax = 0, f;
2962764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2972764a2aaSMatthew G. Knepley 
2982764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2992764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3002764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3012764a2aaSMatthew G. Knepley   /* Calculate sizes */
3022764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
3032764a2aaSMatthew G. Knepley   prob->totDim = prob->totDimBd = prob->totComp = 0;
30447e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
305194d53e6SMatthew G. Knepley   ierr = PetscCalloc4(Nf+1,&prob->off,Nf+1,&prob->offDer,Nf+1,&prob->offBd,Nf+1,&prob->offDerBd);CHKERRQ(ierr);
306*4d0b9603SSander Arens   ierr = PetscMalloc6(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisBd,Nf,&prob->basisDerBd,Nf,&prob->basisFace,Nf,&prob->basisDerFace);CHKERRQ(ierr);
3072764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3082764a2aaSMatthew G. Knepley     PetscFE         feBd = (PetscFE) prob->discBd[f];
3099de99aefSMatthew G. Knepley     PetscObject     obj;
3109de99aefSMatthew G. Knepley     PetscClassId    id;
3112764a2aaSMatthew G. Knepley     PetscQuadrature q;
3129de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
3132764a2aaSMatthew G. Knepley 
3149de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3159de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3169de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
3179de99aefSMatthew G. Knepley       PetscFE fe = (PetscFE) obj;
3189de99aefSMatthew G. Knepley 
3192764a2aaSMatthew G. Knepley       ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
3202764a2aaSMatthew G. Knepley       ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
3212764a2aaSMatthew G. Knepley       ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
3222764a2aaSMatthew G. Knepley       ierr = PetscFEGetDefaultTabulation(fe, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
323*4d0b9603SSander Arens       ierr = PetscFEGetFaceTabulation(fe, &prob->basisFace[f], &prob->basisDerFace[f], NULL);CHKERRQ(ierr);
3249de99aefSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
3259de99aefSMatthew G. Knepley       PetscFV fv = (PetscFV) obj;
3269de99aefSMatthew G. Knepley 
3279de99aefSMatthew G. Knepley       ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
3289de99aefSMatthew G. Knepley       Nb   = 1;
3299de99aefSMatthew G. Knepley       ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
3306c1a3d01SMatthew G. Knepley       ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
331*4d0b9603SSander Arens       /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
332abac5ca0SMatthew G. Knepley     } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
33347e57110SSander Arens     prob->Nc[f]       = Nc;
33447e57110SSander Arens     prob->Nb[f]       = Nb;
335194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
336194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
3379de99aefSMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
3382764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
3392764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
3402764a2aaSMatthew G. Knepley     prob->totDim  += Nb*Nc;
3412764a2aaSMatthew G. Knepley     prob->totComp += Nc;
3422764a2aaSMatthew G. Knepley     if (feBd) {
3432764a2aaSMatthew G. Knepley       ierr = PetscFEGetDimension(feBd, &Nb);CHKERRQ(ierr);
3442764a2aaSMatthew G. Knepley       ierr = PetscFEGetNumComponents(feBd, &Nc);CHKERRQ(ierr);
3452764a2aaSMatthew G. Knepley       ierr = PetscFEGetDefaultTabulation(feBd, &prob->basisBd[f], &prob->basisDerBd[f], NULL);CHKERRQ(ierr);
3462764a2aaSMatthew G. Knepley       prob->totDimBd += Nb*Nc;
347194d53e6SMatthew G. Knepley       prob->offBd[f+1]    = Nc     + prob->offBd[f];
348194d53e6SMatthew G. Knepley       prob->offDerBd[f+1] = Nc*dim + prob->offDerBd[f];
3492764a2aaSMatthew G. Knepley     }
3502764a2aaSMatthew G. Knepley   }
3512764a2aaSMatthew G. Knepley   work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim));
3522764a2aaSMatthew G. Knepley   /* Allocate works space */
3532764a2aaSMatthew 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);
3542764a2aaSMatthew 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);
3552764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
3562764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
3572764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3582764a2aaSMatthew G. Knepley }
3592764a2aaSMatthew G. Knepley 
3602764a2aaSMatthew G. Knepley #undef __FUNCT__
3612764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroyStructs_Static"
3622764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
3632764a2aaSMatthew G. Knepley {
3642764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3652764a2aaSMatthew G. Knepley 
3662764a2aaSMatthew G. Knepley   PetscFunctionBegin;
36747e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
368194d53e6SMatthew G. Knepley   ierr = PetscFree4(prob->off,prob->offDer,prob->offBd,prob->offDerBd);CHKERRQ(ierr);
369*4d0b9603SSander Arens   ierr = PetscFree6(prob->basis,prob->basisDer,prob->basisBd,prob->basisDerBd,prob->basisFace,prob->basisDerFace);CHKERRQ(ierr);
3702764a2aaSMatthew G. Knepley   ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr);
3712764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
3722764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3732764a2aaSMatthew G. Knepley }
3742764a2aaSMatthew G. Knepley 
3752764a2aaSMatthew G. Knepley #undef __FUNCT__
3762764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSEnlarge_Static"
3772764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
3782764a2aaSMatthew G. Knepley {
3792764a2aaSMatthew G. Knepley   PetscObject      *tmpd, *tmpdbd;
380a6cbbb48SMatthew G. Knepley   PetscBool        *tmpi, *tmpa;
3812aa1fc23SMatthew G. Knepley   PetscPointFunc   *tmpobj, *tmpf;
382b7e05686SMatthew G. Knepley   PetscPointJac    *tmpg, *tmpgp, *tmpgt;
3832aa1fc23SMatthew G. Knepley   PetscBdPointFunc *tmpfbd;
3842aa1fc23SMatthew G. Knepley   PetscBdPointJac  *tmpgbd;
385194d53e6SMatthew G. Knepley   PetscRiemannFunc *tmpr;
3860c2f2876SMatthew G. Knepley   void            **tmpctx;
387a6cbbb48SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f, i;
3882764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
3892764a2aaSMatthew G. Knepley 
3902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3912764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
3922764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
3932764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
394a6cbbb48SMatthew G. Knepley   ierr = PetscMalloc4(NfNew, &tmpd, NfNew, &tmpdbd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr);
395a6cbbb48SMatthew G. Knepley   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpdbd[f] = prob->discBd[f]; tmpi[f] = prob->implicit[f]; for (i = 0; i < 2; ++i) tmpa[f*2+i] = prob->adjacency[f*2+i];}
39654f1004bSSander Arens   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL, tmpdbd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpa[f*2+0] = PETSC_FALSE; tmpa[f*2+1] = PETSC_TRUE;}
397a6cbbb48SMatthew G. Knepley   ierr = PetscFree4(prob->disc, prob->discBd, prob->implicit, prob->adjacency);CHKERRQ(ierr);
3982764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
3992764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
400a6cbbb48SMatthew G. Knepley   prob->discBd    = tmpdbd;
401249df284SMatthew G. Knepley   prob->implicit  = tmpi;
402a6cbbb48SMatthew G. Knepley   prob->adjacency = tmpa;
403b7e05686SMatthew 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);
4042764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f];
4052764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f];
4062764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f];
407475e0ac9SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f];
4080c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f];
4090c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
4102764a2aaSMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL;
4112764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL;
4122764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL;
413475e0ac9SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL;
414b7e05686SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL;
4150c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL;
4160c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
417b7e05686SMatthew G. Knepley   ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr);
4182764a2aaSMatthew G. Knepley   prob->obj = tmpobj;
4192764a2aaSMatthew G. Knepley   prob->f   = tmpf;
4202764a2aaSMatthew G. Knepley   prob->g   = tmpg;
421475e0ac9SMatthew G. Knepley   prob->gp  = tmpgp;
422b7e05686SMatthew G. Knepley   prob->gt  = tmpgt;
4230c2f2876SMatthew G. Knepley   prob->r   = tmpr;
4240c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
4252764a2aaSMatthew G. Knepley   ierr = PetscCalloc2(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd);CHKERRQ(ierr);
4262764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f];
4272764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f];
4282764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL;
4292764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL;
4302764a2aaSMatthew G. Knepley   ierr = PetscFree2(prob->fBd, prob->gBd);CHKERRQ(ierr);
4312764a2aaSMatthew G. Knepley   prob->fBd = tmpfbd;
4322764a2aaSMatthew G. Knepley   prob->gBd = tmpgbd;
4332764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4342764a2aaSMatthew G. Knepley }
4352764a2aaSMatthew G. Knepley 
4362764a2aaSMatthew G. Knepley #undef __FUNCT__
4372764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroy"
4382764a2aaSMatthew G. Knepley /*@
4392764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
4402764a2aaSMatthew G. Knepley 
4412764a2aaSMatthew G. Knepley   Collective on PetscDS
4422764a2aaSMatthew G. Knepley 
4432764a2aaSMatthew G. Knepley   Input Parameter:
4442764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
4452764a2aaSMatthew G. Knepley 
4462764a2aaSMatthew G. Knepley   Level: developer
4472764a2aaSMatthew G. Knepley 
4482764a2aaSMatthew G. Knepley .seealso PetscDSView()
4492764a2aaSMatthew G. Knepley @*/
4502764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob)
4512764a2aaSMatthew G. Knepley {
4522764a2aaSMatthew G. Knepley   PetscInt       f;
45358ebd649SToby Isaac   DSBoundary     next;
4542764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4552764a2aaSMatthew G. Knepley 
4562764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4572764a2aaSMatthew G. Knepley   if (!*prob) PetscFunctionReturn(0);
4582764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1);
4592764a2aaSMatthew G. Knepley 
4602764a2aaSMatthew G. Knepley   if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);}
4612764a2aaSMatthew G. Knepley   ((PetscObject) (*prob))->refct = 0;
4622764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr);
4632764a2aaSMatthew G. Knepley   for (f = 0; f < (*prob)->Nf; ++f) {
4642764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr);
4652764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->discBd[f]);CHKERRQ(ierr);
4662764a2aaSMatthew G. Knepley   }
467a6cbbb48SMatthew G. Knepley   ierr = PetscFree4((*prob)->disc, (*prob)->discBd, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr);
468b7e05686SMatthew G. Knepley   ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr);
4692764a2aaSMatthew G. Knepley   ierr = PetscFree2((*prob)->fBd,(*prob)->gBd);CHKERRQ(ierr);
4702764a2aaSMatthew G. Knepley   if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);}
47158ebd649SToby Isaac   next = (*prob)->boundary;
47258ebd649SToby Isaac   while (next) {
47358ebd649SToby Isaac     DSBoundary b = next;
47458ebd649SToby Isaac 
47558ebd649SToby Isaac     next = b->next;
47658ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
47758ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
47858ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
47958ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
48058ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
48158ebd649SToby Isaac   }
4822764a2aaSMatthew G. Knepley   ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr);
4832764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4842764a2aaSMatthew G. Knepley }
4852764a2aaSMatthew G. Knepley 
4862764a2aaSMatthew G. Knepley #undef __FUNCT__
4872764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSCreate"
4882764a2aaSMatthew G. Knepley /*@
4892764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
4902764a2aaSMatthew G. Knepley 
4912764a2aaSMatthew G. Knepley   Collective on MPI_Comm
4922764a2aaSMatthew G. Knepley 
4932764a2aaSMatthew G. Knepley   Input Parameter:
4942764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
4952764a2aaSMatthew G. Knepley 
4962764a2aaSMatthew G. Knepley   Output Parameter:
4972764a2aaSMatthew G. Knepley . prob - The PetscDS object
4982764a2aaSMatthew G. Knepley 
4992764a2aaSMatthew G. Knepley   Level: beginner
5002764a2aaSMatthew G. Knepley 
5012764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
5022764a2aaSMatthew G. Knepley @*/
5032764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob)
5042764a2aaSMatthew G. Knepley {
5052764a2aaSMatthew G. Knepley   PetscDS   p;
5062764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5072764a2aaSMatthew G. Knepley 
5082764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5092764a2aaSMatthew G. Knepley   PetscValidPointer(prob, 2);
5102764a2aaSMatthew G. Knepley   *prob  = NULL;
5112764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5122764a2aaSMatthew G. Knepley 
51373107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5142764a2aaSMatthew G. Knepley 
5152764a2aaSMatthew G. Knepley   p->Nf    = 0;
5162764a2aaSMatthew G. Knepley   p->setup = PETSC_FALSE;
5172764a2aaSMatthew G. Knepley 
5182764a2aaSMatthew G. Knepley   *prob = p;
5192764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5202764a2aaSMatthew G. Knepley }
5212764a2aaSMatthew G. Knepley 
5222764a2aaSMatthew G. Knepley #undef __FUNCT__
5232764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetNumFields"
524bc4ae4beSMatthew G. Knepley /*@
525bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
526bc4ae4beSMatthew G. Knepley 
527bc4ae4beSMatthew G. Knepley   Not collective
528bc4ae4beSMatthew G. Knepley 
529bc4ae4beSMatthew G. Knepley   Input Parameter:
530bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
531bc4ae4beSMatthew G. Knepley 
532bc4ae4beSMatthew G. Knepley   Output Parameter:
533bc4ae4beSMatthew G. Knepley . Nf - The number of fields
534bc4ae4beSMatthew G. Knepley 
535bc4ae4beSMatthew G. Knepley   Level: beginner
536bc4ae4beSMatthew G. Knepley 
537bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
538bc4ae4beSMatthew G. Knepley @*/
5392764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
5402764a2aaSMatthew G. Knepley {
5412764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5422764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5432764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
5442764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
5452764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5462764a2aaSMatthew G. Knepley }
5472764a2aaSMatthew G. Knepley 
5482764a2aaSMatthew G. Knepley #undef __FUNCT__
5492764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetSpatialDimension"
550bc4ae4beSMatthew G. Knepley /*@
551bc4ae4beSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS
552bc4ae4beSMatthew G. Knepley 
553bc4ae4beSMatthew G. Knepley   Not collective
554bc4ae4beSMatthew G. Knepley 
555bc4ae4beSMatthew G. Knepley   Input Parameter:
556bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
557bc4ae4beSMatthew G. Knepley 
558bc4ae4beSMatthew G. Knepley   Output Parameter:
559bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
560bc4ae4beSMatthew G. Knepley 
561bc4ae4beSMatthew G. Knepley   Level: beginner
562bc4ae4beSMatthew G. Knepley 
563bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
564bc4ae4beSMatthew G. Knepley @*/
5652764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
5662764a2aaSMatthew G. Knepley {
5672764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5682764a2aaSMatthew G. Knepley 
5692764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5702764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5712764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
5722764a2aaSMatthew G. Knepley   *dim = 0;
5739de99aefSMatthew G. Knepley   if (prob->Nf) {
5749de99aefSMatthew G. Knepley     PetscObject  obj;
5759de99aefSMatthew G. Knepley     PetscClassId id;
5769de99aefSMatthew G. Knepley 
5779de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
5789de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
5799de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
5809de99aefSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
5819de99aefSMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
5829de99aefSMatthew G. Knepley   }
5832764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5842764a2aaSMatthew G. Knepley }
5852764a2aaSMatthew G. Knepley 
5862764a2aaSMatthew G. Knepley #undef __FUNCT__
5872764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalDimension"
588bc4ae4beSMatthew G. Knepley /*@
589bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
590bc4ae4beSMatthew G. Knepley 
591bc4ae4beSMatthew G. Knepley   Not collective
592bc4ae4beSMatthew G. Knepley 
593bc4ae4beSMatthew G. Knepley   Input Parameter:
594bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
595bc4ae4beSMatthew G. Knepley 
596bc4ae4beSMatthew G. Knepley   Output Parameter:
597bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
598bc4ae4beSMatthew G. Knepley 
599bc4ae4beSMatthew G. Knepley   Level: beginner
600bc4ae4beSMatthew G. Knepley 
601bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
602bc4ae4beSMatthew G. Knepley @*/
6032764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
6042764a2aaSMatthew G. Knepley {
6052764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6062764a2aaSMatthew G. Knepley 
6072764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6082764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6092764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6102764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6112764a2aaSMatthew G. Knepley   *dim = prob->totDim;
6122764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6132764a2aaSMatthew G. Knepley }
6142764a2aaSMatthew G. Knepley 
6152764a2aaSMatthew G. Knepley #undef __FUNCT__
6162764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalBdDimension"
617bc4ae4beSMatthew G. Knepley /*@
618c3ac4435SMatthew G. Knepley   PetscDSGetTotalBdDimension - Returns the total size of the boundary approximation space for this system
619bc4ae4beSMatthew G. Knepley 
620bc4ae4beSMatthew G. Knepley   Not collective
621bc4ae4beSMatthew G. Knepley 
622bc4ae4beSMatthew G. Knepley   Input Parameter:
623bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
624bc4ae4beSMatthew G. Knepley 
625bc4ae4beSMatthew G. Knepley   Output Parameter:
626bc4ae4beSMatthew G. Knepley . dim - The total boundary problem dimension
627bc4ae4beSMatthew G. Knepley 
628bc4ae4beSMatthew G. Knepley   Level: beginner
629bc4ae4beSMatthew G. Knepley 
630bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
631bc4ae4beSMatthew G. Knepley @*/
6322764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalBdDimension(PetscDS prob, PetscInt *dim)
6332764a2aaSMatthew G. Knepley {
6342764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6352764a2aaSMatthew G. Knepley 
6362764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6372764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6382764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6392764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6402764a2aaSMatthew G. Knepley   *dim = prob->totDimBd;
6412764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6422764a2aaSMatthew G. Knepley }
6432764a2aaSMatthew G. Knepley 
6442764a2aaSMatthew G. Knepley #undef __FUNCT__
6452764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalComponents"
646bc4ae4beSMatthew G. Knepley /*@
647bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
648bc4ae4beSMatthew G. Knepley 
649bc4ae4beSMatthew G. Knepley   Not collective
650bc4ae4beSMatthew G. Knepley 
651bc4ae4beSMatthew G. Knepley   Input Parameter:
652bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
653bc4ae4beSMatthew G. Knepley 
654bc4ae4beSMatthew G. Knepley   Output Parameter:
655bc4ae4beSMatthew G. Knepley . dim - The total number of components
656bc4ae4beSMatthew G. Knepley 
657bc4ae4beSMatthew G. Knepley   Level: beginner
658bc4ae4beSMatthew G. Knepley 
659bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
660bc4ae4beSMatthew G. Knepley @*/
6612764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
6622764a2aaSMatthew G. Knepley {
6632764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6642764a2aaSMatthew G. Knepley 
6652764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6662764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6672764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6682764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
6692764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
6702764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6712764a2aaSMatthew G. Knepley }
6722764a2aaSMatthew G. Knepley 
6732764a2aaSMatthew G. Knepley #undef __FUNCT__
6742764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetDiscretization"
675bc4ae4beSMatthew G. Knepley /*@
676bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
677bc4ae4beSMatthew G. Knepley 
678bc4ae4beSMatthew G. Knepley   Not collective
679bc4ae4beSMatthew G. Knepley 
680bc4ae4beSMatthew G. Knepley   Input Parameters:
681bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
682bc4ae4beSMatthew G. Knepley - f - The field number
683bc4ae4beSMatthew G. Knepley 
684bc4ae4beSMatthew G. Knepley   Output Parameter:
685bc4ae4beSMatthew G. Knepley . disc - The discretization object
686bc4ae4beSMatthew G. Knepley 
687bc4ae4beSMatthew G. Knepley   Level: beginner
688bc4ae4beSMatthew G. Knepley 
689bc4ae4beSMatthew G. Knepley .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
690bc4ae4beSMatthew G. Knepley @*/
6912764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
6922764a2aaSMatthew G. Knepley {
6932764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6942764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6952764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
6962764a2aaSMatthew 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);
6972764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
6982764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6992764a2aaSMatthew G. Knepley }
7002764a2aaSMatthew G. Knepley 
7012764a2aaSMatthew G. Knepley #undef __FUNCT__
7022764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdDiscretization"
703bc4ae4beSMatthew G. Knepley /*@
704bc4ae4beSMatthew G. Knepley   PetscDSGetBdDiscretization - Returns the boundary discretization object for the given field
705bc4ae4beSMatthew G. Knepley 
706bc4ae4beSMatthew G. Knepley   Not collective
707bc4ae4beSMatthew G. Knepley 
708bc4ae4beSMatthew G. Knepley   Input Parameters:
709bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
710bc4ae4beSMatthew G. Knepley - f - The field number
711bc4ae4beSMatthew G. Knepley 
712bc4ae4beSMatthew G. Knepley   Output Parameter:
713bc4ae4beSMatthew G. Knepley . disc - The boundary discretization object
714bc4ae4beSMatthew G. Knepley 
715bc4ae4beSMatthew G. Knepley   Level: beginner
716bc4ae4beSMatthew G. Knepley 
717bc4ae4beSMatthew G. Knepley .seealso: PetscDSSetBdDiscretization(), PetscDSAddBdDiscretization(), PetscDSGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
718bc4ae4beSMatthew G. Knepley @*/
7192764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
7202764a2aaSMatthew G. Knepley {
7212764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7222764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7232764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
7242764a2aaSMatthew 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);
7252764a2aaSMatthew G. Knepley   *disc = prob->discBd[f];
7262764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7272764a2aaSMatthew G. Knepley }
7282764a2aaSMatthew G. Knepley 
7292764a2aaSMatthew G. Knepley #undef __FUNCT__
7302764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetDiscretization"
731bc4ae4beSMatthew G. Knepley /*@
732bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
733bc4ae4beSMatthew G. Knepley 
734bc4ae4beSMatthew G. Knepley   Not collective
735bc4ae4beSMatthew G. Knepley 
736bc4ae4beSMatthew G. Knepley   Input Parameters:
737bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
738bc4ae4beSMatthew G. Knepley . f - The field number
739bc4ae4beSMatthew G. Knepley - disc - The discretization object
740bc4ae4beSMatthew G. Knepley 
741bc4ae4beSMatthew G. Knepley   Level: beginner
742bc4ae4beSMatthew G. Knepley 
743bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
744bc4ae4beSMatthew G. Knepley @*/
7452764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
7462764a2aaSMatthew G. Knepley {
7472764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7482764a2aaSMatthew G. Knepley 
7492764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7502764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7512764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
7522764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
7532764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
7542764a2aaSMatthew G. Knepley   if (prob->disc[f]) {ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);}
7552764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
7562764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
757249df284SMatthew G. Knepley   {
758249df284SMatthew G. Knepley     PetscClassId id;
759249df284SMatthew G. Knepley 
760249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
761a6cbbb48SMatthew G. Knepley     if (id == PETSCFV_CLASSID) {
762a6cbbb48SMatthew G. Knepley       prob->implicit[f]      = PETSC_FALSE;
763a6cbbb48SMatthew G. Knepley       prob->adjacency[f*2+0] = PETSC_TRUE;
764a6cbbb48SMatthew G. Knepley       prob->adjacency[f*2+1] = PETSC_FALSE;
765a6cbbb48SMatthew G. Knepley     }
766249df284SMatthew G. Knepley   }
7672764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7682764a2aaSMatthew G. Knepley }
7692764a2aaSMatthew G. Knepley 
7702764a2aaSMatthew G. Knepley #undef __FUNCT__
7712764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdDiscretization"
772bc4ae4beSMatthew G. Knepley /*@
773bc4ae4beSMatthew G. Knepley   PetscDSSetBdDiscretization - Sets the boundary discretization object for the given field
774bc4ae4beSMatthew G. Knepley 
775bc4ae4beSMatthew G. Knepley   Not collective
776bc4ae4beSMatthew G. Knepley 
777bc4ae4beSMatthew G. Knepley   Input Parameters:
778bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
779bc4ae4beSMatthew G. Knepley . f - The field number
780bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
781bc4ae4beSMatthew G. Knepley 
782bc4ae4beSMatthew G. Knepley   Level: beginner
783bc4ae4beSMatthew G. Knepley 
784bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetBdDiscretization(), PetscDSAddBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
785bc4ae4beSMatthew G. Knepley @*/
7862764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
7872764a2aaSMatthew G. Knepley {
7882764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7892764a2aaSMatthew G. Knepley 
7902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7912764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7922764a2aaSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
7932764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
7942764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
7952764a2aaSMatthew G. Knepley   if (prob->discBd[f]) {ierr = PetscObjectDereference(prob->discBd[f]);CHKERRQ(ierr);}
7962764a2aaSMatthew G. Knepley   prob->discBd[f] = disc;
7972764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
7982764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7992764a2aaSMatthew G. Knepley }
8002764a2aaSMatthew G. Knepley 
8012764a2aaSMatthew G. Knepley #undef __FUNCT__
8022764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSAddDiscretization"
803bc4ae4beSMatthew G. Knepley /*@
804bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
805bc4ae4beSMatthew G. Knepley 
806bc4ae4beSMatthew G. Knepley   Not collective
807bc4ae4beSMatthew G. Knepley 
808bc4ae4beSMatthew G. Knepley   Input Parameters:
809bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
810bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
811bc4ae4beSMatthew G. Knepley 
812bc4ae4beSMatthew G. Knepley   Level: beginner
813bc4ae4beSMatthew G. Knepley 
814bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
815bc4ae4beSMatthew G. Knepley @*/
8162764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
8172764a2aaSMatthew G. Knepley {
8182764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8192764a2aaSMatthew G. Knepley 
8202764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8212764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
8222764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8232764a2aaSMatthew G. Knepley }
8242764a2aaSMatthew G. Knepley 
8252764a2aaSMatthew G. Knepley #undef __FUNCT__
8262764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSAddBdDiscretization"
827bc4ae4beSMatthew G. Knepley /*@
828bc4ae4beSMatthew G. Knepley   PetscDSAddBdDiscretization - Adds a boundary discretization object
829bc4ae4beSMatthew G. Knepley 
830bc4ae4beSMatthew G. Knepley   Not collective
831bc4ae4beSMatthew G. Knepley 
832bc4ae4beSMatthew G. Knepley   Input Parameters:
833bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
834bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
835bc4ae4beSMatthew G. Knepley 
836bc4ae4beSMatthew G. Knepley   Level: beginner
837bc4ae4beSMatthew G. Knepley 
838bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetBdDiscretization(), PetscDSSetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
839bc4ae4beSMatthew G. Knepley @*/
8402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddBdDiscretization(PetscDS prob, PetscObject disc)
8412764a2aaSMatthew G. Knepley {
8422764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8432764a2aaSMatthew G. Knepley 
8442764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8452764a2aaSMatthew G. Knepley   ierr = PetscDSSetBdDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
8462764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8472764a2aaSMatthew G. Knepley }
8482764a2aaSMatthew G. Knepley 
8492764a2aaSMatthew G. Knepley #undef __FUNCT__
850249df284SMatthew G. Knepley #define __FUNCT__ "PetscDSGetImplicit"
851249df284SMatthew G. Knepley /*@
852249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
853249df284SMatthew G. Knepley 
854249df284SMatthew G. Knepley   Not collective
855249df284SMatthew G. Knepley 
856249df284SMatthew G. Knepley   Input Parameters:
857249df284SMatthew G. Knepley + prob - The PetscDS object
858249df284SMatthew G. Knepley - f - The field number
859249df284SMatthew G. Knepley 
860249df284SMatthew G. Knepley   Output Parameter:
861249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
862249df284SMatthew G. Knepley 
863249df284SMatthew G. Knepley   Level: developer
864249df284SMatthew G. Knepley 
865249df284SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
866249df284SMatthew G. Knepley @*/
867249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
868249df284SMatthew G. Knepley {
869249df284SMatthew G. Knepley   PetscFunctionBegin;
870249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
871249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
872249df284SMatthew 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);
873249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
874249df284SMatthew G. Knepley   PetscFunctionReturn(0);
875249df284SMatthew G. Knepley }
876249df284SMatthew G. Knepley 
877249df284SMatthew G. Knepley #undef __FUNCT__
878249df284SMatthew G. Knepley #define __FUNCT__ "PetscDSSetImplicit"
879249df284SMatthew G. Knepley /*@
880249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
881249df284SMatthew G. Knepley 
882249df284SMatthew G. Knepley   Not collective
883249df284SMatthew G. Knepley 
884249df284SMatthew G. Knepley   Input Parameters:
885249df284SMatthew G. Knepley + prob - The PetscDS object
886249df284SMatthew G. Knepley . f - The field number
887249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
888249df284SMatthew G. Knepley 
889249df284SMatthew G. Knepley   Level: developer
890249df284SMatthew G. Knepley 
891249df284SMatthew G. Knepley .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
892249df284SMatthew G. Knepley @*/
893249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
894249df284SMatthew G. Knepley {
895249df284SMatthew G. Knepley   PetscFunctionBegin;
896249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
897249df284SMatthew 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);
898249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
899249df284SMatthew G. Knepley   PetscFunctionReturn(0);
900249df284SMatthew G. Knepley }
901249df284SMatthew G. Knepley 
902249df284SMatthew G. Knepley #undef __FUNCT__
903a6cbbb48SMatthew G. Knepley #define __FUNCT__ "PetscDSGetAdjacency"
904a6cbbb48SMatthew G. Knepley /*@
905a6cbbb48SMatthew G. Knepley   PetscDSGetAdjacency - Returns the flags for determining variable influence
906a6cbbb48SMatthew G. Knepley 
907a6cbbb48SMatthew G. Knepley   Not collective
908a6cbbb48SMatthew G. Knepley 
909a6cbbb48SMatthew G. Knepley   Input Parameters:
910a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
911a6cbbb48SMatthew G. Knepley - f - The field number
912a6cbbb48SMatthew G. Knepley 
913a6cbbb48SMatthew G. Knepley   Output Parameter:
914a6cbbb48SMatthew G. Knepley + useCone    - Flag for variable influence starting with the cone operation
915a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
916a6cbbb48SMatthew G. Knepley 
917a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
918a6cbbb48SMatthew G. Knepley 
919a6cbbb48SMatthew G. Knepley   Level: developer
920a6cbbb48SMatthew G. Knepley 
921a6cbbb48SMatthew G. Knepley .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
922a6cbbb48SMatthew G. Knepley @*/
923a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure)
924a6cbbb48SMatthew G. Knepley {
925a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
926a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
927a6cbbb48SMatthew G. Knepley   PetscValidPointer(useCone, 3);
928a6cbbb48SMatthew G. Knepley   PetscValidPointer(useClosure, 4);
929a6cbbb48SMatthew 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);
930a6cbbb48SMatthew G. Knepley   *useCone    = prob->adjacency[f*2+0];
931a6cbbb48SMatthew G. Knepley   *useClosure = prob->adjacency[f*2+1];
932a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
933a6cbbb48SMatthew G. Knepley }
934a6cbbb48SMatthew G. Knepley 
935a6cbbb48SMatthew G. Knepley #undef __FUNCT__
936a6cbbb48SMatthew G. Knepley #define __FUNCT__ "PetscDSSetAdjacency"
937a6cbbb48SMatthew G. Knepley /*@
938a6cbbb48SMatthew G. Knepley   PetscDSSetAdjacency - Set the flags for determining variable influence
939a6cbbb48SMatthew G. Knepley 
940a6cbbb48SMatthew G. Knepley   Not collective
941a6cbbb48SMatthew G. Knepley 
942a6cbbb48SMatthew G. Knepley   Input Parameters:
943a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
944a6cbbb48SMatthew G. Knepley . f - The field number
945a6cbbb48SMatthew G. Knepley . useCone    - Flag for variable influence starting with the cone operation
946a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
947a6cbbb48SMatthew G. Knepley 
948a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
949a6cbbb48SMatthew G. Knepley 
950a6cbbb48SMatthew G. Knepley   Level: developer
951a6cbbb48SMatthew G. Knepley 
952a6cbbb48SMatthew G. Knepley .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
953a6cbbb48SMatthew G. Knepley @*/
954a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure)
955a6cbbb48SMatthew G. Knepley {
956a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
957a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
958a6cbbb48SMatthew 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);
959a6cbbb48SMatthew G. Knepley   prob->adjacency[f*2+0] = useCone;
960a6cbbb48SMatthew G. Knepley   prob->adjacency[f*2+1] = useClosure;
961a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
962a6cbbb48SMatthew G. Knepley }
963a6cbbb48SMatthew G. Knepley 
964a6cbbb48SMatthew G. Knepley #undef __FUNCT__
9652764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetObjective"
9662764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f,
96730b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
968194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
969194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
97030b9ff8bSMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscScalar obj[]))
9712764a2aaSMatthew G. Knepley {
9722764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9732764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9742764a2aaSMatthew G. Knepley   PetscValidPointer(obj, 2);
9752764a2aaSMatthew 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);
9762764a2aaSMatthew G. Knepley   *obj = prob->obj[f];
9772764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9782764a2aaSMatthew G. Knepley }
9792764a2aaSMatthew G. Knepley 
9802764a2aaSMatthew G. Knepley #undef __FUNCT__
9812764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetObjective"
9822764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f,
98330b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
984194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
985194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
98630b9ff8bSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscScalar obj[]))
9872764a2aaSMatthew G. Knepley {
9882764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9892764a2aaSMatthew G. Knepley 
9902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9912764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
992de716cbcSToby Isaac   if (obj) PetscValidFunction(obj, 2);
9932764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
9942764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
9952764a2aaSMatthew G. Knepley   prob->obj[f] = obj;
9962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9972764a2aaSMatthew G. Knepley }
9982764a2aaSMatthew G. Knepley 
9992764a2aaSMatthew G. Knepley #undef __FUNCT__
10002764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetResidual"
1001194d53e6SMatthew G. Knepley /*@C
1002194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1003194d53e6SMatthew G. Knepley 
1004194d53e6SMatthew G. Knepley   Not collective
1005194d53e6SMatthew G. Knepley 
1006194d53e6SMatthew G. Knepley   Input Parameters:
1007194d53e6SMatthew G. Knepley + prob - The PetscDS
1008194d53e6SMatthew G. Knepley - f    - The test field number
1009194d53e6SMatthew G. Knepley 
1010194d53e6SMatthew G. Knepley   Output Parameters:
1011194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1012194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1013194d53e6SMatthew G. Knepley 
1014194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1015194d53e6SMatthew G. Knepley 
1016194d53e6SMatthew 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)
1017194d53e6SMatthew G. Knepley 
1018194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1019194d53e6SMatthew G. Knepley 
102030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1021194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1022194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
102330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1024194d53e6SMatthew G. Knepley 
1025194d53e6SMatthew G. Knepley + dim - the spatial dimension
1026194d53e6SMatthew G. Knepley . Nf - the number of fields
1027194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1028194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1029194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1030194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1031194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1032194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1033194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1034194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1035194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1036194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1037194d53e6SMatthew G. Knepley . t - current time
1038194d53e6SMatthew G. Knepley . x - coordinates of the current point
1039194d53e6SMatthew G. Knepley - f0 - output values at the current point
1040194d53e6SMatthew G. Knepley 
1041194d53e6SMatthew G. Knepley   Level: intermediate
1042194d53e6SMatthew G. Knepley 
1043194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
1044194d53e6SMatthew G. Knepley @*/
10452764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f,
104630b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1047194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1048194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
104930b9ff8bSMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscScalar f0[]),
105030b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1051194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1052194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
105330b9ff8bSMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscScalar f1[]))
10542764a2aaSMatthew G. Knepley {
10552764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10562764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10572764a2aaSMatthew 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);
10582764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];}
10592764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];}
10602764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10612764a2aaSMatthew G. Knepley }
10622764a2aaSMatthew G. Knepley 
10632764a2aaSMatthew G. Knepley #undef __FUNCT__
10642764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetResidual"
1065194d53e6SMatthew G. Knepley /*@C
1066194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1067194d53e6SMatthew G. Knepley 
1068194d53e6SMatthew G. Knepley   Not collective
1069194d53e6SMatthew G. Knepley 
1070194d53e6SMatthew G. Knepley   Input Parameters:
1071194d53e6SMatthew G. Knepley + prob - The PetscDS
1072194d53e6SMatthew G. Knepley . f    - The test field number
1073194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1074194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1075194d53e6SMatthew G. Knepley 
1076194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1077194d53e6SMatthew G. Knepley 
1078194d53e6SMatthew 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)
1079194d53e6SMatthew G. Knepley 
1080194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1081194d53e6SMatthew G. Knepley 
108230b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1083194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1084194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
108530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1086194d53e6SMatthew G. Knepley 
1087194d53e6SMatthew G. Knepley + dim - the spatial dimension
1088194d53e6SMatthew G. Knepley . Nf - the number of fields
1089194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1090194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1091194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1092194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1093194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1094194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1095194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1096194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1097194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1098194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1099194d53e6SMatthew G. Knepley . t - current time
1100194d53e6SMatthew G. Knepley . x - coordinates of the current point
1101194d53e6SMatthew G. Knepley - f0 - output values at the current point
1102194d53e6SMatthew G. Knepley 
1103194d53e6SMatthew G. Knepley   Level: intermediate
1104194d53e6SMatthew G. Knepley 
1105194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1106194d53e6SMatthew G. Knepley @*/
11072764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f,
110830b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1109194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1110194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
111130b9ff8bSMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscScalar f0[]),
111230b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1113194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1114194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
111530b9ff8bSMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscScalar f1[]))
11162764a2aaSMatthew G. Knepley {
11172764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
11182764a2aaSMatthew G. Knepley 
11192764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11202764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1121f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1122f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
11232764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
11242764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
11252764a2aaSMatthew G. Knepley   prob->f[f*2+0] = f0;
11262764a2aaSMatthew G. Knepley   prob->f[f*2+1] = f1;
11272764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11282764a2aaSMatthew G. Knepley }
11292764a2aaSMatthew G. Knepley 
11302764a2aaSMatthew G. Knepley #undef __FUNCT__
11313e75805dSMatthew G. Knepley #define __FUNCT__ "PetscDSHasJacobian"
11323e75805dSMatthew G. Knepley /*@C
11333e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
11343e75805dSMatthew G. Knepley 
11353e75805dSMatthew G. Knepley   Not collective
11363e75805dSMatthew G. Knepley 
11373e75805dSMatthew G. Knepley   Input Parameter:
11383e75805dSMatthew G. Knepley . prob - The PetscDS
11393e75805dSMatthew G. Knepley 
11403e75805dSMatthew G. Knepley   Output Parameter:
11413e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
11423e75805dSMatthew G. Knepley 
11433e75805dSMatthew G. Knepley   Level: intermediate
11443e75805dSMatthew G. Knepley 
11453e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
11463e75805dSMatthew G. Knepley @*/
11473e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac)
11483e75805dSMatthew G. Knepley {
11493e75805dSMatthew G. Knepley   PetscInt f, g, h;
11503e75805dSMatthew G. Knepley 
11513e75805dSMatthew G. Knepley   PetscFunctionBegin;
11523e75805dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11533e75805dSMatthew G. Knepley   *hasJac = PETSC_FALSE;
11543e75805dSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
11553e75805dSMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
11563e75805dSMatthew G. Knepley       for (h = 0; h < 4; ++h) {
11573e75805dSMatthew G. Knepley         if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE;
11583e75805dSMatthew G. Knepley       }
11593e75805dSMatthew G. Knepley     }
11603e75805dSMatthew G. Knepley   }
11613e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
11623e75805dSMatthew G. Knepley }
11633e75805dSMatthew G. Knepley 
11643e75805dSMatthew G. Knepley #undef __FUNCT__
11652764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetJacobian"
1166194d53e6SMatthew G. Knepley /*@C
1167194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1168194d53e6SMatthew G. Knepley 
1169194d53e6SMatthew G. Knepley   Not collective
1170194d53e6SMatthew G. Knepley 
1171194d53e6SMatthew G. Knepley   Input Parameters:
1172194d53e6SMatthew G. Knepley + prob - The PetscDS
1173194d53e6SMatthew G. Knepley . f    - The test field number
1174194d53e6SMatthew G. Knepley - g    - The field number
1175194d53e6SMatthew G. Knepley 
1176194d53e6SMatthew G. Knepley   Output Parameters:
1177194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1178194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1179194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1180194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1181194d53e6SMatthew G. Knepley 
1182194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1183194d53e6SMatthew G. Knepley 
1184194d53e6SMatthew 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
1185194d53e6SMatthew G. Knepley 
1186194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1187194d53e6SMatthew G. Knepley 
118830b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1189194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1190194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
119130b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1192194d53e6SMatthew G. Knepley 
1193194d53e6SMatthew G. Knepley + dim - the spatial dimension
1194194d53e6SMatthew G. Knepley . Nf - the number of fields
1195194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1196194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1197194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1198194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1199194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1200194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1201194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1202194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1203194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1204194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1205194d53e6SMatthew G. Knepley . t - current time
12062aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1207194d53e6SMatthew G. Knepley . x - coordinates of the current point
1208194d53e6SMatthew G. Knepley - g0 - output values at the current point
1209194d53e6SMatthew G. Knepley 
1210194d53e6SMatthew G. Knepley   Level: intermediate
1211194d53e6SMatthew G. Knepley 
1212194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1213194d53e6SMatthew G. Knepley @*/
12142764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g,
121530b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1216194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1217194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
12182aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
121930b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1220194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1221194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
12222aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
122330b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1224194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1225194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
12262aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
122730b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1228194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1229194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
12302aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
12312764a2aaSMatthew G. Knepley {
12322764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12332764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
12342764a2aaSMatthew 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);
12352764a2aaSMatthew 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);
12362764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];}
12372764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];}
12382764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];}
12392764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];}
12402764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12412764a2aaSMatthew G. Knepley }
12422764a2aaSMatthew G. Knepley 
12432764a2aaSMatthew G. Knepley #undef __FUNCT__
12442764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetJacobian"
1245194d53e6SMatthew G. Knepley /*@C
1246194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1247194d53e6SMatthew G. Knepley 
1248194d53e6SMatthew G. Knepley   Not collective
1249194d53e6SMatthew G. Knepley 
1250194d53e6SMatthew G. Knepley   Input Parameters:
1251194d53e6SMatthew G. Knepley + prob - The PetscDS
1252194d53e6SMatthew G. Knepley . f    - The test field number
1253194d53e6SMatthew G. Knepley . g    - The field number
1254194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1255194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1256194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1257194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1258194d53e6SMatthew G. Knepley 
1259194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1260194d53e6SMatthew G. Knepley 
1261194d53e6SMatthew G. Knepley   \int_\Omega \phi 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
1262194d53e6SMatthew G. Knepley 
1263194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1264194d53e6SMatthew G. Knepley 
126530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1266194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1267194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
126830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1269194d53e6SMatthew G. Knepley 
1270194d53e6SMatthew G. Knepley + dim - the spatial dimension
1271194d53e6SMatthew G. Knepley . Nf - the number of fields
1272194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1273194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1274194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1275194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1276194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1277194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1278194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1279194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1280194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1281194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1282194d53e6SMatthew G. Knepley . t - current time
12832aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1284194d53e6SMatthew G. Knepley . x - coordinates of the current point
1285194d53e6SMatthew G. Knepley - g0 - output values at the current point
1286194d53e6SMatthew G. Knepley 
1287194d53e6SMatthew G. Knepley   Level: intermediate
1288194d53e6SMatthew G. Knepley 
1289194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1290194d53e6SMatthew G. Knepley @*/
12912764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g,
129230b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1293194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1294194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
129530b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
129630b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1297194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1298194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
129930b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
130030b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1301194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1302194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130330b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
130430b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1305194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1306194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130730b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
13082764a2aaSMatthew G. Knepley {
13092764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
13102764a2aaSMatthew G. Knepley 
13112764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13122764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
13132764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
13142764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
13152764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
13162764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
13172764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
13182764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
13192764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
13202764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+0] = g0;
13212764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+1] = g1;
13222764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+2] = g2;
13232764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+3] = g3;
13242764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
13252764a2aaSMatthew G. Knepley }
13262764a2aaSMatthew G. Knepley 
13272764a2aaSMatthew G. Knepley #undef __FUNCT__
1328475e0ac9SMatthew G. Knepley #define __FUNCT__ "PetscDSHasJacobianPreconditioner"
1329475e0ac9SMatthew G. Knepley /*@C
1330475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1331475e0ac9SMatthew G. Knepley 
1332475e0ac9SMatthew G. Knepley   Not collective
1333475e0ac9SMatthew G. Knepley 
1334475e0ac9SMatthew G. Knepley   Input Parameter:
1335475e0ac9SMatthew G. Knepley . prob - The PetscDS
1336475e0ac9SMatthew G. Knepley 
1337475e0ac9SMatthew G. Knepley   Output Parameter:
1338475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1339475e0ac9SMatthew G. Knepley 
1340475e0ac9SMatthew G. Knepley   Level: intermediate
1341475e0ac9SMatthew G. Knepley 
1342475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1343475e0ac9SMatthew G. Knepley @*/
1344475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre)
1345475e0ac9SMatthew G. Knepley {
1346475e0ac9SMatthew G. Knepley   PetscInt f, g, h;
1347475e0ac9SMatthew G. Knepley 
1348475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1349475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1350475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
1351475e0ac9SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1352475e0ac9SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1353475e0ac9SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1354475e0ac9SMatthew G. Knepley         if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE;
1355475e0ac9SMatthew G. Knepley       }
1356475e0ac9SMatthew G. Knepley     }
1357475e0ac9SMatthew G. Knepley   }
1358475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1359475e0ac9SMatthew G. Knepley }
1360475e0ac9SMatthew G. Knepley 
1361475e0ac9SMatthew G. Knepley #undef __FUNCT__
1362475e0ac9SMatthew G. Knepley #define __FUNCT__ "PetscDSGetJacobianPreconditioner"
1363475e0ac9SMatthew G. Knepley /*@C
1364475e0ac9SMatthew G. Knepley   PetscDSGetJacobianPreconditioner - Get the pointwise Jacobian preconditioner function for given test and basis field. If this is missing, the system matrix is used to build the preconditioner.
1365475e0ac9SMatthew G. Knepley 
1366475e0ac9SMatthew G. Knepley   Not collective
1367475e0ac9SMatthew G. Knepley 
1368475e0ac9SMatthew G. Knepley   Input Parameters:
1369475e0ac9SMatthew G. Knepley + prob - The PetscDS
1370475e0ac9SMatthew G. Knepley . f    - The test field number
1371475e0ac9SMatthew G. Knepley - g    - The field number
1372475e0ac9SMatthew G. Knepley 
1373475e0ac9SMatthew G. Knepley   Output Parameters:
1374475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1375475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1376475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1377475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1378475e0ac9SMatthew G. Knepley 
1379475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1380475e0ac9SMatthew G. Knepley 
1381475e0ac9SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1382475e0ac9SMatthew G. Knepley 
1383475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1384475e0ac9SMatthew G. Knepley 
1385475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1386475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1387475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1388475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1389475e0ac9SMatthew G. Knepley 
1390475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1391475e0ac9SMatthew G. Knepley . Nf - the number of fields
1392475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1393475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1394475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1395475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1396475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1397475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1398475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1399475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1400475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1401475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1402475e0ac9SMatthew G. Knepley . t - current time
1403475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1404475e0ac9SMatthew G. Knepley . x - coordinates of the current point
1405475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1406475e0ac9SMatthew G. Knepley 
1407475e0ac9SMatthew G. Knepley   Level: intermediate
1408475e0ac9SMatthew G. Knepley 
1409475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1410475e0ac9SMatthew G. Knepley @*/
1411475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1412475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1413475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1414475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1415475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1416475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1417475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1418475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1419475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1420475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1421475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1422475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1423475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1424475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1425475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1426475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1427475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1428475e0ac9SMatthew G. Knepley {
1429475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1430475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1431475e0ac9SMatthew 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);
1432475e0ac9SMatthew 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);
1433475e0ac9SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];}
1434475e0ac9SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];}
1435475e0ac9SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];}
1436475e0ac9SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];}
1437475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1438475e0ac9SMatthew G. Knepley }
1439475e0ac9SMatthew G. Knepley 
1440475e0ac9SMatthew G. Knepley #undef __FUNCT__
1441475e0ac9SMatthew G. Knepley #define __FUNCT__ "PetscDSSetJacobianPreconditioner"
1442475e0ac9SMatthew G. Knepley /*@C
1443475e0ac9SMatthew G. Knepley   PetscDSSetJacobianPreconditioner - Set the pointwise Jacobian preconditioner function for given test and basis fields. If this is missing, the system matrix is used to build the preconditioner.
1444475e0ac9SMatthew G. Knepley 
1445475e0ac9SMatthew G. Knepley   Not collective
1446475e0ac9SMatthew G. Knepley 
1447475e0ac9SMatthew G. Knepley   Input Parameters:
1448475e0ac9SMatthew G. Knepley + prob - The PetscDS
1449475e0ac9SMatthew G. Knepley . f    - The test field number
1450475e0ac9SMatthew G. Knepley . g    - The field number
1451475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1452475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1453475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1454475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1455475e0ac9SMatthew G. Knepley 
1456475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1457475e0ac9SMatthew G. Knepley 
1458475e0ac9SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1459475e0ac9SMatthew G. Knepley 
1460475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1461475e0ac9SMatthew G. Knepley 
1462475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1463475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1464475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1465475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1466475e0ac9SMatthew G. Knepley 
1467475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1468475e0ac9SMatthew G. Knepley . Nf - the number of fields
1469475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1470475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1471475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1472475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1473475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1474475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1475475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1476475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1477475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1478475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1479475e0ac9SMatthew G. Knepley . t - current time
1480475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1481475e0ac9SMatthew G. Knepley . x - coordinates of the current point
1482475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1483475e0ac9SMatthew G. Knepley 
1484475e0ac9SMatthew G. Knepley   Level: intermediate
1485475e0ac9SMatthew G. Knepley 
1486475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1487475e0ac9SMatthew G. Knepley @*/
1488475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1489475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1490475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1491475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1492475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1493475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1494475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1495475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1496475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1497475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1498475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1499475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1500475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1501475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1502475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1503475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1504475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1505475e0ac9SMatthew G. Knepley {
1506475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1507475e0ac9SMatthew G. Knepley 
1508475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1509475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1510475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1511475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1512475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1513475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1514475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1515475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1516475e0ac9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1517475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+0] = g0;
1518475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+1] = g1;
1519475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+2] = g2;
1520475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+3] = g3;
1521475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1522475e0ac9SMatthew G. Knepley }
1523475e0ac9SMatthew G. Knepley 
1524475e0ac9SMatthew G. Knepley #undef __FUNCT__
1525b7e05686SMatthew G. Knepley #define __FUNCT__ "PetscDSHasDynamicJacobian"
1526b7e05686SMatthew G. Knepley /*@C
1527b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1528b7e05686SMatthew G. Knepley 
1529b7e05686SMatthew G. Knepley   Not collective
1530b7e05686SMatthew G. Knepley 
1531b7e05686SMatthew G. Knepley   Input Parameter:
1532b7e05686SMatthew G. Knepley . prob - The PetscDS
1533b7e05686SMatthew G. Knepley 
1534b7e05686SMatthew G. Knepley   Output Parameter:
1535b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1536b7e05686SMatthew G. Knepley 
1537b7e05686SMatthew G. Knepley   Level: intermediate
1538b7e05686SMatthew G. Knepley 
1539b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1540b7e05686SMatthew G. Knepley @*/
1541b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac)
1542b7e05686SMatthew G. Knepley {
1543b7e05686SMatthew G. Knepley   PetscInt f, g, h;
1544b7e05686SMatthew G. Knepley 
1545b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1546b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1547b7e05686SMatthew G. Knepley   *hasDynJac = PETSC_FALSE;
1548b7e05686SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1549b7e05686SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1550b7e05686SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1551b7e05686SMatthew G. Knepley         if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE;
1552b7e05686SMatthew G. Knepley       }
1553b7e05686SMatthew G. Knepley     }
1554b7e05686SMatthew G. Knepley   }
1555b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1556b7e05686SMatthew G. Knepley }
1557b7e05686SMatthew G. Knepley 
1558b7e05686SMatthew G. Knepley #undef __FUNCT__
1559b7e05686SMatthew G. Knepley #define __FUNCT__ "PetscDSGetDynamicJacobian"
1560b7e05686SMatthew G. Knepley /*@C
1561b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1562b7e05686SMatthew G. Knepley 
1563b7e05686SMatthew G. Knepley   Not collective
1564b7e05686SMatthew G. Knepley 
1565b7e05686SMatthew G. Knepley   Input Parameters:
1566b7e05686SMatthew G. Knepley + prob - The PetscDS
1567b7e05686SMatthew G. Knepley . f    - The test field number
1568b7e05686SMatthew G. Knepley - g    - The field number
1569b7e05686SMatthew G. Knepley 
1570b7e05686SMatthew G. Knepley   Output Parameters:
1571b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1572b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1573b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1574b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1575b7e05686SMatthew G. Knepley 
1576b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1577b7e05686SMatthew G. Knepley 
1578b7e05686SMatthew 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
1579b7e05686SMatthew G. Knepley 
1580b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1581b7e05686SMatthew G. Knepley 
1582b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1583b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1584b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1585b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1586b7e05686SMatthew G. Knepley 
1587b7e05686SMatthew G. Knepley + dim - the spatial dimension
1588b7e05686SMatthew G. Knepley . Nf - the number of fields
1589b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1590b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1591b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1592b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1593b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1594b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1595b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1596b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1597b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1598b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1599b7e05686SMatthew G. Knepley . t - current time
1600b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1601b7e05686SMatthew G. Knepley . x - coordinates of the current point
1602b7e05686SMatthew G. Knepley - g0 - output values at the current point
1603b7e05686SMatthew G. Knepley 
1604b7e05686SMatthew G. Knepley   Level: intermediate
1605b7e05686SMatthew G. Knepley 
1606b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1607b7e05686SMatthew G. Knepley @*/
1608b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1609b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1610b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1611b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1612b7e05686SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1613b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1614b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1615b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1616b7e05686SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1617b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1618b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1619b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1620b7e05686SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1621b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1622b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1623b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1624b7e05686SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1625b7e05686SMatthew G. Knepley {
1626b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1627b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1628b7e05686SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
1629b7e05686SMatthew G. Knepley   if ((g < 0) || (g >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", g, prob->Nf);
1630b7e05686SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];}
1631b7e05686SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];}
1632b7e05686SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];}
1633b7e05686SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];}
1634b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1635b7e05686SMatthew G. Knepley }
1636b7e05686SMatthew G. Knepley 
1637b7e05686SMatthew G. Knepley #undef __FUNCT__
1638b7e05686SMatthew G. Knepley #define __FUNCT__ "PetscDSSetDynamicJacobian"
1639b7e05686SMatthew G. Knepley /*@C
1640b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1641b7e05686SMatthew G. Knepley 
1642b7e05686SMatthew G. Knepley   Not collective
1643b7e05686SMatthew G. Knepley 
1644b7e05686SMatthew G. Knepley   Input Parameters:
1645b7e05686SMatthew G. Knepley + prob - The PetscDS
1646b7e05686SMatthew G. Knepley . f    - The test field number
1647b7e05686SMatthew G. Knepley . g    - The field number
1648b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1649b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1650b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1651b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1652b7e05686SMatthew G. Knepley 
1653b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1654b7e05686SMatthew G. Knepley 
1655b7e05686SMatthew 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
1656b7e05686SMatthew G. Knepley 
1657b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1658b7e05686SMatthew G. Knepley 
1659b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1660b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1661b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1662b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1663b7e05686SMatthew G. Knepley 
1664b7e05686SMatthew G. Knepley + dim - the spatial dimension
1665b7e05686SMatthew G. Knepley . Nf - the number of fields
1666b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1667b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1668b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1669b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1670b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1671b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1672b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1673b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1674b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1675b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1676b7e05686SMatthew G. Knepley . t - current time
1677b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1678b7e05686SMatthew G. Knepley . x - coordinates of the current point
1679b7e05686SMatthew G. Knepley - g0 - output values at the current point
1680b7e05686SMatthew G. Knepley 
1681b7e05686SMatthew G. Knepley   Level: intermediate
1682b7e05686SMatthew G. Knepley 
1683b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1684b7e05686SMatthew G. Knepley @*/
1685b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1686b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1687b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1688b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1689b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1690b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1691b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1692b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1693b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1694b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1695b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1696b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1697b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1698b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1699b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1700b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1701b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1702b7e05686SMatthew G. Knepley {
1703b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1704b7e05686SMatthew G. Knepley 
1705b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1706b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1707b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1708b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1709b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1710b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1711b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1712b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1713b7e05686SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1714b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+0] = g0;
1715b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+1] = g1;
1716b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+2] = g2;
1717b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+3] = g3;
1718b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1719b7e05686SMatthew G. Knepley }
1720b7e05686SMatthew G. Knepley 
1721b7e05686SMatthew G. Knepley #undef __FUNCT__
17220c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSGetRiemannSolver"
17230c2f2876SMatthew G. Knepley /*@C
17240c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
17250c2f2876SMatthew G. Knepley 
17260c2f2876SMatthew G. Knepley   Not collective
17270c2f2876SMatthew G. Knepley 
17280c2f2876SMatthew G. Knepley   Input Arguments:
17290c2f2876SMatthew G. Knepley + prob - The PetscDS object
17300c2f2876SMatthew G. Knepley - f    - The field number
17310c2f2876SMatthew G. Knepley 
17320c2f2876SMatthew G. Knepley   Output Argument:
17330c2f2876SMatthew G. Knepley . r    - Riemann solver
17340c2f2876SMatthew G. Knepley 
17350c2f2876SMatthew G. Knepley   Calling sequence for r:
17360c2f2876SMatthew G. Knepley 
17375db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
17380c2f2876SMatthew G. Knepley 
17395db36cf9SMatthew G. Knepley + dim  - The spatial dimension
17405db36cf9SMatthew G. Knepley . Nf   - The number of fields
17415db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
17420c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
17430c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
17440c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
17450c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
17460c2f2876SMatthew G. Knepley - ctx  - optional user context
17470c2f2876SMatthew G. Knepley 
17480c2f2876SMatthew G. Knepley   Level: intermediate
17490c2f2876SMatthew G. Knepley 
17500c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
17510c2f2876SMatthew G. Knepley @*/
17520c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f,
17535db36cf9SMatthew G. Knepley                                        void (**r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx))
17540c2f2876SMatthew G. Knepley {
17550c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17560c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
17570c2f2876SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
17580c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
17590c2f2876SMatthew G. Knepley   *r = prob->r[f];
17600c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17610c2f2876SMatthew G. Knepley }
17620c2f2876SMatthew G. Knepley 
17630c2f2876SMatthew G. Knepley #undef __FUNCT__
17640c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSSetRiemannSolver"
17650c2f2876SMatthew G. Knepley /*@C
17660c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
17670c2f2876SMatthew G. Knepley 
17680c2f2876SMatthew G. Knepley   Not collective
17690c2f2876SMatthew G. Knepley 
17700c2f2876SMatthew G. Knepley   Input Arguments:
17710c2f2876SMatthew G. Knepley + prob - The PetscDS object
17720c2f2876SMatthew G. Knepley . f    - The field number
17730c2f2876SMatthew G. Knepley - r    - Riemann solver
17740c2f2876SMatthew G. Knepley 
17750c2f2876SMatthew G. Knepley   Calling sequence for r:
17760c2f2876SMatthew G. Knepley 
17775db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
17780c2f2876SMatthew G. Knepley 
17795db36cf9SMatthew G. Knepley + dim  - The spatial dimension
17805db36cf9SMatthew G. Knepley . Nf   - The number of fields
17815db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
17820c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
17830c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
17840c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
17850c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
17860c2f2876SMatthew G. Knepley - ctx  - optional user context
17870c2f2876SMatthew G. Knepley 
17880c2f2876SMatthew G. Knepley   Level: intermediate
17890c2f2876SMatthew G. Knepley 
17900c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
17910c2f2876SMatthew G. Knepley @*/
17920c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f,
17935db36cf9SMatthew G. Knepley                                        void (*r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx))
17940c2f2876SMatthew G. Knepley {
17950c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
17960c2f2876SMatthew G. Knepley 
17970c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17980c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1799de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
18000c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
18010c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
18020c2f2876SMatthew G. Knepley   prob->r[f] = r;
18030c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18040c2f2876SMatthew G. Knepley }
18050c2f2876SMatthew G. Knepley 
18060c2f2876SMatthew G. Knepley #undef __FUNCT__
18070c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSGetContext"
18080c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx)
18090c2f2876SMatthew G. Knepley {
18100c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18110c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18120c2f2876SMatthew 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);
18130c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
18140c2f2876SMatthew G. Knepley   *ctx = prob->ctx[f];
18150c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18160c2f2876SMatthew G. Knepley }
18170c2f2876SMatthew G. Knepley 
18180c2f2876SMatthew G. Knepley #undef __FUNCT__
18190c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSSetContext"
18200c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx)
18210c2f2876SMatthew G. Knepley {
18220c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
18230c2f2876SMatthew G. Knepley 
18240c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18250c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18260c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
18270c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
18280c2f2876SMatthew G. Knepley   prob->ctx[f] = ctx;
18290c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18300c2f2876SMatthew G. Knepley }
18310c2f2876SMatthew G. Knepley 
18320c2f2876SMatthew G. Knepley #undef __FUNCT__
18332764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdResidual"
1834194d53e6SMatthew G. Knepley /*@C
1835194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
1836194d53e6SMatthew G. Knepley 
1837194d53e6SMatthew G. Knepley   Not collective
1838194d53e6SMatthew G. Knepley 
1839194d53e6SMatthew G. Knepley   Input Parameters:
1840194d53e6SMatthew G. Knepley + prob - The PetscDS
1841194d53e6SMatthew G. Knepley - f    - The test field number
1842194d53e6SMatthew G. Knepley 
1843194d53e6SMatthew G. Knepley   Output Parameters:
1844194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
1845194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1846194d53e6SMatthew G. Knepley 
1847194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1848194d53e6SMatthew G. Knepley 
1849194d53e6SMatthew 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
1850194d53e6SMatthew G. Knepley 
1851194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1852194d53e6SMatthew G. Knepley 
185330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1854194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1855194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
185630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1857194d53e6SMatthew G. Knepley 
1858194d53e6SMatthew G. Knepley + dim - the spatial dimension
1859194d53e6SMatthew G. Knepley . Nf - the number of fields
1860194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1861194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1862194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1863194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1864194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1865194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1866194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1867194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1868194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1869194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1870194d53e6SMatthew G. Knepley . t - current time
1871194d53e6SMatthew G. Knepley . x - coordinates of the current point
1872194d53e6SMatthew G. Knepley . n - unit normal at the current point
1873194d53e6SMatthew G. Knepley - f0 - output values at the current point
1874194d53e6SMatthew G. Knepley 
1875194d53e6SMatthew G. Knepley   Level: intermediate
1876194d53e6SMatthew G. Knepley 
1877194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
1878194d53e6SMatthew G. Knepley @*/
18792764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f,
188030b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1881194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1882194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
188330b9ff8bSMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]),
188430b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1885194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1886194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
188730b9ff8bSMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f1[]))
18882764a2aaSMatthew G. Knepley {
18892764a2aaSMatthew G. Knepley   PetscFunctionBegin;
18902764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18912764a2aaSMatthew 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);
18922764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];}
18932764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];}
18942764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
18952764a2aaSMatthew G. Knepley }
18962764a2aaSMatthew G. Knepley 
18972764a2aaSMatthew G. Knepley #undef __FUNCT__
18982764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdResidual"
1899194d53e6SMatthew G. Knepley /*@C
1900194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
1901194d53e6SMatthew G. Knepley 
1902194d53e6SMatthew G. Knepley   Not collective
1903194d53e6SMatthew G. Knepley 
1904194d53e6SMatthew G. Knepley   Input Parameters:
1905194d53e6SMatthew G. Knepley + prob - The PetscDS
1906194d53e6SMatthew G. Knepley . f    - The test field number
1907194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
1908194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1909194d53e6SMatthew G. Knepley 
1910194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1911194d53e6SMatthew G. Knepley 
1912194d53e6SMatthew 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
1913194d53e6SMatthew G. Knepley 
1914194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1915194d53e6SMatthew G. Knepley 
191630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1917194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1918194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
191930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1920194d53e6SMatthew G. Knepley 
1921194d53e6SMatthew G. Knepley + dim - the spatial dimension
1922194d53e6SMatthew G. Knepley . Nf - the number of fields
1923194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1924194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1925194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1926194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1927194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1928194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1929194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1930194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1931194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1932194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1933194d53e6SMatthew G. Knepley . t - current time
1934194d53e6SMatthew G. Knepley . x - coordinates of the current point
1935194d53e6SMatthew G. Knepley . n - unit normal at the current point
1936194d53e6SMatthew G. Knepley - f0 - output values at the current point
1937194d53e6SMatthew G. Knepley 
1938194d53e6SMatthew G. Knepley   Level: intermediate
1939194d53e6SMatthew G. Knepley 
1940194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
1941194d53e6SMatthew G. Knepley @*/
19422764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f,
194330b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1944194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1945194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194630b9ff8bSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]),
194730b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1948194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1949194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
195030b9ff8bSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f1[]))
19512764a2aaSMatthew G. Knepley {
19522764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
19532764a2aaSMatthew G. Knepley 
19542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19552764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19562764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19572764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
19582764a2aaSMatthew G. Knepley   if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;}
19592764a2aaSMatthew G. Knepley   if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;}
19602764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
19612764a2aaSMatthew G. Knepley }
19622764a2aaSMatthew G. Knepley 
19632764a2aaSMatthew G. Knepley #undef __FUNCT__
19642764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdJacobian"
1965194d53e6SMatthew G. Knepley /*@C
1966194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
1967194d53e6SMatthew G. Knepley 
1968194d53e6SMatthew G. Knepley   Not collective
1969194d53e6SMatthew G. Knepley 
1970194d53e6SMatthew G. Knepley   Input Parameters:
1971194d53e6SMatthew G. Knepley + prob - The PetscDS
1972194d53e6SMatthew G. Knepley . f    - The test field number
1973194d53e6SMatthew G. Knepley - g    - The field number
1974194d53e6SMatthew G. Knepley 
1975194d53e6SMatthew G. Knepley   Output Parameters:
1976194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1977194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1978194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1979194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1980194d53e6SMatthew G. Knepley 
1981194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1982194d53e6SMatthew G. Knepley 
1983194d53e6SMatthew 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
1984194d53e6SMatthew G. Knepley 
1985194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1986194d53e6SMatthew G. Knepley 
198730b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1988194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1989194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
199030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
1991194d53e6SMatthew G. Knepley 
1992194d53e6SMatthew G. Knepley + dim - the spatial dimension
1993194d53e6SMatthew G. Knepley . Nf - the number of fields
1994194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1995194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1996194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1997194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1998194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1999194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2000194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2001194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2002194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2003194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2004194d53e6SMatthew G. Knepley . t - current time
20052aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2006194d53e6SMatthew G. Knepley . x - coordinates of the current point
2007194d53e6SMatthew G. Knepley . n - normal at the current point
2008194d53e6SMatthew G. Knepley - g0 - output values at the current point
2009194d53e6SMatthew G. Knepley 
2010194d53e6SMatthew G. Knepley   Level: intermediate
2011194d53e6SMatthew G. Knepley 
2012194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2013194d53e6SMatthew G. Knepley @*/
20142764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
201530b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2016194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2017194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20182aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g0[]),
201930b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2020194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2021194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20222aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g1[]),
202330b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2024194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2025194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20262aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g2[]),
202730b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2028194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2029194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20302aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g3[]))
20312764a2aaSMatthew G. Knepley {
20322764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20332764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20342764a2aaSMatthew 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);
20352764a2aaSMatthew 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);
20362764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];}
20372764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];}
20382764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];}
20392764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];}
20402764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20412764a2aaSMatthew G. Knepley }
20422764a2aaSMatthew G. Knepley 
20432764a2aaSMatthew G. Knepley #undef __FUNCT__
20442764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdJacobian"
2045194d53e6SMatthew G. Knepley /*@C
2046194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2047194d53e6SMatthew G. Knepley 
2048194d53e6SMatthew G. Knepley   Not collective
2049194d53e6SMatthew G. Knepley 
2050194d53e6SMatthew G. Knepley   Input Parameters:
2051194d53e6SMatthew G. Knepley + prob - The PetscDS
2052194d53e6SMatthew G. Knepley . f    - The test field number
2053194d53e6SMatthew G. Knepley . g    - The field number
2054194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2055194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2056194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2057194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2058194d53e6SMatthew G. Knepley 
2059194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2060194d53e6SMatthew G. Knepley 
2061194d53e6SMatthew 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
2062194d53e6SMatthew G. Knepley 
2063194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2064194d53e6SMatthew G. Knepley 
206530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2066194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2067194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
206830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2069194d53e6SMatthew G. Knepley 
2070194d53e6SMatthew G. Knepley + dim - the spatial dimension
2071194d53e6SMatthew G. Knepley . Nf - the number of fields
2072194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2073194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2074194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2075194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2076194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2077194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2078194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2079194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2080194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2081194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2082194d53e6SMatthew G. Knepley . t - current time
20832aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2084194d53e6SMatthew G. Knepley . x - coordinates of the current point
2085194d53e6SMatthew G. Knepley . n - normal at the current point
2086194d53e6SMatthew G. Knepley - g0 - output values at the current point
2087194d53e6SMatthew G. Knepley 
2088194d53e6SMatthew G. Knepley   Level: intermediate
2089194d53e6SMatthew G. Knepley 
2090194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2091194d53e6SMatthew G. Knepley @*/
20922764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
209330b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2094194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2095194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20962aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g0[]),
209730b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2098194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2099194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
21002aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g1[]),
210130b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2102194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2103194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
21042aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g2[]),
210530b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2106194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2107194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
21082aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g3[]))
21092764a2aaSMatthew G. Knepley {
21102764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21112764a2aaSMatthew G. Knepley 
21122764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21132764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21142764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
21152764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
21162764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
21172764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
21182764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21192764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
21202764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
21212764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+0] = g0;
21222764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+1] = g1;
21232764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+2] = g2;
21242764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+3] = g3;
21252764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21262764a2aaSMatthew G. Knepley }
21272764a2aaSMatthew G. Knepley 
21282764a2aaSMatthew G. Knepley #undef __FUNCT__
21294cd1e086SMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldIndex"
21304cd1e086SMatthew G. Knepley /*@
21314cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
21324cd1e086SMatthew G. Knepley 
21334cd1e086SMatthew G. Knepley   Not collective
21344cd1e086SMatthew G. Knepley 
21354cd1e086SMatthew G. Knepley   Input Parameters:
21364cd1e086SMatthew G. Knepley + prob - The PetscDS object
21374cd1e086SMatthew G. Knepley - disc - The discretization object
21384cd1e086SMatthew G. Knepley 
21394cd1e086SMatthew G. Knepley   Output Parameter:
21404cd1e086SMatthew G. Knepley . f - The field number
21414cd1e086SMatthew G. Knepley 
21424cd1e086SMatthew G. Knepley   Level: beginner
21434cd1e086SMatthew G. Knepley 
21444cd1e086SMatthew G. Knepley .seealso: PetscGetDiscretization(), PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
21454cd1e086SMatthew G. Knepley @*/
21464cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
21474cd1e086SMatthew G. Knepley {
21484cd1e086SMatthew G. Knepley   PetscInt g;
21494cd1e086SMatthew G. Knepley 
21504cd1e086SMatthew G. Knepley   PetscFunctionBegin;
21514cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21524cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
21534cd1e086SMatthew G. Knepley   *f = -1;
21544cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
21554cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
21564cd1e086SMatthew G. Knepley   *f = g;
21574cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
21584cd1e086SMatthew G. Knepley }
21594cd1e086SMatthew G. Knepley 
21604cd1e086SMatthew G. Knepley #undef __FUNCT__
21614cd1e086SMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldSize"
21624cd1e086SMatthew G. Knepley /*@
21634cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
21644cd1e086SMatthew G. Knepley 
21654cd1e086SMatthew G. Knepley   Not collective
21664cd1e086SMatthew G. Knepley 
21674cd1e086SMatthew G. Knepley   Input Parameters:
21684cd1e086SMatthew G. Knepley + prob - The PetscDS object
21694cd1e086SMatthew G. Knepley - f - The field number
21704cd1e086SMatthew G. Knepley 
21714cd1e086SMatthew G. Knepley   Output Parameter:
21724cd1e086SMatthew G. Knepley . size - The size
21734cd1e086SMatthew G. Knepley 
21744cd1e086SMatthew G. Knepley   Level: beginner
21754cd1e086SMatthew G. Knepley 
21764cd1e086SMatthew G. Knepley .seealso: PetscDSGetFieldOffset(), PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
21774cd1e086SMatthew G. Knepley @*/
21784cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
21794cd1e086SMatthew G. Knepley {
21804cd1e086SMatthew G. Knepley   PetscInt       Nb, Nc;
21814cd1e086SMatthew G. Knepley   PetscErrorCode ierr;
21824cd1e086SMatthew G. Knepley 
21834cd1e086SMatthew G. Knepley   PetscFunctionBegin;
21844cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21854cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
21864cd1e086SMatthew 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);
218747e57110SSander Arens   *size = prob->Nc[f] * prob->Nb[f];
21884cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
21894cd1e086SMatthew G. Knepley }
21904cd1e086SMatthew G. Knepley 
21914cd1e086SMatthew G. Knepley #undef __FUNCT__
21922764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldOffset"
2193bc4ae4beSMatthew G. Knepley /*@
2194bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2195bc4ae4beSMatthew G. Knepley 
2196bc4ae4beSMatthew G. Knepley   Not collective
2197bc4ae4beSMatthew G. Knepley 
2198bc4ae4beSMatthew G. Knepley   Input Parameters:
2199bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2200bc4ae4beSMatthew G. Knepley - f - The field number
2201bc4ae4beSMatthew G. Knepley 
2202bc4ae4beSMatthew G. Knepley   Output Parameter:
2203bc4ae4beSMatthew G. Knepley . off - The offset
2204bc4ae4beSMatthew G. Knepley 
2205bc4ae4beSMatthew G. Knepley   Level: beginner
2206bc4ae4beSMatthew G. Knepley 
22074cd1e086SMatthew G. Knepley .seealso: PetscDSGetFieldSize(), PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2208bc4ae4beSMatthew G. Knepley @*/
22092764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
22102764a2aaSMatthew G. Knepley {
22114cd1e086SMatthew G. Knepley   PetscInt       size, g;
22122764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
22132764a2aaSMatthew G. Knepley 
22142764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22152764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22162764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
22172764a2aaSMatthew 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);
22182764a2aaSMatthew G. Knepley   *off = 0;
22192764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
22204cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
22214cd1e086SMatthew G. Knepley     *off += size;
22222764a2aaSMatthew G. Knepley   }
22232764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22242764a2aaSMatthew G. Knepley }
22252764a2aaSMatthew G. Knepley 
22262764a2aaSMatthew G. Knepley #undef __FUNCT__
22272764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdFieldOffset"
2228bc4ae4beSMatthew G. Knepley /*@
2229c3ac4435SMatthew G. Knepley   PetscDSGetBdFieldOffset - Returns the offset of the given field in the full space boundary basis
2230bc4ae4beSMatthew G. Knepley 
2231bc4ae4beSMatthew G. Knepley   Not collective
2232bc4ae4beSMatthew G. Knepley 
2233bc4ae4beSMatthew G. Knepley   Input Parameters:
2234bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2235bc4ae4beSMatthew G. Knepley - f - The field number
2236bc4ae4beSMatthew G. Knepley 
2237bc4ae4beSMatthew G. Knepley   Output Parameter:
2238bc4ae4beSMatthew G. Knepley . off - The boundary offset
2239bc4ae4beSMatthew G. Knepley 
2240bc4ae4beSMatthew G. Knepley   Level: beginner
2241bc4ae4beSMatthew G. Knepley 
2242bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2243bc4ae4beSMatthew G. Knepley @*/
22442764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
22452764a2aaSMatthew G. Knepley {
22462764a2aaSMatthew G. Knepley   PetscInt       g;
22472764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
22482764a2aaSMatthew G. Knepley 
22492764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22502764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22512764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
22522764a2aaSMatthew 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);
22532764a2aaSMatthew G. Knepley   *off = 0;
22542764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
22552764a2aaSMatthew G. Knepley     PetscFE  fe = (PetscFE) prob->discBd[g];
22562764a2aaSMatthew G. Knepley     PetscInt Nb, Nc;
22572764a2aaSMatthew G. Knepley 
22582764a2aaSMatthew G. Knepley     ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
22592764a2aaSMatthew G. Knepley     ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
22602764a2aaSMatthew G. Knepley     *off += Nb*Nc;
22616ce16762SMatthew G. Knepley   }
22626ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
22636ce16762SMatthew G. Knepley }
22646ce16762SMatthew G. Knepley 
22656ce16762SMatthew G. Knepley #undef __FUNCT__
226647e57110SSander Arens #define __FUNCT__ "PetscDSGetDimensions"
226747e57110SSander Arens /*@
226847e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
226947e57110SSander Arens 
227047e57110SSander Arens   Not collective
227147e57110SSander Arens 
227247e57110SSander Arens   Input Parameter:
227347e57110SSander Arens . prob - The PetscDS object
227447e57110SSander Arens 
227547e57110SSander Arens   Output Parameter:
227647e57110SSander Arens . dimensions - The number of dimensions
227747e57110SSander Arens 
227847e57110SSander Arens   Level: beginner
227947e57110SSander Arens 
228047e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
228147e57110SSander Arens @*/
228247e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
228347e57110SSander Arens {
228447e57110SSander Arens   PetscErrorCode ierr;
228547e57110SSander Arens 
228647e57110SSander Arens   PetscFunctionBegin;
228747e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
228847e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
228947e57110SSander Arens   PetscValidPointer(dimensions, 2);
229047e57110SSander Arens   *dimensions = prob->Nb;
229147e57110SSander Arens   PetscFunctionReturn(0);
229247e57110SSander Arens }
229347e57110SSander Arens 
229447e57110SSander Arens #undef __FUNCT__
229547e57110SSander Arens #define __FUNCT__ "PetscDSGetComponents"
229647e57110SSander Arens /*@
229747e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
229847e57110SSander Arens 
229947e57110SSander Arens   Not collective
230047e57110SSander Arens 
230147e57110SSander Arens   Input Parameter:
230247e57110SSander Arens . prob - The PetscDS object
230347e57110SSander Arens 
230447e57110SSander Arens   Output Parameter:
230547e57110SSander Arens . components - The number of components
230647e57110SSander Arens 
230747e57110SSander Arens   Level: beginner
230847e57110SSander Arens 
230947e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
231047e57110SSander Arens @*/
231147e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
231247e57110SSander Arens {
231347e57110SSander Arens   PetscErrorCode ierr;
231447e57110SSander Arens 
231547e57110SSander Arens   PetscFunctionBegin;
231647e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
231747e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
231847e57110SSander Arens   PetscValidPointer(components, 2);
231947e57110SSander Arens   *components = prob->Nc;
232047e57110SSander Arens   PetscFunctionReturn(0);
232147e57110SSander Arens }
232247e57110SSander Arens 
232347e57110SSander Arens #undef __FUNCT__
23246ce16762SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentOffset"
23256ce16762SMatthew G. Knepley /*@
23266ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
23276ce16762SMatthew G. Knepley 
23286ce16762SMatthew G. Knepley   Not collective
23296ce16762SMatthew G. Knepley 
23306ce16762SMatthew G. Knepley   Input Parameters:
23316ce16762SMatthew G. Knepley + prob - The PetscDS object
23326ce16762SMatthew G. Knepley - f - The field number
23336ce16762SMatthew G. Knepley 
23346ce16762SMatthew G. Knepley   Output Parameter:
23356ce16762SMatthew G. Knepley . off - The offset
23366ce16762SMatthew G. Knepley 
23376ce16762SMatthew G. Knepley   Level: beginner
23386ce16762SMatthew G. Knepley 
23396ce16762SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
23406ce16762SMatthew G. Knepley @*/
23416ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
23426ce16762SMatthew G. Knepley {
23436ce16762SMatthew G. Knepley   PetscInt       g;
23446ce16762SMatthew G. Knepley   PetscErrorCode ierr;
23456ce16762SMatthew G. Knepley 
23466ce16762SMatthew G. Knepley   PetscFunctionBegin;
23476ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23486ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
23496ce16762SMatthew 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);
235047e57110SSander Arens   *off = prob->off[f];
23512764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23522764a2aaSMatthew G. Knepley }
23532764a2aaSMatthew G. Knepley 
23542764a2aaSMatthew G. Knepley #undef __FUNCT__
2355194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentOffsets"
2356194d53e6SMatthew G. Knepley /*@
2357194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2358194d53e6SMatthew G. Knepley 
2359194d53e6SMatthew G. Knepley   Not collective
2360194d53e6SMatthew G. Knepley 
2361194d53e6SMatthew G. Knepley   Input Parameter:
2362194d53e6SMatthew G. Knepley . prob - The PetscDS object
2363194d53e6SMatthew G. Knepley 
2364194d53e6SMatthew G. Knepley   Output Parameter:
2365194d53e6SMatthew G. Knepley . offsets - The offsets
2366194d53e6SMatthew G. Knepley 
2367194d53e6SMatthew G. Knepley   Level: beginner
2368194d53e6SMatthew G. Knepley 
2369194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2370194d53e6SMatthew G. Knepley @*/
2371194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2372194d53e6SMatthew G. Knepley {
2373194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2374194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2375194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2376194d53e6SMatthew G. Knepley   *offsets = prob->off;
2377194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2378194d53e6SMatthew G. Knepley }
2379194d53e6SMatthew G. Knepley 
2380194d53e6SMatthew G. Knepley #undef __FUNCT__
2381194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentDerivativeOffsets"
2382194d53e6SMatthew G. Knepley /*@
2383194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2384194d53e6SMatthew G. Knepley 
2385194d53e6SMatthew G. Knepley   Not collective
2386194d53e6SMatthew G. Knepley 
2387194d53e6SMatthew G. Knepley   Input Parameter:
2388194d53e6SMatthew G. Knepley . prob - The PetscDS object
2389194d53e6SMatthew G. Knepley 
2390194d53e6SMatthew G. Knepley   Output Parameter:
2391194d53e6SMatthew G. Knepley . offsets - The offsets
2392194d53e6SMatthew G. Knepley 
2393194d53e6SMatthew G. Knepley   Level: beginner
2394194d53e6SMatthew G. Knepley 
2395194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2396194d53e6SMatthew G. Knepley @*/
2397194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2398194d53e6SMatthew G. Knepley {
2399194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2400194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2401194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2402194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
2403194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2404194d53e6SMatthew G. Knepley }
2405194d53e6SMatthew G. Knepley 
2406194d53e6SMatthew G. Knepley #undef __FUNCT__
2407194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentBdOffsets"
2408194d53e6SMatthew G. Knepley /*@
2409194d53e6SMatthew G. Knepley   PetscDSGetComponentBdOffsets - Returns the offset of each field on a boundary evaluation point
2410194d53e6SMatthew G. Knepley 
2411194d53e6SMatthew G. Knepley   Not collective
2412194d53e6SMatthew G. Knepley 
2413194d53e6SMatthew G. Knepley   Input Parameter:
2414194d53e6SMatthew G. Knepley . prob - The PetscDS object
2415194d53e6SMatthew G. Knepley 
2416194d53e6SMatthew G. Knepley   Output Parameter:
2417194d53e6SMatthew G. Knepley . offsets - The offsets
2418194d53e6SMatthew G. Knepley 
2419194d53e6SMatthew G. Knepley   Level: beginner
2420194d53e6SMatthew G. Knepley 
2421194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2422194d53e6SMatthew G. Knepley @*/
2423194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentBdOffsets(PetscDS prob, PetscInt *offsets[])
2424194d53e6SMatthew G. Knepley {
2425194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2426194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2427194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2428194d53e6SMatthew G. Knepley   *offsets = prob->offBd;
2429194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2430194d53e6SMatthew G. Knepley }
2431194d53e6SMatthew G. Knepley 
2432194d53e6SMatthew G. Knepley #undef __FUNCT__
2433194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentBdDerivativeOffsets"
2434194d53e6SMatthew G. Knepley /*@
2435194d53e6SMatthew G. Knepley   PetscDSGetComponentBdDerivativeOffsets - Returns the offset of each field derivative on a boundary evaluation point
2436194d53e6SMatthew G. Knepley 
2437194d53e6SMatthew G. Knepley   Not collective
2438194d53e6SMatthew G. Knepley 
2439194d53e6SMatthew G. Knepley   Input Parameter:
2440194d53e6SMatthew G. Knepley . prob - The PetscDS object
2441194d53e6SMatthew G. Knepley 
2442194d53e6SMatthew G. Knepley   Output Parameter:
2443194d53e6SMatthew G. Knepley . offsets - The offsets
2444194d53e6SMatthew G. Knepley 
2445194d53e6SMatthew G. Knepley   Level: beginner
2446194d53e6SMatthew G. Knepley 
2447194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2448194d53e6SMatthew G. Knepley @*/
2449194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentBdDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2450194d53e6SMatthew G. Knepley {
2451194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2452194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2453194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2454194d53e6SMatthew G. Knepley   *offsets = prob->offDerBd;
2455194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2456194d53e6SMatthew G. Knepley }
2457194d53e6SMatthew G. Knepley 
2458194d53e6SMatthew G. Knepley #undef __FUNCT__
24592764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTabulation"
246068c9edb9SMatthew G. Knepley /*@C
246168c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
246268c9edb9SMatthew G. Knepley 
246368c9edb9SMatthew G. Knepley   Not collective
246468c9edb9SMatthew G. Knepley 
246568c9edb9SMatthew G. Knepley   Input Parameter:
246668c9edb9SMatthew G. Knepley . prob - The PetscDS object
246768c9edb9SMatthew G. Knepley 
246868c9edb9SMatthew G. Knepley   Output Parameters:
246968c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
247068c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
247168c9edb9SMatthew G. Knepley 
247268c9edb9SMatthew G. Knepley   Level: intermediate
247368c9edb9SMatthew G. Knepley 
247468c9edb9SMatthew G. Knepley .seealso: PetscDSGetBdTabulation(), PetscDSCreate()
247568c9edb9SMatthew G. Knepley @*/
24762764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
24772764a2aaSMatthew G. Knepley {
24782764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24792764a2aaSMatthew G. Knepley 
24802764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24812764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24822764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
24832764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basis;}
24842764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;}
24852764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
24862764a2aaSMatthew G. Knepley }
24872764a2aaSMatthew G. Knepley 
24882764a2aaSMatthew G. Knepley #undef __FUNCT__
2489*4d0b9603SSander Arens #define __FUNCT__ "PetscDSGetFaceTabulation"
2490*4d0b9603SSander Arens /*@C
2491*4d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
2492*4d0b9603SSander Arens 
2493*4d0b9603SSander Arens   Not collective
2494*4d0b9603SSander Arens 
2495*4d0b9603SSander Arens   Input Parameter:
2496*4d0b9603SSander Arens . prob - The PetscDS object
2497*4d0b9603SSander Arens 
2498*4d0b9603SSander Arens   Output Parameters:
2499*4d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points
2500*4d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points
2501*4d0b9603SSander Arens 
2502*4d0b9603SSander Arens   Level: intermediate
2503*4d0b9603SSander Arens 
2504*4d0b9603SSander Arens .seealso: PetscDSGetTabulation(), PetscDSCreate()
2505*4d0b9603SSander Arens @*/
2506*4d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
2507*4d0b9603SSander Arens {
2508*4d0b9603SSander Arens   PetscErrorCode ierr;
2509*4d0b9603SSander Arens 
2510*4d0b9603SSander Arens   PetscFunctionBegin;
2511*4d0b9603SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2512*4d0b9603SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2513*4d0b9603SSander Arens   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basisFace;}
2514*4d0b9603SSander Arens   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;}
2515*4d0b9603SSander Arens   PetscFunctionReturn(0);
2516*4d0b9603SSander Arens }
2517*4d0b9603SSander Arens 
2518*4d0b9603SSander Arens 
2519*4d0b9603SSander Arens #undef __FUNCT__
25202764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdTabulation"
252168c9edb9SMatthew G. Knepley /*@C
252268c9edb9SMatthew G. Knepley   PetscDSGetBdTabulation - Return the basis tabulation at quadrature points for the boundary discretization
252368c9edb9SMatthew G. Knepley 
252468c9edb9SMatthew G. Knepley   Not collective
252568c9edb9SMatthew G. Knepley 
252668c9edb9SMatthew G. Knepley   Input Parameter:
252768c9edb9SMatthew G. Knepley . prob - The PetscDS object
252868c9edb9SMatthew G. Knepley 
252968c9edb9SMatthew G. Knepley   Output Parameters:
253068c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
253168c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
253268c9edb9SMatthew G. Knepley 
253368c9edb9SMatthew G. Knepley   Level: intermediate
253468c9edb9SMatthew G. Knepley 
253568c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
253668c9edb9SMatthew G. Knepley @*/
25372764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
25382764a2aaSMatthew G. Knepley {
25392764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25402764a2aaSMatthew G. Knepley 
25412764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25422764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25432764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25442764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basisBd;}
25452764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerBd;}
25462764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25472764a2aaSMatthew G. Knepley }
25482764a2aaSMatthew G. Knepley 
25492764a2aaSMatthew G. Knepley #undef __FUNCT__
25502764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetEvaluationArrays"
25512764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
25522764a2aaSMatthew G. Knepley {
25532764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25542764a2aaSMatthew G. Knepley 
25552764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25562764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25572764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25582764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
25592764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
25602764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
25612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25622764a2aaSMatthew G. Knepley }
25632764a2aaSMatthew G. Knepley 
25642764a2aaSMatthew G. Knepley #undef __FUNCT__
25652764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetWeakFormArrays"
25662764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
25672764a2aaSMatthew G. Knepley {
25682764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25692764a2aaSMatthew G. Knepley 
25702764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25712764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25722764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25732764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
25742764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
25752764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
25762764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
25772764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
25782764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
25792764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25802764a2aaSMatthew G. Knepley }
25812764a2aaSMatthew G. Knepley 
25822764a2aaSMatthew G. Knepley #undef __FUNCT__
25832764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetRefCoordArrays"
25842764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer)
25852764a2aaSMatthew G. Knepley {
25862764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25872764a2aaSMatthew G. Knepley 
25882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25902764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25912764a2aaSMatthew G. Knepley   if (x)           {PetscValidPointer(x, 2);           *x           = prob->x;}
25922764a2aaSMatthew G. Knepley   if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;}
25932764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25942764a2aaSMatthew G. Knepley }
25952764a2aaSMatthew G. Knepley 
25962764a2aaSMatthew G. Knepley #undef __FUNCT__
259758ebd649SToby Isaac #define __FUNCT__ "PetscDSAddBoundary"
259858ebd649SToby Isaac /*@C
259958ebd649SToby Isaac   PetscDSAddBoundary - Add a boundary condition to the model
260058ebd649SToby Isaac 
260158ebd649SToby Isaac   Input Parameters:
260258ebd649SToby Isaac + ds          - The PetscDS object
260358ebd649SToby Isaac . isEssential - Flag for an essential (Dirichlet) condition, as opposed to a natural (Neumann) condition
260458ebd649SToby Isaac . name        - The BC name
260558ebd649SToby Isaac . labelname   - The label defining constrained points
260658ebd649SToby Isaac . field       - The field to constrain
260758ebd649SToby Isaac . numcomps    - The number of constrained field components
260858ebd649SToby Isaac . comps       - An array of constrained component numbers
260958ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
261058ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
261158ebd649SToby Isaac . ids         - An array of ids for constrained points
261258ebd649SToby Isaac - ctx         - An optional user context for bcFunc
261358ebd649SToby Isaac 
261458ebd649SToby Isaac   Options Database Keys:
261558ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
261658ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
261758ebd649SToby Isaac 
261858ebd649SToby Isaac   Level: developer
261958ebd649SToby Isaac 
262058ebd649SToby Isaac .seealso: PetscDSGetBoundary()
262158ebd649SToby Isaac @*/
262258ebd649SToby Isaac PetscErrorCode PetscDSAddBoundary(PetscDS ds, PetscBool isEssential, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(), PetscInt numids, const PetscInt *ids, void *ctx)
262358ebd649SToby Isaac {
262458ebd649SToby Isaac   DSBoundary     b;
262558ebd649SToby Isaac   PetscErrorCode ierr;
262658ebd649SToby Isaac 
262758ebd649SToby Isaac   PetscFunctionBegin;
262858ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
262958ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
263058ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
263158ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
263258ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
263358ebd649SToby Isaac   if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
263458ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
263558ebd649SToby Isaac   if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
263658ebd649SToby Isaac   b->essential       = isEssential;
263758ebd649SToby Isaac   b->field           = field;
263858ebd649SToby Isaac   b->numcomps        = numcomps;
263958ebd649SToby Isaac   b->func            = bcFunc;
264058ebd649SToby Isaac   b->numids          = numids;
264158ebd649SToby Isaac   b->ctx             = ctx;
264258ebd649SToby Isaac   b->next            = ds->boundary;
264358ebd649SToby Isaac   ds->boundary       = b;
264458ebd649SToby Isaac   PetscFunctionReturn(0);
264558ebd649SToby Isaac }
264658ebd649SToby Isaac 
264758ebd649SToby Isaac #undef __FUNCT__
264858ebd649SToby Isaac #define __FUNCT__ "PetscDSGetNumBoundary"
264958ebd649SToby Isaac /*@
265058ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
265158ebd649SToby Isaac 
265258ebd649SToby Isaac   Input Parameters:
265358ebd649SToby Isaac . ds - The PetscDS object
265458ebd649SToby Isaac 
265558ebd649SToby Isaac   Output Parameters:
265658ebd649SToby Isaac . numBd - The number of BC
265758ebd649SToby Isaac 
265858ebd649SToby Isaac   Level: intermediate
265958ebd649SToby Isaac 
266058ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
266158ebd649SToby Isaac @*/
266258ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
266358ebd649SToby Isaac {
266458ebd649SToby Isaac   DSBoundary b = ds->boundary;
266558ebd649SToby Isaac 
266658ebd649SToby Isaac   PetscFunctionBegin;
266758ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
266858ebd649SToby Isaac   PetscValidPointer(numBd, 2);
266958ebd649SToby Isaac   *numBd = 0;
267058ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
267158ebd649SToby Isaac   PetscFunctionReturn(0);
267258ebd649SToby Isaac }
267358ebd649SToby Isaac 
267458ebd649SToby Isaac #undef __FUNCT__
267558ebd649SToby Isaac #define __FUNCT__ "PetscDSGetBoundary"
267658ebd649SToby Isaac /*@C
267758ebd649SToby Isaac   PetscDSGetBoundary - Add a boundary condition to the model
267858ebd649SToby Isaac 
267958ebd649SToby Isaac   Input Parameters:
268058ebd649SToby Isaac + ds          - The PetscDS object
268158ebd649SToby Isaac - bd          - The BC number
268258ebd649SToby Isaac 
268358ebd649SToby Isaac   Output Parameters:
268458ebd649SToby Isaac + isEssential - Flag for an essential (Dirichlet) condition, as opposed to a natural (Neumann) condition
268558ebd649SToby Isaac . name        - The BC name
268658ebd649SToby Isaac . labelname   - The label defining constrained points
268758ebd649SToby Isaac . field       - The field to constrain
268858ebd649SToby Isaac . numcomps    - The number of constrained field components
268958ebd649SToby Isaac . comps       - An array of constrained component numbers
269058ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
269158ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
269258ebd649SToby Isaac . ids         - An array of ids for constrained points
269358ebd649SToby Isaac - ctx         - An optional user context for bcFunc
269458ebd649SToby Isaac 
269558ebd649SToby Isaac   Options Database Keys:
269658ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
269758ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
269858ebd649SToby Isaac 
269958ebd649SToby Isaac   Level: developer
270058ebd649SToby Isaac 
270158ebd649SToby Isaac .seealso: PetscDSAddBoundary()
270258ebd649SToby Isaac @*/
270358ebd649SToby Isaac PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, PetscBool *isEssential, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(), PetscInt *numids, const PetscInt **ids, void **ctx)
270458ebd649SToby Isaac {
270558ebd649SToby Isaac   DSBoundary b    = ds->boundary;
270658ebd649SToby Isaac   PetscInt   n    = 0;
270758ebd649SToby Isaac 
270858ebd649SToby Isaac   PetscFunctionBegin;
270958ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
271058ebd649SToby Isaac   while (b) {
271158ebd649SToby Isaac     if (n == bd) break;
271258ebd649SToby Isaac     b = b->next;
271358ebd649SToby Isaac     ++n;
271458ebd649SToby Isaac   }
271558ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
271658ebd649SToby Isaac   if (isEssential) {
271758ebd649SToby Isaac     PetscValidPointer(isEssential, 3);
271858ebd649SToby Isaac     *isEssential = b->essential;
271958ebd649SToby Isaac   }
272058ebd649SToby Isaac   if (name) {
272158ebd649SToby Isaac     PetscValidPointer(name, 4);
272258ebd649SToby Isaac     *name = b->name;
272358ebd649SToby Isaac   }
272458ebd649SToby Isaac   if (labelname) {
272558ebd649SToby Isaac     PetscValidPointer(labelname, 5);
272658ebd649SToby Isaac     *labelname = b->labelname;
272758ebd649SToby Isaac   }
272858ebd649SToby Isaac   if (field) {
272958ebd649SToby Isaac     PetscValidPointer(field, 6);
273058ebd649SToby Isaac     *field = b->field;
273158ebd649SToby Isaac   }
273258ebd649SToby Isaac   if (numcomps) {
273358ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
273458ebd649SToby Isaac     *numcomps = b->numcomps;
273558ebd649SToby Isaac   }
273658ebd649SToby Isaac   if (comps) {
273758ebd649SToby Isaac     PetscValidPointer(comps, 8);
273858ebd649SToby Isaac     *comps = b->comps;
273958ebd649SToby Isaac   }
274058ebd649SToby Isaac   if (func) {
274158ebd649SToby Isaac     PetscValidPointer(func, 9);
274258ebd649SToby Isaac     *func = b->func;
274358ebd649SToby Isaac   }
274458ebd649SToby Isaac   if (numids) {
274558ebd649SToby Isaac     PetscValidPointer(numids, 10);
274658ebd649SToby Isaac     *numids = b->numids;
274758ebd649SToby Isaac   }
274858ebd649SToby Isaac   if (ids) {
274958ebd649SToby Isaac     PetscValidPointer(ids, 11);
275058ebd649SToby Isaac     *ids = b->ids;
275158ebd649SToby Isaac   }
275258ebd649SToby Isaac   if (ctx) {
275358ebd649SToby Isaac     PetscValidPointer(ctx, 12);
275458ebd649SToby Isaac     *ctx = b->ctx;
275558ebd649SToby Isaac   }
275658ebd649SToby Isaac   PetscFunctionReturn(0);
275758ebd649SToby Isaac }
275858ebd649SToby Isaac 
275958ebd649SToby Isaac #undef __FUNCT__
2760dff059c6SToby Isaac #define __FUNCT__ "PetscDSCopyBoundary"
2761dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB)
2762dff059c6SToby Isaac {
2763dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
2764dff059c6SToby Isaac   PetscErrorCode ierr;
2765dff059c6SToby Isaac 
2766dff059c6SToby Isaac   PetscFunctionBegin;
2767dff059c6SToby Isaac   PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1);
2768dff059c6SToby Isaac   PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2);
2769dff059c6SToby Isaac   if (probA == probB) PetscFunctionReturn(0);
2770dff059c6SToby Isaac   next = probB->boundary;
2771dff059c6SToby Isaac   while (next) {
2772dff059c6SToby Isaac     DSBoundary b = next;
2773dff059c6SToby Isaac 
2774dff059c6SToby Isaac     next = b->next;
2775dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2776dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2777dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
2778dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2779dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
2780dff059c6SToby Isaac   }
2781dff059c6SToby Isaac   lastnext = &(probB->boundary);
2782dff059c6SToby Isaac   for (b = probA->boundary; b; b = b->next) {
2783dff059c6SToby Isaac     DSBoundary bNew;
2784dff059c6SToby Isaac 
2785dff059c6SToby Isaac     ierr = PetscNew(&bNew);
2786dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
2787dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
2788dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr);
2789dff059c6SToby Isaac     bNew->numids = b->numids;
2790dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
2791dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr);
2792dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
2793dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
2794dff059c6SToby Isaac     bNew->ctx       = b->ctx;
2795dff059c6SToby Isaac     bNew->essential = b->essential;
2796dff059c6SToby Isaac     bNew->field     = b->field;
2797dff059c6SToby Isaac     bNew->func      = b->func;
2798dff059c6SToby Isaac 
2799dff059c6SToby Isaac     *lastnext = bNew;
2800dff059c6SToby Isaac     lastnext = &(bNew->next);
2801dff059c6SToby Isaac   }
2802dff059c6SToby Isaac   PetscFunctionReturn(0);
2803dff059c6SToby Isaac }
2804dff059c6SToby Isaac 
2805dff059c6SToby Isaac #undef __FUNCT__
2806da51fcedSMatthew G. Knepley #define __FUNCT__ "PetscDSCopyEquations"
2807da51fcedSMatthew G. Knepley /*@
2808da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
2809da51fcedSMatthew G. Knepley 
2810da51fcedSMatthew G. Knepley   Not collective
2811da51fcedSMatthew G. Knepley 
2812da51fcedSMatthew G. Knepley   Input Parameter:
2813da51fcedSMatthew G. Knepley . prob - The PetscDS object
2814da51fcedSMatthew G. Knepley 
2815da51fcedSMatthew G. Knepley   Output Parameter:
2816da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
2817da51fcedSMatthew G. Knepley 
2818da51fcedSMatthew G. Knepley   Level: intermediate
2819da51fcedSMatthew G. Knepley 
2820da51fcedSMatthew G. Knepley .seealso: PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
2821da51fcedSMatthew G. Knepley @*/
2822da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
2823da51fcedSMatthew G. Knepley {
2824da51fcedSMatthew G. Knepley   PetscInt       Nf, Ng, f, g;
2825da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
2826da51fcedSMatthew G. Knepley 
2827da51fcedSMatthew G. Knepley   PetscFunctionBegin;
2828da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2829da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
2830da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
2831da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
2832da51fcedSMatthew G. Knepley   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);CHKERRQ(ierr);
2833da51fcedSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
2834da51fcedSMatthew G. Knepley     PetscPointFunc   obj;
2835da51fcedSMatthew G. Knepley     PetscPointFunc   f0, f1;
2836da51fcedSMatthew G. Knepley     PetscPointJac    g0, g1, g2, g3;
2837da51fcedSMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
2838da51fcedSMatthew G. Knepley     PetscBdPointJac  g0Bd, g1Bd, g2Bd, g3Bd;
2839da51fcedSMatthew G. Knepley     PetscRiemannFunc r;
2840da51fcedSMatthew G. Knepley 
2841da51fcedSMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
2842da51fcedSMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
2843da51fcedSMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
2844da51fcedSMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
2845da51fcedSMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, f, obj);CHKERRQ(ierr);
2846da51fcedSMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, f, f0, f1);CHKERRQ(ierr);
2847da51fcedSMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, f, f0Bd, f1Bd);CHKERRQ(ierr);
2848da51fcedSMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, f, r);CHKERRQ(ierr);
2849da51fcedSMatthew G. Knepley     for (g = 0; g < Nf; ++g) {
2850da51fcedSMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
2851da51fcedSMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
2852da51fcedSMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, f, g, g0, g1, g2, g3);CHKERRQ(ierr);
2853da51fcedSMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, f, g, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
2854da51fcedSMatthew G. Knepley     }
2855da51fcedSMatthew G. Knepley   }
2856da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
2857da51fcedSMatthew G. Knepley }
2858da51fcedSMatthew G. Knepley 
2859da51fcedSMatthew G. Knepley #undef __FUNCT__
28602764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroy_Basic"
2861bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob)
28622764a2aaSMatthew G. Knepley {
2863931fb3b8SToby Isaac   PetscErrorCode      ierr;
2864931fb3b8SToby Isaac 
28652764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2866931fb3b8SToby Isaac   ierr = PetscFree(prob->data);CHKERRQ(ierr);
28672764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28682764a2aaSMatthew G. Knepley }
28692764a2aaSMatthew G. Knepley 
28702764a2aaSMatthew G. Knepley #undef __FUNCT__
28712764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSInitialize_Basic"
2872bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob)
28732764a2aaSMatthew G. Knepley {
28742764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28752764a2aaSMatthew G. Knepley   prob->ops->setfromoptions = NULL;
28762764a2aaSMatthew G. Knepley   prob->ops->setup          = NULL;
28772764a2aaSMatthew G. Knepley   prob->ops->view           = NULL;
28782764a2aaSMatthew G. Knepley   prob->ops->destroy        = PetscDSDestroy_Basic;
28792764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28802764a2aaSMatthew G. Knepley }
28812764a2aaSMatthew G. Knepley 
28822764a2aaSMatthew G. Knepley /*MC
28832764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
28842764a2aaSMatthew G. Knepley 
28852764a2aaSMatthew G. Knepley   Level: intermediate
28862764a2aaSMatthew G. Knepley 
28872764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
28882764a2aaSMatthew G. Knepley M*/
28892764a2aaSMatthew G. Knepley 
28902764a2aaSMatthew G. Knepley #undef __FUNCT__
28912764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSCreate_Basic"
28922764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob)
28932764a2aaSMatthew G. Knepley {
28942764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
28952764a2aaSMatthew G. Knepley   PetscErrorCode      ierr;
28962764a2aaSMatthew G. Knepley 
28972764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2898931fb3b8SToby Isaac   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28992764a2aaSMatthew G. Knepley   ierr       = PetscNewLog(prob, &b);CHKERRQ(ierr);
29002764a2aaSMatthew G. Knepley   prob->data = b;
29012764a2aaSMatthew G. Knepley 
29022764a2aaSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr);
29032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29042764a2aaSMatthew G. Knepley }
2905