xref: /petsc/src/dm/dt/interface/dtds.c (revision 47e5711078941341a23f7a2285d5d0fac76940ae)
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;
304*47e57110SSander 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);
3062764a2aaSMatthew G. Knepley   ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisBd,Nf,&prob->basisDerBd);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);
3239de99aefSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
3249de99aefSMatthew G. Knepley       PetscFV fv = (PetscFV) obj;
3259de99aefSMatthew G. Knepley 
3269de99aefSMatthew G. Knepley       ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
3279de99aefSMatthew G. Knepley       Nb   = 1;
3289de99aefSMatthew G. Knepley       ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
3296c1a3d01SMatthew G. Knepley       ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
330abac5ca0SMatthew G. Knepley     } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
331*47e57110SSander Arens     prob->Nc[f]       = Nc;
332*47e57110SSander Arens     prob->Nb[f]       = Nb;
333194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
334194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
3359de99aefSMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
3362764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
3372764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
3382764a2aaSMatthew G. Knepley     prob->totDim  += Nb*Nc;
3392764a2aaSMatthew G. Knepley     prob->totComp += Nc;
3402764a2aaSMatthew G. Knepley     if (feBd) {
3412764a2aaSMatthew G. Knepley       ierr = PetscFEGetDimension(feBd, &Nb);CHKERRQ(ierr);
3422764a2aaSMatthew G. Knepley       ierr = PetscFEGetNumComponents(feBd, &Nc);CHKERRQ(ierr);
3432764a2aaSMatthew G. Knepley       ierr = PetscFEGetDefaultTabulation(feBd, &prob->basisBd[f], &prob->basisDerBd[f], NULL);CHKERRQ(ierr);
3442764a2aaSMatthew G. Knepley       prob->totDimBd += Nb*Nc;
345194d53e6SMatthew G. Knepley       prob->offBd[f+1]    = Nc     + prob->offBd[f];
346194d53e6SMatthew G. Knepley       prob->offDerBd[f+1] = Nc*dim + prob->offDerBd[f];
3472764a2aaSMatthew G. Knepley     }
3482764a2aaSMatthew G. Knepley   }
3492764a2aaSMatthew G. Knepley   work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim));
3502764a2aaSMatthew G. Knepley   /* Allocate works space */
3512764a2aaSMatthew 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);
3522764a2aaSMatthew 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);
3532764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
3542764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
3552764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3562764a2aaSMatthew G. Knepley }
3572764a2aaSMatthew G. Knepley 
3582764a2aaSMatthew G. Knepley #undef __FUNCT__
3592764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroyStructs_Static"
3602764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
3612764a2aaSMatthew G. Knepley {
3622764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3632764a2aaSMatthew G. Knepley 
3642764a2aaSMatthew G. Knepley   PetscFunctionBegin;
365*47e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
366194d53e6SMatthew G. Knepley   ierr = PetscFree4(prob->off,prob->offDer,prob->offBd,prob->offDerBd);CHKERRQ(ierr);
3672764a2aaSMatthew G. Knepley   ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisBd,prob->basisDerBd);CHKERRQ(ierr);
3682764a2aaSMatthew G. Knepley   ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr);
3692764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
3702764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3712764a2aaSMatthew G. Knepley }
3722764a2aaSMatthew G. Knepley 
3732764a2aaSMatthew G. Knepley #undef __FUNCT__
3742764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSEnlarge_Static"
3752764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
3762764a2aaSMatthew G. Knepley {
3772764a2aaSMatthew G. Knepley   PetscObject      *tmpd, *tmpdbd;
378a6cbbb48SMatthew G. Knepley   PetscBool        *tmpi, *tmpa;
3792aa1fc23SMatthew G. Knepley   PetscPointFunc   *tmpobj, *tmpf;
380b7e05686SMatthew G. Knepley   PetscPointJac    *tmpg, *tmpgp, *tmpgt;
3812aa1fc23SMatthew G. Knepley   PetscBdPointFunc *tmpfbd;
3822aa1fc23SMatthew G. Knepley   PetscBdPointJac  *tmpgbd;
383194d53e6SMatthew G. Knepley   PetscRiemannFunc *tmpr;
3840c2f2876SMatthew G. Knepley   void            **tmpctx;
385a6cbbb48SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f, i;
3862764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
3872764a2aaSMatthew G. Knepley 
3882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3892764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
3902764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
3912764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
392a6cbbb48SMatthew G. Knepley   ierr = PetscMalloc4(NfNew, &tmpd, NfNew, &tmpdbd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr);
393a6cbbb48SMatthew 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];}
39454f1004bSSander 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;}
395a6cbbb48SMatthew G. Knepley   ierr = PetscFree4(prob->disc, prob->discBd, prob->implicit, prob->adjacency);CHKERRQ(ierr);
3962764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
3972764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
398a6cbbb48SMatthew G. Knepley   prob->discBd    = tmpdbd;
399249df284SMatthew G. Knepley   prob->implicit  = tmpi;
400a6cbbb48SMatthew G. Knepley   prob->adjacency = tmpa;
401b7e05686SMatthew 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);
4022764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f];
4032764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f];
4042764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f];
405475e0ac9SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f];
4060c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f];
4070c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
4082764a2aaSMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL;
4092764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL;
4102764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL;
411475e0ac9SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL;
412b7e05686SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL;
4130c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL;
4140c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
415b7e05686SMatthew G. Knepley   ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr);
4162764a2aaSMatthew G. Knepley   prob->obj = tmpobj;
4172764a2aaSMatthew G. Knepley   prob->f   = tmpf;
4182764a2aaSMatthew G. Knepley   prob->g   = tmpg;
419475e0ac9SMatthew G. Knepley   prob->gp  = tmpgp;
420b7e05686SMatthew G. Knepley   prob->gt  = tmpgt;
4210c2f2876SMatthew G. Knepley   prob->r   = tmpr;
4220c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
4232764a2aaSMatthew G. Knepley   ierr = PetscCalloc2(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd);CHKERRQ(ierr);
4242764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f];
4252764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f];
4262764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL;
4272764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL;
4282764a2aaSMatthew G. Knepley   ierr = PetscFree2(prob->fBd, prob->gBd);CHKERRQ(ierr);
4292764a2aaSMatthew G. Knepley   prob->fBd = tmpfbd;
4302764a2aaSMatthew G. Knepley   prob->gBd = tmpgbd;
4312764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4322764a2aaSMatthew G. Knepley }
4332764a2aaSMatthew G. Knepley 
4342764a2aaSMatthew G. Knepley #undef __FUNCT__
4352764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroy"
4362764a2aaSMatthew G. Knepley /*@
4372764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
4382764a2aaSMatthew G. Knepley 
4392764a2aaSMatthew G. Knepley   Collective on PetscDS
4402764a2aaSMatthew G. Knepley 
4412764a2aaSMatthew G. Knepley   Input Parameter:
4422764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
4432764a2aaSMatthew G. Knepley 
4442764a2aaSMatthew G. Knepley   Level: developer
4452764a2aaSMatthew G. Knepley 
4462764a2aaSMatthew G. Knepley .seealso PetscDSView()
4472764a2aaSMatthew G. Knepley @*/
4482764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob)
4492764a2aaSMatthew G. Knepley {
4502764a2aaSMatthew G. Knepley   PetscInt       f;
45158ebd649SToby Isaac   DSBoundary     next;
4522764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4532764a2aaSMatthew G. Knepley 
4542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4552764a2aaSMatthew G. Knepley   if (!*prob) PetscFunctionReturn(0);
4562764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1);
4572764a2aaSMatthew G. Knepley 
4582764a2aaSMatthew G. Knepley   if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);}
4592764a2aaSMatthew G. Knepley   ((PetscObject) (*prob))->refct = 0;
4602764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr);
4612764a2aaSMatthew G. Knepley   for (f = 0; f < (*prob)->Nf; ++f) {
4622764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr);
4632764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->discBd[f]);CHKERRQ(ierr);
4642764a2aaSMatthew G. Knepley   }
465a6cbbb48SMatthew G. Knepley   ierr = PetscFree4((*prob)->disc, (*prob)->discBd, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr);
466b7e05686SMatthew G. Knepley   ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr);
4672764a2aaSMatthew G. Knepley   ierr = PetscFree2((*prob)->fBd,(*prob)->gBd);CHKERRQ(ierr);
4682764a2aaSMatthew G. Knepley   if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);}
46958ebd649SToby Isaac   next = (*prob)->boundary;
47058ebd649SToby Isaac   while (next) {
47158ebd649SToby Isaac     DSBoundary b = next;
47258ebd649SToby Isaac 
47358ebd649SToby Isaac     next = b->next;
47458ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
47558ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
47658ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
47758ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
47858ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
47958ebd649SToby Isaac   }
4802764a2aaSMatthew G. Knepley   ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr);
4812764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4822764a2aaSMatthew G. Knepley }
4832764a2aaSMatthew G. Knepley 
4842764a2aaSMatthew G. Knepley #undef __FUNCT__
4852764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSCreate"
4862764a2aaSMatthew G. Knepley /*@
4872764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
4882764a2aaSMatthew G. Knepley 
4892764a2aaSMatthew G. Knepley   Collective on MPI_Comm
4902764a2aaSMatthew G. Knepley 
4912764a2aaSMatthew G. Knepley   Input Parameter:
4922764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
4932764a2aaSMatthew G. Knepley 
4942764a2aaSMatthew G. Knepley   Output Parameter:
4952764a2aaSMatthew G. Knepley . prob - The PetscDS object
4962764a2aaSMatthew G. Knepley 
4972764a2aaSMatthew G. Knepley   Level: beginner
4982764a2aaSMatthew G. Knepley 
4992764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
5002764a2aaSMatthew G. Knepley @*/
5012764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob)
5022764a2aaSMatthew G. Knepley {
5032764a2aaSMatthew G. Knepley   PetscDS   p;
5042764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5052764a2aaSMatthew G. Knepley 
5062764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5072764a2aaSMatthew G. Knepley   PetscValidPointer(prob, 2);
5082764a2aaSMatthew G. Knepley   *prob  = NULL;
5092764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5102764a2aaSMatthew G. Knepley 
51173107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5122764a2aaSMatthew G. Knepley 
5132764a2aaSMatthew G. Knepley   p->Nf    = 0;
5142764a2aaSMatthew G. Knepley   p->setup = PETSC_FALSE;
5152764a2aaSMatthew G. Knepley 
5162764a2aaSMatthew G. Knepley   *prob = p;
5172764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5182764a2aaSMatthew G. Knepley }
5192764a2aaSMatthew G. Knepley 
5202764a2aaSMatthew G. Knepley #undef __FUNCT__
5212764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetNumFields"
522bc4ae4beSMatthew G. Knepley /*@
523bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
524bc4ae4beSMatthew G. Knepley 
525bc4ae4beSMatthew G. Knepley   Not collective
526bc4ae4beSMatthew G. Knepley 
527bc4ae4beSMatthew G. Knepley   Input Parameter:
528bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
529bc4ae4beSMatthew G. Knepley 
530bc4ae4beSMatthew G. Knepley   Output Parameter:
531bc4ae4beSMatthew G. Knepley . Nf - The number of fields
532bc4ae4beSMatthew G. Knepley 
533bc4ae4beSMatthew G. Knepley   Level: beginner
534bc4ae4beSMatthew G. Knepley 
535bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
536bc4ae4beSMatthew G. Knepley @*/
5372764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
5382764a2aaSMatthew G. Knepley {
5392764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5402764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5412764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
5422764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
5432764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5442764a2aaSMatthew G. Knepley }
5452764a2aaSMatthew G. Knepley 
5462764a2aaSMatthew G. Knepley #undef __FUNCT__
5472764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetSpatialDimension"
548bc4ae4beSMatthew G. Knepley /*@
549bc4ae4beSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS
550bc4ae4beSMatthew G. Knepley 
551bc4ae4beSMatthew G. Knepley   Not collective
552bc4ae4beSMatthew G. Knepley 
553bc4ae4beSMatthew G. Knepley   Input Parameter:
554bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
555bc4ae4beSMatthew G. Knepley 
556bc4ae4beSMatthew G. Knepley   Output Parameter:
557bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
558bc4ae4beSMatthew G. Knepley 
559bc4ae4beSMatthew G. Knepley   Level: beginner
560bc4ae4beSMatthew G. Knepley 
561bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
562bc4ae4beSMatthew G. Knepley @*/
5632764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
5642764a2aaSMatthew G. Knepley {
5652764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5662764a2aaSMatthew G. Knepley 
5672764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5682764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5692764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
5702764a2aaSMatthew G. Knepley   *dim = 0;
5719de99aefSMatthew G. Knepley   if (prob->Nf) {
5729de99aefSMatthew G. Knepley     PetscObject  obj;
5739de99aefSMatthew G. Knepley     PetscClassId id;
5749de99aefSMatthew G. Knepley 
5759de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
5769de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
5779de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
5789de99aefSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
5799de99aefSMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
5809de99aefSMatthew G. Knepley   }
5812764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5822764a2aaSMatthew G. Knepley }
5832764a2aaSMatthew G. Knepley 
5842764a2aaSMatthew G. Knepley #undef __FUNCT__
5852764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalDimension"
586bc4ae4beSMatthew G. Knepley /*@
587bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
588bc4ae4beSMatthew G. Knepley 
589bc4ae4beSMatthew G. Knepley   Not collective
590bc4ae4beSMatthew G. Knepley 
591bc4ae4beSMatthew G. Knepley   Input Parameter:
592bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
593bc4ae4beSMatthew G. Knepley 
594bc4ae4beSMatthew G. Knepley   Output Parameter:
595bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
596bc4ae4beSMatthew G. Knepley 
597bc4ae4beSMatthew G. Knepley   Level: beginner
598bc4ae4beSMatthew G. Knepley 
599bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
600bc4ae4beSMatthew G. Knepley @*/
6012764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
6022764a2aaSMatthew G. Knepley {
6032764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6042764a2aaSMatthew G. Knepley 
6052764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6062764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6072764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6082764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6092764a2aaSMatthew G. Knepley   *dim = prob->totDim;
6102764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6112764a2aaSMatthew G. Knepley }
6122764a2aaSMatthew G. Knepley 
6132764a2aaSMatthew G. Knepley #undef __FUNCT__
6142764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalBdDimension"
615bc4ae4beSMatthew G. Knepley /*@
616c3ac4435SMatthew G. Knepley   PetscDSGetTotalBdDimension - Returns the total size of the boundary approximation space for this system
617bc4ae4beSMatthew G. Knepley 
618bc4ae4beSMatthew G. Knepley   Not collective
619bc4ae4beSMatthew G. Knepley 
620bc4ae4beSMatthew G. Knepley   Input Parameter:
621bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
622bc4ae4beSMatthew G. Knepley 
623bc4ae4beSMatthew G. Knepley   Output Parameter:
624bc4ae4beSMatthew G. Knepley . dim - The total boundary problem dimension
625bc4ae4beSMatthew G. Knepley 
626bc4ae4beSMatthew G. Knepley   Level: beginner
627bc4ae4beSMatthew G. Knepley 
628bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
629bc4ae4beSMatthew G. Knepley @*/
6302764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalBdDimension(PetscDS prob, PetscInt *dim)
6312764a2aaSMatthew G. Knepley {
6322764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6332764a2aaSMatthew G. Knepley 
6342764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6352764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6362764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6372764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6382764a2aaSMatthew G. Knepley   *dim = prob->totDimBd;
6392764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6402764a2aaSMatthew G. Knepley }
6412764a2aaSMatthew G. Knepley 
6422764a2aaSMatthew G. Knepley #undef __FUNCT__
6432764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalComponents"
644bc4ae4beSMatthew G. Knepley /*@
645bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
646bc4ae4beSMatthew G. Knepley 
647bc4ae4beSMatthew G. Knepley   Not collective
648bc4ae4beSMatthew G. Knepley 
649bc4ae4beSMatthew G. Knepley   Input Parameter:
650bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
651bc4ae4beSMatthew G. Knepley 
652bc4ae4beSMatthew G. Knepley   Output Parameter:
653bc4ae4beSMatthew G. Knepley . dim - The total number of components
654bc4ae4beSMatthew G. Knepley 
655bc4ae4beSMatthew G. Knepley   Level: beginner
656bc4ae4beSMatthew G. Knepley 
657bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
658bc4ae4beSMatthew G. Knepley @*/
6592764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
6602764a2aaSMatthew G. Knepley {
6612764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6622764a2aaSMatthew G. Knepley 
6632764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6642764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6652764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6662764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
6672764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
6682764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6692764a2aaSMatthew G. Knepley }
6702764a2aaSMatthew G. Knepley 
6712764a2aaSMatthew G. Knepley #undef __FUNCT__
6722764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetDiscretization"
673bc4ae4beSMatthew G. Knepley /*@
674bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
675bc4ae4beSMatthew G. Knepley 
676bc4ae4beSMatthew G. Knepley   Not collective
677bc4ae4beSMatthew G. Knepley 
678bc4ae4beSMatthew G. Knepley   Input Parameters:
679bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
680bc4ae4beSMatthew G. Knepley - f - The field number
681bc4ae4beSMatthew G. Knepley 
682bc4ae4beSMatthew G. Knepley   Output Parameter:
683bc4ae4beSMatthew G. Knepley . disc - The discretization object
684bc4ae4beSMatthew G. Knepley 
685bc4ae4beSMatthew G. Knepley   Level: beginner
686bc4ae4beSMatthew G. Knepley 
687bc4ae4beSMatthew G. Knepley .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
688bc4ae4beSMatthew G. Knepley @*/
6892764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
6902764a2aaSMatthew G. Knepley {
6912764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6922764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6932764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
6942764a2aaSMatthew 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);
6952764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
6962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6972764a2aaSMatthew G. Knepley }
6982764a2aaSMatthew G. Knepley 
6992764a2aaSMatthew G. Knepley #undef __FUNCT__
7002764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdDiscretization"
701bc4ae4beSMatthew G. Knepley /*@
702bc4ae4beSMatthew G. Knepley   PetscDSGetBdDiscretization - Returns the boundary discretization object for the given field
703bc4ae4beSMatthew G. Knepley 
704bc4ae4beSMatthew G. Knepley   Not collective
705bc4ae4beSMatthew G. Knepley 
706bc4ae4beSMatthew G. Knepley   Input Parameters:
707bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
708bc4ae4beSMatthew G. Knepley - f - The field number
709bc4ae4beSMatthew G. Knepley 
710bc4ae4beSMatthew G. Knepley   Output Parameter:
711bc4ae4beSMatthew G. Knepley . disc - The boundary discretization object
712bc4ae4beSMatthew G. Knepley 
713bc4ae4beSMatthew G. Knepley   Level: beginner
714bc4ae4beSMatthew G. Knepley 
715bc4ae4beSMatthew G. Knepley .seealso: PetscDSSetBdDiscretization(), PetscDSAddBdDiscretization(), PetscDSGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
716bc4ae4beSMatthew G. Knepley @*/
7172764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
7182764a2aaSMatthew G. Knepley {
7192764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7202764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7212764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
7222764a2aaSMatthew 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);
7232764a2aaSMatthew G. Knepley   *disc = prob->discBd[f];
7242764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7252764a2aaSMatthew G. Knepley }
7262764a2aaSMatthew G. Knepley 
7272764a2aaSMatthew G. Knepley #undef __FUNCT__
7282764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetDiscretization"
729bc4ae4beSMatthew G. Knepley /*@
730bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
731bc4ae4beSMatthew G. Knepley 
732bc4ae4beSMatthew G. Knepley   Not collective
733bc4ae4beSMatthew G. Knepley 
734bc4ae4beSMatthew G. Knepley   Input Parameters:
735bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
736bc4ae4beSMatthew G. Knepley . f - The field number
737bc4ae4beSMatthew G. Knepley - disc - The discretization object
738bc4ae4beSMatthew G. Knepley 
739bc4ae4beSMatthew G. Knepley   Level: beginner
740bc4ae4beSMatthew G. Knepley 
741bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
742bc4ae4beSMatthew G. Knepley @*/
7432764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
7442764a2aaSMatthew G. Knepley {
7452764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7462764a2aaSMatthew G. Knepley 
7472764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7482764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7492764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
7502764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
7512764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
7522764a2aaSMatthew G. Knepley   if (prob->disc[f]) {ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);}
7532764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
7542764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
755249df284SMatthew G. Knepley   {
756249df284SMatthew G. Knepley     PetscClassId id;
757249df284SMatthew G. Knepley 
758249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
759a6cbbb48SMatthew G. Knepley     if (id == PETSCFV_CLASSID) {
760a6cbbb48SMatthew G. Knepley       prob->implicit[f]      = PETSC_FALSE;
761a6cbbb48SMatthew G. Knepley       prob->adjacency[f*2+0] = PETSC_TRUE;
762a6cbbb48SMatthew G. Knepley       prob->adjacency[f*2+1] = PETSC_FALSE;
763a6cbbb48SMatthew G. Knepley     }
764249df284SMatthew G. Knepley   }
7652764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7662764a2aaSMatthew G. Knepley }
7672764a2aaSMatthew G. Knepley 
7682764a2aaSMatthew G. Knepley #undef __FUNCT__
7692764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdDiscretization"
770bc4ae4beSMatthew G. Knepley /*@
771bc4ae4beSMatthew G. Knepley   PetscDSSetBdDiscretization - Sets the boundary discretization object for the given field
772bc4ae4beSMatthew G. Knepley 
773bc4ae4beSMatthew G. Knepley   Not collective
774bc4ae4beSMatthew G. Knepley 
775bc4ae4beSMatthew G. Knepley   Input Parameters:
776bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
777bc4ae4beSMatthew G. Knepley . f - The field number
778bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
779bc4ae4beSMatthew G. Knepley 
780bc4ae4beSMatthew G. Knepley   Level: beginner
781bc4ae4beSMatthew G. Knepley 
782bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetBdDiscretization(), PetscDSAddBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
783bc4ae4beSMatthew G. Knepley @*/
7842764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
7852764a2aaSMatthew G. Knepley {
7862764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7872764a2aaSMatthew G. Knepley 
7882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7902764a2aaSMatthew G. Knepley   if (disc) PetscValidPointer(disc, 3);
7912764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
7922764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
7932764a2aaSMatthew G. Knepley   if (prob->discBd[f]) {ierr = PetscObjectDereference(prob->discBd[f]);CHKERRQ(ierr);}
7942764a2aaSMatthew G. Knepley   prob->discBd[f] = disc;
7952764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
7962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7972764a2aaSMatthew G. Knepley }
7982764a2aaSMatthew G. Knepley 
7992764a2aaSMatthew G. Knepley #undef __FUNCT__
8002764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSAddDiscretization"
801bc4ae4beSMatthew G. Knepley /*@
802bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
803bc4ae4beSMatthew G. Knepley 
804bc4ae4beSMatthew G. Knepley   Not collective
805bc4ae4beSMatthew G. Knepley 
806bc4ae4beSMatthew G. Knepley   Input Parameters:
807bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
808bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
809bc4ae4beSMatthew G. Knepley 
810bc4ae4beSMatthew G. Knepley   Level: beginner
811bc4ae4beSMatthew G. Knepley 
812bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
813bc4ae4beSMatthew G. Knepley @*/
8142764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
8152764a2aaSMatthew G. Knepley {
8162764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8172764a2aaSMatthew G. Knepley 
8182764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8192764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
8202764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8212764a2aaSMatthew G. Knepley }
8222764a2aaSMatthew G. Knepley 
8232764a2aaSMatthew G. Knepley #undef __FUNCT__
8242764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSAddBdDiscretization"
825bc4ae4beSMatthew G. Knepley /*@
826bc4ae4beSMatthew G. Knepley   PetscDSAddBdDiscretization - Adds a boundary discretization object
827bc4ae4beSMatthew G. Knepley 
828bc4ae4beSMatthew G. Knepley   Not collective
829bc4ae4beSMatthew G. Knepley 
830bc4ae4beSMatthew G. Knepley   Input Parameters:
831bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
832bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
833bc4ae4beSMatthew G. Knepley 
834bc4ae4beSMatthew G. Knepley   Level: beginner
835bc4ae4beSMatthew G. Knepley 
836bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetBdDiscretization(), PetscDSSetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
837bc4ae4beSMatthew G. Knepley @*/
8382764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddBdDiscretization(PetscDS prob, PetscObject disc)
8392764a2aaSMatthew G. Knepley {
8402764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8412764a2aaSMatthew G. Knepley 
8422764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8432764a2aaSMatthew G. Knepley   ierr = PetscDSSetBdDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
8442764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8452764a2aaSMatthew G. Knepley }
8462764a2aaSMatthew G. Knepley 
8472764a2aaSMatthew G. Knepley #undef __FUNCT__
848249df284SMatthew G. Knepley #define __FUNCT__ "PetscDSGetImplicit"
849249df284SMatthew G. Knepley /*@
850249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
851249df284SMatthew G. Knepley 
852249df284SMatthew G. Knepley   Not collective
853249df284SMatthew G. Knepley 
854249df284SMatthew G. Knepley   Input Parameters:
855249df284SMatthew G. Knepley + prob - The PetscDS object
856249df284SMatthew G. Knepley - f - The field number
857249df284SMatthew G. Knepley 
858249df284SMatthew G. Knepley   Output Parameter:
859249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
860249df284SMatthew G. Knepley 
861249df284SMatthew G. Knepley   Level: developer
862249df284SMatthew G. Knepley 
863249df284SMatthew G. Knepley .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
864249df284SMatthew G. Knepley @*/
865249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
866249df284SMatthew G. Knepley {
867249df284SMatthew G. Knepley   PetscFunctionBegin;
868249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
869249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
870249df284SMatthew 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);
871249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
872249df284SMatthew G. Knepley   PetscFunctionReturn(0);
873249df284SMatthew G. Knepley }
874249df284SMatthew G. Knepley 
875249df284SMatthew G. Knepley #undef __FUNCT__
876249df284SMatthew G. Knepley #define __FUNCT__ "PetscDSSetImplicit"
877249df284SMatthew G. Knepley /*@
878249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
879249df284SMatthew G. Knepley 
880249df284SMatthew G. Knepley   Not collective
881249df284SMatthew G. Knepley 
882249df284SMatthew G. Knepley   Input Parameters:
883249df284SMatthew G. Knepley + prob - The PetscDS object
884249df284SMatthew G. Knepley . f - The field number
885249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
886249df284SMatthew G. Knepley 
887249df284SMatthew G. Knepley   Level: developer
888249df284SMatthew G. Knepley 
889249df284SMatthew G. Knepley .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
890249df284SMatthew G. Knepley @*/
891249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
892249df284SMatthew G. Knepley {
893249df284SMatthew G. Knepley   PetscFunctionBegin;
894249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
895249df284SMatthew 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);
896249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
897249df284SMatthew G. Knepley   PetscFunctionReturn(0);
898249df284SMatthew G. Knepley }
899249df284SMatthew G. Knepley 
900249df284SMatthew G. Knepley #undef __FUNCT__
901a6cbbb48SMatthew G. Knepley #define __FUNCT__ "PetscDSGetAdjacency"
902a6cbbb48SMatthew G. Knepley /*@
903a6cbbb48SMatthew G. Knepley   PetscDSGetAdjacency - Returns the flags for determining variable influence
904a6cbbb48SMatthew G. Knepley 
905a6cbbb48SMatthew G. Knepley   Not collective
906a6cbbb48SMatthew G. Knepley 
907a6cbbb48SMatthew G. Knepley   Input Parameters:
908a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
909a6cbbb48SMatthew G. Knepley - f - The field number
910a6cbbb48SMatthew G. Knepley 
911a6cbbb48SMatthew G. Knepley   Output Parameter:
912a6cbbb48SMatthew G. Knepley + useCone    - Flag for variable influence starting with the cone operation
913a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
914a6cbbb48SMatthew G. Knepley 
915a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
916a6cbbb48SMatthew G. Knepley 
917a6cbbb48SMatthew G. Knepley   Level: developer
918a6cbbb48SMatthew G. Knepley 
919a6cbbb48SMatthew G. Knepley .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
920a6cbbb48SMatthew G. Knepley @*/
921a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure)
922a6cbbb48SMatthew G. Knepley {
923a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
924a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
925a6cbbb48SMatthew G. Knepley   PetscValidPointer(useCone, 3);
926a6cbbb48SMatthew G. Knepley   PetscValidPointer(useClosure, 4);
927a6cbbb48SMatthew 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);
928a6cbbb48SMatthew G. Knepley   *useCone    = prob->adjacency[f*2+0];
929a6cbbb48SMatthew G. Knepley   *useClosure = prob->adjacency[f*2+1];
930a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
931a6cbbb48SMatthew G. Knepley }
932a6cbbb48SMatthew G. Knepley 
933a6cbbb48SMatthew G. Knepley #undef __FUNCT__
934a6cbbb48SMatthew G. Knepley #define __FUNCT__ "PetscDSSetAdjacency"
935a6cbbb48SMatthew G. Knepley /*@
936a6cbbb48SMatthew G. Knepley   PetscDSSetAdjacency - Set the flags for determining variable influence
937a6cbbb48SMatthew G. Knepley 
938a6cbbb48SMatthew G. Knepley   Not collective
939a6cbbb48SMatthew G. Knepley 
940a6cbbb48SMatthew G. Knepley   Input Parameters:
941a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
942a6cbbb48SMatthew G. Knepley . f - The field number
943a6cbbb48SMatthew G. Knepley . useCone    - Flag for variable influence starting with the cone operation
944a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
945a6cbbb48SMatthew G. Knepley 
946a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
947a6cbbb48SMatthew G. Knepley 
948a6cbbb48SMatthew G. Knepley   Level: developer
949a6cbbb48SMatthew G. Knepley 
950a6cbbb48SMatthew G. Knepley .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetBdDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
951a6cbbb48SMatthew G. Knepley @*/
952a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure)
953a6cbbb48SMatthew G. Knepley {
954a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
955a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
956a6cbbb48SMatthew 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);
957a6cbbb48SMatthew G. Knepley   prob->adjacency[f*2+0] = useCone;
958a6cbbb48SMatthew G. Knepley   prob->adjacency[f*2+1] = useClosure;
959a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
960a6cbbb48SMatthew G. Knepley }
961a6cbbb48SMatthew G. Knepley 
962a6cbbb48SMatthew G. Knepley #undef __FUNCT__
9632764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetObjective"
9642764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f,
96530b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
966194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
967194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
96830b9ff8bSMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscScalar obj[]))
9692764a2aaSMatthew G. Knepley {
9702764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9712764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9722764a2aaSMatthew G. Knepley   PetscValidPointer(obj, 2);
9732764a2aaSMatthew 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);
9742764a2aaSMatthew G. Knepley   *obj = prob->obj[f];
9752764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9762764a2aaSMatthew G. Knepley }
9772764a2aaSMatthew G. Knepley 
9782764a2aaSMatthew G. Knepley #undef __FUNCT__
9792764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetObjective"
9802764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f,
98130b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
982194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
983194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
98430b9ff8bSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscScalar obj[]))
9852764a2aaSMatthew G. Knepley {
9862764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9872764a2aaSMatthew G. Knepley 
9882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
990de716cbcSToby Isaac   if (obj) PetscValidFunction(obj, 2);
9912764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
9922764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
9932764a2aaSMatthew G. Knepley   prob->obj[f] = obj;
9942764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9952764a2aaSMatthew G. Knepley }
9962764a2aaSMatthew G. Knepley 
9972764a2aaSMatthew G. Knepley #undef __FUNCT__
9982764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetResidual"
999194d53e6SMatthew G. Knepley /*@C
1000194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
1001194d53e6SMatthew G. Knepley 
1002194d53e6SMatthew G. Knepley   Not collective
1003194d53e6SMatthew G. Knepley 
1004194d53e6SMatthew G. Knepley   Input Parameters:
1005194d53e6SMatthew G. Knepley + prob - The PetscDS
1006194d53e6SMatthew G. Knepley - f    - The test field number
1007194d53e6SMatthew G. Knepley 
1008194d53e6SMatthew G. Knepley   Output Parameters:
1009194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
1010194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1011194d53e6SMatthew G. Knepley 
1012194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1013194d53e6SMatthew G. Knepley 
1014194d53e6SMatthew 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)
1015194d53e6SMatthew G. Knepley 
1016194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1017194d53e6SMatthew G. Knepley 
101830b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1019194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1020194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
102130b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1022194d53e6SMatthew G. Knepley 
1023194d53e6SMatthew G. Knepley + dim - the spatial dimension
1024194d53e6SMatthew G. Knepley . Nf - the number of fields
1025194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1026194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1027194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1028194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1029194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1030194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1031194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1032194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1033194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1034194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1035194d53e6SMatthew G. Knepley . t - current time
1036194d53e6SMatthew G. Knepley . x - coordinates of the current point
1037194d53e6SMatthew G. Knepley - f0 - output values at the current point
1038194d53e6SMatthew G. Knepley 
1039194d53e6SMatthew G. Knepley   Level: intermediate
1040194d53e6SMatthew G. Knepley 
1041194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
1042194d53e6SMatthew G. Knepley @*/
10432764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f,
104430b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1045194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1046194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
104730b9ff8bSMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscScalar f0[]),
104830b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1049194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1050194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
105130b9ff8bSMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscScalar f1[]))
10522764a2aaSMatthew G. Knepley {
10532764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10542764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10552764a2aaSMatthew 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);
10562764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];}
10572764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];}
10582764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10592764a2aaSMatthew G. Knepley }
10602764a2aaSMatthew G. Knepley 
10612764a2aaSMatthew G. Knepley #undef __FUNCT__
10622764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetResidual"
1063194d53e6SMatthew G. Knepley /*@C
1064194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
1065194d53e6SMatthew G. Knepley 
1066194d53e6SMatthew G. Knepley   Not collective
1067194d53e6SMatthew G. Knepley 
1068194d53e6SMatthew G. Knepley   Input Parameters:
1069194d53e6SMatthew G. Knepley + prob - The PetscDS
1070194d53e6SMatthew G. Knepley . f    - The test field number
1071194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1072194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1073194d53e6SMatthew G. Knepley 
1074194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1075194d53e6SMatthew G. Knepley 
1076194d53e6SMatthew 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)
1077194d53e6SMatthew G. Knepley 
1078194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1079194d53e6SMatthew G. Knepley 
108030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1081194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1082194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
108330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1084194d53e6SMatthew G. Knepley 
1085194d53e6SMatthew G. Knepley + dim - the spatial dimension
1086194d53e6SMatthew G. Knepley . Nf - the number of fields
1087194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1088194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1089194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1090194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1091194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1092194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1093194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1094194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1095194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1096194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1097194d53e6SMatthew G. Knepley . t - current time
1098194d53e6SMatthew G. Knepley . x - coordinates of the current point
1099194d53e6SMatthew G. Knepley - f0 - output values at the current point
1100194d53e6SMatthew G. Knepley 
1101194d53e6SMatthew G. Knepley   Level: intermediate
1102194d53e6SMatthew G. Knepley 
1103194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1104194d53e6SMatthew G. Knepley @*/
11052764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f,
110630b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1107194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1108194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
110930b9ff8bSMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscScalar f0[]),
111030b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1111194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1112194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
111330b9ff8bSMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscScalar f1[]))
11142764a2aaSMatthew G. Knepley {
11152764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
11162764a2aaSMatthew G. Knepley 
11172764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11182764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1119f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1120f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
11212764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
11222764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
11232764a2aaSMatthew G. Knepley   prob->f[f*2+0] = f0;
11242764a2aaSMatthew G. Knepley   prob->f[f*2+1] = f1;
11252764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11262764a2aaSMatthew G. Knepley }
11272764a2aaSMatthew G. Knepley 
11282764a2aaSMatthew G. Knepley #undef __FUNCT__
11293e75805dSMatthew G. Knepley #define __FUNCT__ "PetscDSHasJacobian"
11303e75805dSMatthew G. Knepley /*@C
11313e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
11323e75805dSMatthew G. Knepley 
11333e75805dSMatthew G. Knepley   Not collective
11343e75805dSMatthew G. Knepley 
11353e75805dSMatthew G. Knepley   Input Parameter:
11363e75805dSMatthew G. Knepley . prob - The PetscDS
11373e75805dSMatthew G. Knepley 
11383e75805dSMatthew G. Knepley   Output Parameter:
11393e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
11403e75805dSMatthew G. Knepley 
11413e75805dSMatthew G. Knepley   Level: intermediate
11423e75805dSMatthew G. Knepley 
11433e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
11443e75805dSMatthew G. Knepley @*/
11453e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac)
11463e75805dSMatthew G. Knepley {
11473e75805dSMatthew G. Knepley   PetscInt f, g, h;
11483e75805dSMatthew G. Knepley 
11493e75805dSMatthew G. Knepley   PetscFunctionBegin;
11503e75805dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11513e75805dSMatthew G. Knepley   *hasJac = PETSC_FALSE;
11523e75805dSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
11533e75805dSMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
11543e75805dSMatthew G. Knepley       for (h = 0; h < 4; ++h) {
11553e75805dSMatthew G. Knepley         if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE;
11563e75805dSMatthew G. Knepley       }
11573e75805dSMatthew G. Knepley     }
11583e75805dSMatthew G. Knepley   }
11593e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
11603e75805dSMatthew G. Knepley }
11613e75805dSMatthew G. Knepley 
11623e75805dSMatthew G. Knepley #undef __FUNCT__
11632764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetJacobian"
1164194d53e6SMatthew G. Knepley /*@C
1165194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1166194d53e6SMatthew G. Knepley 
1167194d53e6SMatthew G. Knepley   Not collective
1168194d53e6SMatthew G. Knepley 
1169194d53e6SMatthew G. Knepley   Input Parameters:
1170194d53e6SMatthew G. Knepley + prob - The PetscDS
1171194d53e6SMatthew G. Knepley . f    - The test field number
1172194d53e6SMatthew G. Knepley - g    - The field number
1173194d53e6SMatthew G. Knepley 
1174194d53e6SMatthew G. Knepley   Output Parameters:
1175194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1176194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1177194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1178194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1179194d53e6SMatthew G. Knepley 
1180194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1181194d53e6SMatthew G. Knepley 
1182194d53e6SMatthew 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
1183194d53e6SMatthew G. Knepley 
1184194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1185194d53e6SMatthew G. Knepley 
118630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1187194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1188194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
118930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1190194d53e6SMatthew G. Knepley 
1191194d53e6SMatthew G. Knepley + dim - the spatial dimension
1192194d53e6SMatthew G. Knepley . Nf - the number of fields
1193194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1194194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1195194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1196194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1197194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1198194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1199194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1200194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1201194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1202194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1203194d53e6SMatthew G. Knepley . t - current time
12042aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1205194d53e6SMatthew G. Knepley . x - coordinates of the current point
1206194d53e6SMatthew G. Knepley - g0 - output values at the current point
1207194d53e6SMatthew G. Knepley 
1208194d53e6SMatthew G. Knepley   Level: intermediate
1209194d53e6SMatthew G. Knepley 
1210194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1211194d53e6SMatthew G. Knepley @*/
12122764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g,
121330b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1214194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1215194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
12162aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
121730b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1218194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1219194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
12202aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
122130b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1222194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1223194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
12242aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
122530b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1226194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1227194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
12282aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
12292764a2aaSMatthew G. Knepley {
12302764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12312764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
12322764a2aaSMatthew 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);
12332764a2aaSMatthew 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);
12342764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];}
12352764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];}
12362764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];}
12372764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];}
12382764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12392764a2aaSMatthew G. Knepley }
12402764a2aaSMatthew G. Knepley 
12412764a2aaSMatthew G. Knepley #undef __FUNCT__
12422764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetJacobian"
1243194d53e6SMatthew G. Knepley /*@C
1244194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1245194d53e6SMatthew G. Knepley 
1246194d53e6SMatthew G. Knepley   Not collective
1247194d53e6SMatthew G. Knepley 
1248194d53e6SMatthew G. Knepley   Input Parameters:
1249194d53e6SMatthew G. Knepley + prob - The PetscDS
1250194d53e6SMatthew G. Knepley . f    - The test field number
1251194d53e6SMatthew G. Knepley . g    - The field number
1252194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1253194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1254194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1255194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1256194d53e6SMatthew G. Knepley 
1257194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1258194d53e6SMatthew G. Knepley 
1259194d53e6SMatthew 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
1260194d53e6SMatthew G. Knepley 
1261194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1262194d53e6SMatthew G. Knepley 
126330b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1264194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1265194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
126630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1267194d53e6SMatthew G. Knepley 
1268194d53e6SMatthew G. Knepley + dim - the spatial dimension
1269194d53e6SMatthew G. Knepley . Nf - the number of fields
1270194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1271194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1272194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1273194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1274194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1275194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1276194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1277194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1278194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1279194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1280194d53e6SMatthew G. Knepley . t - current time
12812aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1282194d53e6SMatthew G. Knepley . x - coordinates of the current point
1283194d53e6SMatthew G. Knepley - g0 - output values at the current point
1284194d53e6SMatthew G. Knepley 
1285194d53e6SMatthew G. Knepley   Level: intermediate
1286194d53e6SMatthew G. Knepley 
1287194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1288194d53e6SMatthew G. Knepley @*/
12892764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g,
129030b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1291194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1292194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
129330b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
129430b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1295194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1296194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
129730b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
129830b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1299194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1300194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130130b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
130230b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1303194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1304194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
130530b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
13062764a2aaSMatthew G. Knepley {
13072764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
13082764a2aaSMatthew G. Knepley 
13092764a2aaSMatthew G. Knepley   PetscFunctionBegin;
13102764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
13112764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
13122764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
13132764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
13142764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
13152764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
13162764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
13172764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
13182764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+0] = g0;
13192764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+1] = g1;
13202764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+2] = g2;
13212764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+3] = g3;
13222764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
13232764a2aaSMatthew G. Knepley }
13242764a2aaSMatthew G. Knepley 
13252764a2aaSMatthew G. Knepley #undef __FUNCT__
1326475e0ac9SMatthew G. Knepley #define __FUNCT__ "PetscDSHasJacobianPreconditioner"
1327475e0ac9SMatthew G. Knepley /*@C
1328475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1329475e0ac9SMatthew G. Knepley 
1330475e0ac9SMatthew G. Knepley   Not collective
1331475e0ac9SMatthew G. Knepley 
1332475e0ac9SMatthew G. Knepley   Input Parameter:
1333475e0ac9SMatthew G. Knepley . prob - The PetscDS
1334475e0ac9SMatthew G. Knepley 
1335475e0ac9SMatthew G. Knepley   Output Parameter:
1336475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1337475e0ac9SMatthew G. Knepley 
1338475e0ac9SMatthew G. Knepley   Level: intermediate
1339475e0ac9SMatthew G. Knepley 
1340475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1341475e0ac9SMatthew G. Knepley @*/
1342475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre)
1343475e0ac9SMatthew G. Knepley {
1344475e0ac9SMatthew G. Knepley   PetscInt f, g, h;
1345475e0ac9SMatthew G. Knepley 
1346475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1347475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1348475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
1349475e0ac9SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1350475e0ac9SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1351475e0ac9SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1352475e0ac9SMatthew G. Knepley         if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE;
1353475e0ac9SMatthew G. Knepley       }
1354475e0ac9SMatthew G. Knepley     }
1355475e0ac9SMatthew G. Knepley   }
1356475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1357475e0ac9SMatthew G. Knepley }
1358475e0ac9SMatthew G. Knepley 
1359475e0ac9SMatthew G. Knepley #undef __FUNCT__
1360475e0ac9SMatthew G. Knepley #define __FUNCT__ "PetscDSGetJacobianPreconditioner"
1361475e0ac9SMatthew G. Knepley /*@C
1362475e0ac9SMatthew 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.
1363475e0ac9SMatthew G. Knepley 
1364475e0ac9SMatthew G. Knepley   Not collective
1365475e0ac9SMatthew G. Knepley 
1366475e0ac9SMatthew G. Knepley   Input Parameters:
1367475e0ac9SMatthew G. Knepley + prob - The PetscDS
1368475e0ac9SMatthew G. Knepley . f    - The test field number
1369475e0ac9SMatthew G. Knepley - g    - The field number
1370475e0ac9SMatthew G. Knepley 
1371475e0ac9SMatthew G. Knepley   Output Parameters:
1372475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1373475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1374475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1375475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1376475e0ac9SMatthew G. Knepley 
1377475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1378475e0ac9SMatthew G. Knepley 
1379475e0ac9SMatthew 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
1380475e0ac9SMatthew G. Knepley 
1381475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1382475e0ac9SMatthew G. Knepley 
1383475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1384475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1385475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1386475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1387475e0ac9SMatthew G. Knepley 
1388475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1389475e0ac9SMatthew G. Knepley . Nf - the number of fields
1390475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1391475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1392475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1393475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1394475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1395475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1396475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1397475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1398475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1399475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1400475e0ac9SMatthew G. Knepley . t - current time
1401475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1402475e0ac9SMatthew G. Knepley . x - coordinates of the current point
1403475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1404475e0ac9SMatthew G. Knepley 
1405475e0ac9SMatthew G. Knepley   Level: intermediate
1406475e0ac9SMatthew G. Knepley 
1407475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1408475e0ac9SMatthew G. Knepley @*/
1409475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1410475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1411475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1412475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1413475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1414475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1415475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1416475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1417475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1418475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1419475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1420475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1421475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1422475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1423475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1424475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1425475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1426475e0ac9SMatthew G. Knepley {
1427475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1428475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1429475e0ac9SMatthew 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);
1430475e0ac9SMatthew 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);
1431475e0ac9SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];}
1432475e0ac9SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];}
1433475e0ac9SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];}
1434475e0ac9SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];}
1435475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1436475e0ac9SMatthew G. Knepley }
1437475e0ac9SMatthew G. Knepley 
1438475e0ac9SMatthew G. Knepley #undef __FUNCT__
1439475e0ac9SMatthew G. Knepley #define __FUNCT__ "PetscDSSetJacobianPreconditioner"
1440475e0ac9SMatthew G. Knepley /*@C
1441475e0ac9SMatthew 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.
1442475e0ac9SMatthew G. Knepley 
1443475e0ac9SMatthew G. Knepley   Not collective
1444475e0ac9SMatthew G. Knepley 
1445475e0ac9SMatthew G. Knepley   Input Parameters:
1446475e0ac9SMatthew G. Knepley + prob - The PetscDS
1447475e0ac9SMatthew G. Knepley . f    - The test field number
1448475e0ac9SMatthew G. Knepley . g    - The field number
1449475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1450475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1451475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1452475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1453475e0ac9SMatthew G. Knepley 
1454475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1455475e0ac9SMatthew G. Knepley 
1456475e0ac9SMatthew 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
1457475e0ac9SMatthew G. Knepley 
1458475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1459475e0ac9SMatthew G. Knepley 
1460475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1461475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1462475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1463475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1464475e0ac9SMatthew G. Knepley 
1465475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1466475e0ac9SMatthew G. Knepley . Nf - the number of fields
1467475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1468475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1469475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1470475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1471475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1472475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1473475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1474475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1475475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1476475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1477475e0ac9SMatthew G. Knepley . t - current time
1478475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1479475e0ac9SMatthew G. Knepley . x - coordinates of the current point
1480475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1481475e0ac9SMatthew G. Knepley 
1482475e0ac9SMatthew G. Knepley   Level: intermediate
1483475e0ac9SMatthew G. Knepley 
1484475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1485475e0ac9SMatthew G. Knepley @*/
1486475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1487475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1488475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1489475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1490475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1491475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1492475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1493475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1494475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1495475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1496475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1497475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1498475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1499475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1500475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1501475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1502475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1503475e0ac9SMatthew G. Knepley {
1504475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1505475e0ac9SMatthew G. Knepley 
1506475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1507475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1508475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1509475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1510475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1511475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1512475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1513475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1514475e0ac9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1515475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+0] = g0;
1516475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+1] = g1;
1517475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+2] = g2;
1518475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+3] = g3;
1519475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1520475e0ac9SMatthew G. Knepley }
1521475e0ac9SMatthew G. Knepley 
1522475e0ac9SMatthew G. Knepley #undef __FUNCT__
1523b7e05686SMatthew G. Knepley #define __FUNCT__ "PetscDSHasDynamicJacobian"
1524b7e05686SMatthew G. Knepley /*@C
1525b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1526b7e05686SMatthew G. Knepley 
1527b7e05686SMatthew G. Knepley   Not collective
1528b7e05686SMatthew G. Knepley 
1529b7e05686SMatthew G. Knepley   Input Parameter:
1530b7e05686SMatthew G. Knepley . prob - The PetscDS
1531b7e05686SMatthew G. Knepley 
1532b7e05686SMatthew G. Knepley   Output Parameter:
1533b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1534b7e05686SMatthew G. Knepley 
1535b7e05686SMatthew G. Knepley   Level: intermediate
1536b7e05686SMatthew G. Knepley 
1537b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1538b7e05686SMatthew G. Knepley @*/
1539b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac)
1540b7e05686SMatthew G. Knepley {
1541b7e05686SMatthew G. Knepley   PetscInt f, g, h;
1542b7e05686SMatthew G. Knepley 
1543b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1544b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1545b7e05686SMatthew G. Knepley   *hasDynJac = PETSC_FALSE;
1546b7e05686SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1547b7e05686SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1548b7e05686SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1549b7e05686SMatthew G. Knepley         if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE;
1550b7e05686SMatthew G. Knepley       }
1551b7e05686SMatthew G. Knepley     }
1552b7e05686SMatthew G. Knepley   }
1553b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1554b7e05686SMatthew G. Knepley }
1555b7e05686SMatthew G. Knepley 
1556b7e05686SMatthew G. Knepley #undef __FUNCT__
1557b7e05686SMatthew G. Knepley #define __FUNCT__ "PetscDSGetDynamicJacobian"
1558b7e05686SMatthew G. Knepley /*@C
1559b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1560b7e05686SMatthew G. Knepley 
1561b7e05686SMatthew G. Knepley   Not collective
1562b7e05686SMatthew G. Knepley 
1563b7e05686SMatthew G. Knepley   Input Parameters:
1564b7e05686SMatthew G. Knepley + prob - The PetscDS
1565b7e05686SMatthew G. Knepley . f    - The test field number
1566b7e05686SMatthew G. Knepley - g    - The field number
1567b7e05686SMatthew G. Knepley 
1568b7e05686SMatthew G. Knepley   Output Parameters:
1569b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1570b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1571b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1572b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1573b7e05686SMatthew G. Knepley 
1574b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1575b7e05686SMatthew G. Knepley 
1576b7e05686SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1577b7e05686SMatthew G. Knepley 
1578b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1579b7e05686SMatthew G. Knepley 
1580b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1581b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1582b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1583b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1584b7e05686SMatthew G. Knepley 
1585b7e05686SMatthew G. Knepley + dim - the spatial dimension
1586b7e05686SMatthew G. Knepley . Nf - the number of fields
1587b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1588b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1589b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1590b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1591b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1592b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1593b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1594b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1595b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1596b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1597b7e05686SMatthew G. Knepley . t - current time
1598b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1599b7e05686SMatthew G. Knepley . x - coordinates of the current point
1600b7e05686SMatthew G. Knepley - g0 - output values at the current point
1601b7e05686SMatthew G. Knepley 
1602b7e05686SMatthew G. Knepley   Level: intermediate
1603b7e05686SMatthew G. Knepley 
1604b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1605b7e05686SMatthew G. Knepley @*/
1606b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1607b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1608b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1609b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1610b7e05686SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1611b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1612b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1613b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1614b7e05686SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1615b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1616b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1617b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1618b7e05686SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1619b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1620b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1621b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1622b7e05686SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1623b7e05686SMatthew G. Knepley {
1624b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1625b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1626b7e05686SMatthew 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);
1627b7e05686SMatthew 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);
1628b7e05686SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];}
1629b7e05686SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];}
1630b7e05686SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];}
1631b7e05686SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];}
1632b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1633b7e05686SMatthew G. Knepley }
1634b7e05686SMatthew G. Knepley 
1635b7e05686SMatthew G. Knepley #undef __FUNCT__
1636b7e05686SMatthew G. Knepley #define __FUNCT__ "PetscDSSetDynamicJacobian"
1637b7e05686SMatthew G. Knepley /*@C
1638b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1639b7e05686SMatthew G. Knepley 
1640b7e05686SMatthew G. Knepley   Not collective
1641b7e05686SMatthew G. Knepley 
1642b7e05686SMatthew G. Knepley   Input Parameters:
1643b7e05686SMatthew G. Knepley + prob - The PetscDS
1644b7e05686SMatthew G. Knepley . f    - The test field number
1645b7e05686SMatthew G. Knepley . g    - The field number
1646b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1647b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1648b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1649b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1650b7e05686SMatthew G. Knepley 
1651b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1652b7e05686SMatthew G. Knepley 
1653b7e05686SMatthew G. Knepley   \int_\Omega \phi g_0(u, u_t, \nabla u, x, t) \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \nabla \psi
1654b7e05686SMatthew G. Knepley 
1655b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1656b7e05686SMatthew G. Knepley 
1657b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1658b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1659b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1660b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1661b7e05686SMatthew G. Knepley 
1662b7e05686SMatthew G. Knepley + dim - the spatial dimension
1663b7e05686SMatthew G. Knepley . Nf - the number of fields
1664b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1665b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1666b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1667b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1668b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1669b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1670b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1671b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1672b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1673b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1674b7e05686SMatthew G. Knepley . t - current time
1675b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1676b7e05686SMatthew G. Knepley . x - coordinates of the current point
1677b7e05686SMatthew G. Knepley - g0 - output values at the current point
1678b7e05686SMatthew G. Knepley 
1679b7e05686SMatthew G. Knepley   Level: intermediate
1680b7e05686SMatthew G. Knepley 
1681b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1682b7e05686SMatthew G. Knepley @*/
1683b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1684b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1685b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1686b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1687b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1688b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1689b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1690b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1691b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1692b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1693b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1694b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1695b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1696b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1697b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1698b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1699b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1700b7e05686SMatthew G. Knepley {
1701b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1702b7e05686SMatthew G. Knepley 
1703b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1704b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1705b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1706b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1707b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1708b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1709b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1710b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1711b7e05686SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1712b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+0] = g0;
1713b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+1] = g1;
1714b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+2] = g2;
1715b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+3] = g3;
1716b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1717b7e05686SMatthew G. Knepley }
1718b7e05686SMatthew G. Knepley 
1719b7e05686SMatthew G. Knepley #undef __FUNCT__
17200c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSGetRiemannSolver"
17210c2f2876SMatthew G. Knepley /*@C
17220c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
17230c2f2876SMatthew G. Knepley 
17240c2f2876SMatthew G. Knepley   Not collective
17250c2f2876SMatthew G. Knepley 
17260c2f2876SMatthew G. Knepley   Input Arguments:
17270c2f2876SMatthew G. Knepley + prob - The PetscDS object
17280c2f2876SMatthew G. Knepley - f    - The field number
17290c2f2876SMatthew G. Knepley 
17300c2f2876SMatthew G. Knepley   Output Argument:
17310c2f2876SMatthew G. Knepley . r    - Riemann solver
17320c2f2876SMatthew G. Knepley 
17330c2f2876SMatthew G. Knepley   Calling sequence for r:
17340c2f2876SMatthew G. Knepley 
17355db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
17360c2f2876SMatthew G. Knepley 
17375db36cf9SMatthew G. Knepley + dim  - The spatial dimension
17385db36cf9SMatthew G. Knepley . Nf   - The number of fields
17395db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
17400c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
17410c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
17420c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
17430c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
17440c2f2876SMatthew G. Knepley - ctx  - optional user context
17450c2f2876SMatthew G. Knepley 
17460c2f2876SMatthew G. Knepley   Level: intermediate
17470c2f2876SMatthew G. Knepley 
17480c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
17490c2f2876SMatthew G. Knepley @*/
17500c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f,
17515db36cf9SMatthew G. Knepley                                        void (**r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx))
17520c2f2876SMatthew G. Knepley {
17530c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17540c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
17550c2f2876SMatthew 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);
17560c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
17570c2f2876SMatthew G. Knepley   *r = prob->r[f];
17580c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17590c2f2876SMatthew G. Knepley }
17600c2f2876SMatthew G. Knepley 
17610c2f2876SMatthew G. Knepley #undef __FUNCT__
17620c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSSetRiemannSolver"
17630c2f2876SMatthew G. Knepley /*@C
17640c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
17650c2f2876SMatthew G. Knepley 
17660c2f2876SMatthew G. Knepley   Not collective
17670c2f2876SMatthew G. Knepley 
17680c2f2876SMatthew G. Knepley   Input Arguments:
17690c2f2876SMatthew G. Knepley + prob - The PetscDS object
17700c2f2876SMatthew G. Knepley . f    - The field number
17710c2f2876SMatthew G. Knepley - r    - Riemann solver
17720c2f2876SMatthew G. Knepley 
17730c2f2876SMatthew G. Knepley   Calling sequence for r:
17740c2f2876SMatthew G. Knepley 
17755db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
17760c2f2876SMatthew G. Knepley 
17775db36cf9SMatthew G. Knepley + dim  - The spatial dimension
17785db36cf9SMatthew G. Knepley . Nf   - The number of fields
17795db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
17800c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
17810c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
17820c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
17830c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
17840c2f2876SMatthew G. Knepley - ctx  - optional user context
17850c2f2876SMatthew G. Knepley 
17860c2f2876SMatthew G. Knepley   Level: intermediate
17870c2f2876SMatthew G. Knepley 
17880c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
17890c2f2876SMatthew G. Knepley @*/
17900c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f,
17915db36cf9SMatthew G. Knepley                                        void (*r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx))
17920c2f2876SMatthew G. Knepley {
17930c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
17940c2f2876SMatthew G. Knepley 
17950c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17960c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1797de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
17980c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
17990c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
18000c2f2876SMatthew G. Knepley   prob->r[f] = r;
18010c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18020c2f2876SMatthew G. Knepley }
18030c2f2876SMatthew G. Knepley 
18040c2f2876SMatthew G. Knepley #undef __FUNCT__
18050c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSGetContext"
18060c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx)
18070c2f2876SMatthew G. Knepley {
18080c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18090c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18100c2f2876SMatthew 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);
18110c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
18120c2f2876SMatthew G. Knepley   *ctx = prob->ctx[f];
18130c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18140c2f2876SMatthew G. Knepley }
18150c2f2876SMatthew G. Knepley 
18160c2f2876SMatthew G. Knepley #undef __FUNCT__
18170c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSSetContext"
18180c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx)
18190c2f2876SMatthew G. Knepley {
18200c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
18210c2f2876SMatthew G. Knepley 
18220c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18230c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18240c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
18250c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
18260c2f2876SMatthew G. Knepley   prob->ctx[f] = ctx;
18270c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18280c2f2876SMatthew G. Knepley }
18290c2f2876SMatthew G. Knepley 
18300c2f2876SMatthew G. Knepley #undef __FUNCT__
18312764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdResidual"
1832194d53e6SMatthew G. Knepley /*@C
1833194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
1834194d53e6SMatthew G. Knepley 
1835194d53e6SMatthew G. Knepley   Not collective
1836194d53e6SMatthew G. Knepley 
1837194d53e6SMatthew G. Knepley   Input Parameters:
1838194d53e6SMatthew G. Knepley + prob - The PetscDS
1839194d53e6SMatthew G. Knepley - f    - The test field number
1840194d53e6SMatthew G. Knepley 
1841194d53e6SMatthew G. Knepley   Output Parameters:
1842194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
1843194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1844194d53e6SMatthew G. Knepley 
1845194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1846194d53e6SMatthew G. Knepley 
1847194d53e6SMatthew 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
1848194d53e6SMatthew G. Knepley 
1849194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1850194d53e6SMatthew G. Knepley 
185130b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1852194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1853194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
185430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1855194d53e6SMatthew G. Knepley 
1856194d53e6SMatthew G. Knepley + dim - the spatial dimension
1857194d53e6SMatthew G. Knepley . Nf - the number of fields
1858194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1859194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1860194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1861194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1862194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1863194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1864194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1865194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1866194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1867194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1868194d53e6SMatthew G. Knepley . t - current time
1869194d53e6SMatthew G. Knepley . x - coordinates of the current point
1870194d53e6SMatthew G. Knepley . n - unit normal at the current point
1871194d53e6SMatthew G. Knepley - f0 - output values at the current point
1872194d53e6SMatthew G. Knepley 
1873194d53e6SMatthew G. Knepley   Level: intermediate
1874194d53e6SMatthew G. Knepley 
1875194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
1876194d53e6SMatthew G. Knepley @*/
18772764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f,
187830b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1879194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1880194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
188130b9ff8bSMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]),
188230b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1883194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1884194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
188530b9ff8bSMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f1[]))
18862764a2aaSMatthew G. Knepley {
18872764a2aaSMatthew G. Knepley   PetscFunctionBegin;
18882764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18892764a2aaSMatthew 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);
18902764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];}
18912764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];}
18922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
18932764a2aaSMatthew G. Knepley }
18942764a2aaSMatthew G. Knepley 
18952764a2aaSMatthew G. Knepley #undef __FUNCT__
18962764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdResidual"
1897194d53e6SMatthew G. Knepley /*@C
1898194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
1899194d53e6SMatthew G. Knepley 
1900194d53e6SMatthew G. Knepley   Not collective
1901194d53e6SMatthew G. Knepley 
1902194d53e6SMatthew G. Knepley   Input Parameters:
1903194d53e6SMatthew G. Knepley + prob - The PetscDS
1904194d53e6SMatthew G. Knepley . f    - The test field number
1905194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
1906194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1907194d53e6SMatthew G. Knepley 
1908194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1909194d53e6SMatthew G. Knepley 
1910194d53e6SMatthew 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
1911194d53e6SMatthew G. Knepley 
1912194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1913194d53e6SMatthew G. Knepley 
191430b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1915194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1916194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
191730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1918194d53e6SMatthew G. Knepley 
1919194d53e6SMatthew G. Knepley + dim - the spatial dimension
1920194d53e6SMatthew G. Knepley . Nf - the number of fields
1921194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1922194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1923194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1924194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1925194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1926194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1927194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1928194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1929194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1930194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1931194d53e6SMatthew G. Knepley . t - current time
1932194d53e6SMatthew G. Knepley . x - coordinates of the current point
1933194d53e6SMatthew G. Knepley . n - unit normal at the current point
1934194d53e6SMatthew G. Knepley - f0 - output values at the current point
1935194d53e6SMatthew G. Knepley 
1936194d53e6SMatthew G. Knepley   Level: intermediate
1937194d53e6SMatthew G. Knepley 
1938194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
1939194d53e6SMatthew G. Knepley @*/
19402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f,
194130b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1942194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1943194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194430b9ff8bSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]),
194530b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1946194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1947194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194830b9ff8bSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f1[]))
19492764a2aaSMatthew G. Knepley {
19502764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
19512764a2aaSMatthew G. Knepley 
19522764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19532764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19542764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19552764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
19562764a2aaSMatthew G. Knepley   if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;}
19572764a2aaSMatthew G. Knepley   if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;}
19582764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
19592764a2aaSMatthew G. Knepley }
19602764a2aaSMatthew G. Knepley 
19612764a2aaSMatthew G. Knepley #undef __FUNCT__
19622764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdJacobian"
1963194d53e6SMatthew G. Knepley /*@C
1964194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
1965194d53e6SMatthew G. Knepley 
1966194d53e6SMatthew G. Knepley   Not collective
1967194d53e6SMatthew G. Knepley 
1968194d53e6SMatthew G. Knepley   Input Parameters:
1969194d53e6SMatthew G. Knepley + prob - The PetscDS
1970194d53e6SMatthew G. Knepley . f    - The test field number
1971194d53e6SMatthew G. Knepley - g    - The field number
1972194d53e6SMatthew G. Knepley 
1973194d53e6SMatthew G. Knepley   Output Parameters:
1974194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1975194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1976194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1977194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1978194d53e6SMatthew G. Knepley 
1979194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1980194d53e6SMatthew G. Knepley 
1981194d53e6SMatthew 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
1982194d53e6SMatthew G. Knepley 
1983194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1984194d53e6SMatthew G. Knepley 
198530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1986194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1987194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
198830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
1989194d53e6SMatthew G. Knepley 
1990194d53e6SMatthew G. Knepley + dim - the spatial dimension
1991194d53e6SMatthew G. Knepley . Nf - the number of fields
1992194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1993194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1994194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1995194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1996194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1997194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1998194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1999194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2000194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2001194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2002194d53e6SMatthew G. Knepley . t - current time
20032aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2004194d53e6SMatthew G. Knepley . x - coordinates of the current point
2005194d53e6SMatthew G. Knepley . n - normal at the current point
2006194d53e6SMatthew G. Knepley - g0 - output values at the current point
2007194d53e6SMatthew G. Knepley 
2008194d53e6SMatthew G. Knepley   Level: intermediate
2009194d53e6SMatthew G. Knepley 
2010194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2011194d53e6SMatthew G. Knepley @*/
20122764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
201330b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2014194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2015194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20162aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g0[]),
201730b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2018194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2019194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20202aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g1[]),
202130b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2022194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2023194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20242aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g2[]),
202530b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2026194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2027194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20282aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g3[]))
20292764a2aaSMatthew G. Knepley {
20302764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20312764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20322764a2aaSMatthew 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);
20332764a2aaSMatthew 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);
20342764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];}
20352764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];}
20362764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];}
20372764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];}
20382764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20392764a2aaSMatthew G. Knepley }
20402764a2aaSMatthew G. Knepley 
20412764a2aaSMatthew G. Knepley #undef __FUNCT__
20422764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdJacobian"
2043194d53e6SMatthew G. Knepley /*@C
2044194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2045194d53e6SMatthew G. Knepley 
2046194d53e6SMatthew G. Knepley   Not collective
2047194d53e6SMatthew G. Knepley 
2048194d53e6SMatthew G. Knepley   Input Parameters:
2049194d53e6SMatthew G. Knepley + prob - The PetscDS
2050194d53e6SMatthew G. Knepley . f    - The test field number
2051194d53e6SMatthew G. Knepley . g    - The field number
2052194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2053194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2054194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2055194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2056194d53e6SMatthew G. Knepley 
2057194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2058194d53e6SMatthew G. Knepley 
2059194d53e6SMatthew 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
2060194d53e6SMatthew G. Knepley 
2061194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2062194d53e6SMatthew G. Knepley 
206330b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2064194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2065194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
206630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2067194d53e6SMatthew G. Knepley 
2068194d53e6SMatthew G. Knepley + dim - the spatial dimension
2069194d53e6SMatthew G. Knepley . Nf - the number of fields
2070194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2071194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2072194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2073194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2074194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2075194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2076194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2077194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2078194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2079194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2080194d53e6SMatthew G. Knepley . t - current time
20812aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2082194d53e6SMatthew G. Knepley . x - coordinates of the current point
2083194d53e6SMatthew G. Knepley . n - normal at the current point
2084194d53e6SMatthew G. Knepley - g0 - output values at the current point
2085194d53e6SMatthew G. Knepley 
2086194d53e6SMatthew G. Knepley   Level: intermediate
2087194d53e6SMatthew G. Knepley 
2088194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2089194d53e6SMatthew G. Knepley @*/
20902764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
209130b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2092194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2093194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20942aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g0[]),
209530b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2096194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2097194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
20982aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g1[]),
209930b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2100194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2101194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
21022aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g2[]),
210330b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2104194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2105194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
21062aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g3[]))
21072764a2aaSMatthew G. Knepley {
21082764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21092764a2aaSMatthew G. Knepley 
21102764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21112764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21122764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
21132764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
21142764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
21152764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
21162764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21172764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
21182764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
21192764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+0] = g0;
21202764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+1] = g1;
21212764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+2] = g2;
21222764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+3] = g3;
21232764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21242764a2aaSMatthew G. Knepley }
21252764a2aaSMatthew G. Knepley 
21262764a2aaSMatthew G. Knepley #undef __FUNCT__
21274cd1e086SMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldIndex"
21284cd1e086SMatthew G. Knepley /*@
21294cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
21304cd1e086SMatthew G. Knepley 
21314cd1e086SMatthew G. Knepley   Not collective
21324cd1e086SMatthew G. Knepley 
21334cd1e086SMatthew G. Knepley   Input Parameters:
21344cd1e086SMatthew G. Knepley + prob - The PetscDS object
21354cd1e086SMatthew G. Knepley - disc - The discretization object
21364cd1e086SMatthew G. Knepley 
21374cd1e086SMatthew G. Knepley   Output Parameter:
21384cd1e086SMatthew G. Knepley . f - The field number
21394cd1e086SMatthew G. Knepley 
21404cd1e086SMatthew G. Knepley   Level: beginner
21414cd1e086SMatthew G. Knepley 
21424cd1e086SMatthew G. Knepley .seealso: PetscGetDiscretization(), PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
21434cd1e086SMatthew G. Knepley @*/
21444cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
21454cd1e086SMatthew G. Knepley {
21464cd1e086SMatthew G. Knepley   PetscInt g;
21474cd1e086SMatthew G. Knepley 
21484cd1e086SMatthew G. Knepley   PetscFunctionBegin;
21494cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21504cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
21514cd1e086SMatthew G. Knepley   *f = -1;
21524cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
21534cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
21544cd1e086SMatthew G. Knepley   *f = g;
21554cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
21564cd1e086SMatthew G. Knepley }
21574cd1e086SMatthew G. Knepley 
21584cd1e086SMatthew G. Knepley #undef __FUNCT__
21594cd1e086SMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldSize"
21604cd1e086SMatthew G. Knepley /*@
21614cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
21624cd1e086SMatthew G. Knepley 
21634cd1e086SMatthew G. Knepley   Not collective
21644cd1e086SMatthew G. Knepley 
21654cd1e086SMatthew G. Knepley   Input Parameters:
21664cd1e086SMatthew G. Knepley + prob - The PetscDS object
21674cd1e086SMatthew G. Knepley - f - The field number
21684cd1e086SMatthew G. Knepley 
21694cd1e086SMatthew G. Knepley   Output Parameter:
21704cd1e086SMatthew G. Knepley . size - The size
21714cd1e086SMatthew G. Knepley 
21724cd1e086SMatthew G. Knepley   Level: beginner
21734cd1e086SMatthew G. Knepley 
21744cd1e086SMatthew G. Knepley .seealso: PetscDSGetFieldOffset(), PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
21754cd1e086SMatthew G. Knepley @*/
21764cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
21774cd1e086SMatthew G. Knepley {
21784cd1e086SMatthew G. Knepley   PetscInt       Nb, Nc;
21794cd1e086SMatthew G. Knepley   PetscErrorCode ierr;
21804cd1e086SMatthew G. Knepley 
21814cd1e086SMatthew G. Knepley   PetscFunctionBegin;
21824cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21834cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
21844cd1e086SMatthew 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);
2185*47e57110SSander Arens   *size = prob->Nc[f] * prob->Nb[f];
21864cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
21874cd1e086SMatthew G. Knepley }
21884cd1e086SMatthew G. Knepley 
21894cd1e086SMatthew G. Knepley #undef __FUNCT__
21902764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldOffset"
2191bc4ae4beSMatthew G. Knepley /*@
2192bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2193bc4ae4beSMatthew G. Knepley 
2194bc4ae4beSMatthew G. Knepley   Not collective
2195bc4ae4beSMatthew G. Knepley 
2196bc4ae4beSMatthew G. Knepley   Input Parameters:
2197bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2198bc4ae4beSMatthew G. Knepley - f - The field number
2199bc4ae4beSMatthew G. Knepley 
2200bc4ae4beSMatthew G. Knepley   Output Parameter:
2201bc4ae4beSMatthew G. Knepley . off - The offset
2202bc4ae4beSMatthew G. Knepley 
2203bc4ae4beSMatthew G. Knepley   Level: beginner
2204bc4ae4beSMatthew G. Knepley 
22054cd1e086SMatthew G. Knepley .seealso: PetscDSGetFieldSize(), PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2206bc4ae4beSMatthew G. Knepley @*/
22072764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
22082764a2aaSMatthew G. Knepley {
22094cd1e086SMatthew G. Knepley   PetscInt       size, g;
22102764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
22112764a2aaSMatthew G. Knepley 
22122764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22132764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22142764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
22152764a2aaSMatthew 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);
22162764a2aaSMatthew G. Knepley   *off = 0;
22172764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
22184cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
22194cd1e086SMatthew G. Knepley     *off += size;
22202764a2aaSMatthew G. Knepley   }
22212764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22222764a2aaSMatthew G. Knepley }
22232764a2aaSMatthew G. Knepley 
22242764a2aaSMatthew G. Knepley #undef __FUNCT__
22252764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdFieldOffset"
2226bc4ae4beSMatthew G. Knepley /*@
2227c3ac4435SMatthew G. Knepley   PetscDSGetBdFieldOffset - Returns the offset of the given field in the full space boundary basis
2228bc4ae4beSMatthew G. Knepley 
2229bc4ae4beSMatthew G. Knepley   Not collective
2230bc4ae4beSMatthew G. Knepley 
2231bc4ae4beSMatthew G. Knepley   Input Parameters:
2232bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2233bc4ae4beSMatthew G. Knepley - f - The field number
2234bc4ae4beSMatthew G. Knepley 
2235bc4ae4beSMatthew G. Knepley   Output Parameter:
2236bc4ae4beSMatthew G. Knepley . off - The boundary offset
2237bc4ae4beSMatthew G. Knepley 
2238bc4ae4beSMatthew G. Knepley   Level: beginner
2239bc4ae4beSMatthew G. Knepley 
2240bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2241bc4ae4beSMatthew G. Knepley @*/
22422764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
22432764a2aaSMatthew G. Knepley {
22442764a2aaSMatthew G. Knepley   PetscInt       g;
22452764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
22462764a2aaSMatthew G. Knepley 
22472764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22482764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22492764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
22502764a2aaSMatthew 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);
22512764a2aaSMatthew G. Knepley   *off = 0;
22522764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
22532764a2aaSMatthew G. Knepley     PetscFE  fe = (PetscFE) prob->discBd[g];
22542764a2aaSMatthew G. Knepley     PetscInt Nb, Nc;
22552764a2aaSMatthew G. Knepley 
22562764a2aaSMatthew G. Knepley     ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
22572764a2aaSMatthew G. Knepley     ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
22582764a2aaSMatthew G. Knepley     *off += Nb*Nc;
22596ce16762SMatthew G. Knepley   }
22606ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
22616ce16762SMatthew G. Knepley }
22626ce16762SMatthew G. Knepley 
22636ce16762SMatthew G. Knepley #undef __FUNCT__
2264*47e57110SSander Arens #define __FUNCT__ "PetscDSGetDimensions"
2265*47e57110SSander Arens /*@
2266*47e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2267*47e57110SSander Arens 
2268*47e57110SSander Arens   Not collective
2269*47e57110SSander Arens 
2270*47e57110SSander Arens   Input Parameter:
2271*47e57110SSander Arens . prob - The PetscDS object
2272*47e57110SSander Arens 
2273*47e57110SSander Arens   Output Parameter:
2274*47e57110SSander Arens . dimensions - The number of dimensions
2275*47e57110SSander Arens 
2276*47e57110SSander Arens   Level: beginner
2277*47e57110SSander Arens 
2278*47e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2279*47e57110SSander Arens @*/
2280*47e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
2281*47e57110SSander Arens {
2282*47e57110SSander Arens   PetscErrorCode ierr;
2283*47e57110SSander Arens 
2284*47e57110SSander Arens   PetscFunctionBegin;
2285*47e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2286*47e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2287*47e57110SSander Arens   PetscValidPointer(dimensions, 2);
2288*47e57110SSander Arens   *dimensions = prob->Nb;
2289*47e57110SSander Arens   PetscFunctionReturn(0);
2290*47e57110SSander Arens }
2291*47e57110SSander Arens 
2292*47e57110SSander Arens #undef __FUNCT__
2293*47e57110SSander Arens #define __FUNCT__ "PetscDSGetComponents"
2294*47e57110SSander Arens /*@
2295*47e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
2296*47e57110SSander Arens 
2297*47e57110SSander Arens   Not collective
2298*47e57110SSander Arens 
2299*47e57110SSander Arens   Input Parameter:
2300*47e57110SSander Arens . prob - The PetscDS object
2301*47e57110SSander Arens 
2302*47e57110SSander Arens   Output Parameter:
2303*47e57110SSander Arens . components - The number of components
2304*47e57110SSander Arens 
2305*47e57110SSander Arens   Level: beginner
2306*47e57110SSander Arens 
2307*47e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2308*47e57110SSander Arens @*/
2309*47e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
2310*47e57110SSander Arens {
2311*47e57110SSander Arens   PetscErrorCode ierr;
2312*47e57110SSander Arens 
2313*47e57110SSander Arens   PetscFunctionBegin;
2314*47e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2315*47e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2316*47e57110SSander Arens   PetscValidPointer(components, 2);
2317*47e57110SSander Arens   *components = prob->Nc;
2318*47e57110SSander Arens   PetscFunctionReturn(0);
2319*47e57110SSander Arens }
2320*47e57110SSander Arens 
2321*47e57110SSander Arens #undef __FUNCT__
23226ce16762SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentOffset"
23236ce16762SMatthew G. Knepley /*@
23246ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
23256ce16762SMatthew G. Knepley 
23266ce16762SMatthew G. Knepley   Not collective
23276ce16762SMatthew G. Knepley 
23286ce16762SMatthew G. Knepley   Input Parameters:
23296ce16762SMatthew G. Knepley + prob - The PetscDS object
23306ce16762SMatthew G. Knepley - f - The field number
23316ce16762SMatthew G. Knepley 
23326ce16762SMatthew G. Knepley   Output Parameter:
23336ce16762SMatthew G. Knepley . off - The offset
23346ce16762SMatthew G. Knepley 
23356ce16762SMatthew G. Knepley   Level: beginner
23366ce16762SMatthew G. Knepley 
23376ce16762SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
23386ce16762SMatthew G. Knepley @*/
23396ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
23406ce16762SMatthew G. Knepley {
23416ce16762SMatthew G. Knepley   PetscInt       g;
23426ce16762SMatthew G. Knepley   PetscErrorCode ierr;
23436ce16762SMatthew G. Knepley 
23446ce16762SMatthew G. Knepley   PetscFunctionBegin;
23456ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23466ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
23476ce16762SMatthew 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);
2348*47e57110SSander Arens   *off = prob->off[f];
23492764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23502764a2aaSMatthew G. Knepley }
23512764a2aaSMatthew G. Knepley 
23522764a2aaSMatthew G. Knepley #undef __FUNCT__
2353194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentOffsets"
2354194d53e6SMatthew G. Knepley /*@
2355194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2356194d53e6SMatthew G. Knepley 
2357194d53e6SMatthew G. Knepley   Not collective
2358194d53e6SMatthew G. Knepley 
2359194d53e6SMatthew G. Knepley   Input Parameter:
2360194d53e6SMatthew G. Knepley . prob - The PetscDS object
2361194d53e6SMatthew G. Knepley 
2362194d53e6SMatthew G. Knepley   Output Parameter:
2363194d53e6SMatthew G. Knepley . offsets - The offsets
2364194d53e6SMatthew G. Knepley 
2365194d53e6SMatthew G. Knepley   Level: beginner
2366194d53e6SMatthew G. Knepley 
2367194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2368194d53e6SMatthew G. Knepley @*/
2369194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2370194d53e6SMatthew G. Knepley {
2371194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2372194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2373194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2374194d53e6SMatthew G. Knepley   *offsets = prob->off;
2375194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2376194d53e6SMatthew G. Knepley }
2377194d53e6SMatthew G. Knepley 
2378194d53e6SMatthew G. Knepley #undef __FUNCT__
2379194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentDerivativeOffsets"
2380194d53e6SMatthew G. Knepley /*@
2381194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2382194d53e6SMatthew G. Knepley 
2383194d53e6SMatthew G. Knepley   Not collective
2384194d53e6SMatthew G. Knepley 
2385194d53e6SMatthew G. Knepley   Input Parameter:
2386194d53e6SMatthew G. Knepley . prob - The PetscDS object
2387194d53e6SMatthew G. Knepley 
2388194d53e6SMatthew G. Knepley   Output Parameter:
2389194d53e6SMatthew G. Knepley . offsets - The offsets
2390194d53e6SMatthew G. Knepley 
2391194d53e6SMatthew G. Knepley   Level: beginner
2392194d53e6SMatthew G. Knepley 
2393194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2394194d53e6SMatthew G. Knepley @*/
2395194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2396194d53e6SMatthew G. Knepley {
2397194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2398194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2399194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2400194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
2401194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2402194d53e6SMatthew G. Knepley }
2403194d53e6SMatthew G. Knepley 
2404194d53e6SMatthew G. Knepley #undef __FUNCT__
2405194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentBdOffsets"
2406194d53e6SMatthew G. Knepley /*@
2407194d53e6SMatthew G. Knepley   PetscDSGetComponentBdOffsets - Returns the offset of each field on a boundary evaluation point
2408194d53e6SMatthew G. Knepley 
2409194d53e6SMatthew G. Knepley   Not collective
2410194d53e6SMatthew G. Knepley 
2411194d53e6SMatthew G. Knepley   Input Parameter:
2412194d53e6SMatthew G. Knepley . prob - The PetscDS object
2413194d53e6SMatthew G. Knepley 
2414194d53e6SMatthew G. Knepley   Output Parameter:
2415194d53e6SMatthew G. Knepley . offsets - The offsets
2416194d53e6SMatthew G. Knepley 
2417194d53e6SMatthew G. Knepley   Level: beginner
2418194d53e6SMatthew G. Knepley 
2419194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2420194d53e6SMatthew G. Knepley @*/
2421194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentBdOffsets(PetscDS prob, PetscInt *offsets[])
2422194d53e6SMatthew G. Knepley {
2423194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2424194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2425194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2426194d53e6SMatthew G. Knepley   *offsets = prob->offBd;
2427194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2428194d53e6SMatthew G. Knepley }
2429194d53e6SMatthew G. Knepley 
2430194d53e6SMatthew G. Knepley #undef __FUNCT__
2431194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentBdDerivativeOffsets"
2432194d53e6SMatthew G. Knepley /*@
2433194d53e6SMatthew G. Knepley   PetscDSGetComponentBdDerivativeOffsets - Returns the offset of each field derivative on a boundary evaluation point
2434194d53e6SMatthew G. Knepley 
2435194d53e6SMatthew G. Knepley   Not collective
2436194d53e6SMatthew G. Knepley 
2437194d53e6SMatthew G. Knepley   Input Parameter:
2438194d53e6SMatthew G. Knepley . prob - The PetscDS object
2439194d53e6SMatthew G. Knepley 
2440194d53e6SMatthew G. Knepley   Output Parameter:
2441194d53e6SMatthew G. Knepley . offsets - The offsets
2442194d53e6SMatthew G. Knepley 
2443194d53e6SMatthew G. Knepley   Level: beginner
2444194d53e6SMatthew G. Knepley 
2445194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
2446194d53e6SMatthew G. Knepley @*/
2447194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentBdDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2448194d53e6SMatthew G. Knepley {
2449194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2450194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2451194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2452194d53e6SMatthew G. Knepley   *offsets = prob->offDerBd;
2453194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2454194d53e6SMatthew G. Knepley }
2455194d53e6SMatthew G. Knepley 
2456194d53e6SMatthew G. Knepley #undef __FUNCT__
24572764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTabulation"
245868c9edb9SMatthew G. Knepley /*@C
245968c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
246068c9edb9SMatthew G. Knepley 
246168c9edb9SMatthew G. Knepley   Not collective
246268c9edb9SMatthew G. Knepley 
246368c9edb9SMatthew G. Knepley   Input Parameter:
246468c9edb9SMatthew G. Knepley . prob - The PetscDS object
246568c9edb9SMatthew G. Knepley 
246668c9edb9SMatthew G. Knepley   Output Parameters:
246768c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
246868c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
246968c9edb9SMatthew G. Knepley 
247068c9edb9SMatthew G. Knepley   Level: intermediate
247168c9edb9SMatthew G. Knepley 
247268c9edb9SMatthew G. Knepley .seealso: PetscDSGetBdTabulation(), PetscDSCreate()
247368c9edb9SMatthew G. Knepley @*/
24742764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
24752764a2aaSMatthew G. Knepley {
24762764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24772764a2aaSMatthew G. Knepley 
24782764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24792764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24802764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
24812764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basis;}
24822764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;}
24832764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
24842764a2aaSMatthew G. Knepley }
24852764a2aaSMatthew G. Knepley 
24862764a2aaSMatthew G. Knepley #undef __FUNCT__
24872764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdTabulation"
248868c9edb9SMatthew G. Knepley /*@C
248968c9edb9SMatthew G. Knepley   PetscDSGetBdTabulation - Return the basis tabulation at quadrature points for the boundary discretization
249068c9edb9SMatthew G. Knepley 
249168c9edb9SMatthew G. Knepley   Not collective
249268c9edb9SMatthew G. Knepley 
249368c9edb9SMatthew G. Knepley   Input Parameter:
249468c9edb9SMatthew G. Knepley . prob - The PetscDS object
249568c9edb9SMatthew G. Knepley 
249668c9edb9SMatthew G. Knepley   Output Parameters:
249768c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
249868c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
249968c9edb9SMatthew G. Knepley 
250068c9edb9SMatthew G. Knepley   Level: intermediate
250168c9edb9SMatthew G. Knepley 
250268c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
250368c9edb9SMatthew G. Knepley @*/
25042764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
25052764a2aaSMatthew G. Knepley {
25062764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25072764a2aaSMatthew G. Knepley 
25082764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25092764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25102764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25112764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basisBd;}
25122764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerBd;}
25132764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25142764a2aaSMatthew G. Knepley }
25152764a2aaSMatthew G. Knepley 
25162764a2aaSMatthew G. Knepley #undef __FUNCT__
25172764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetEvaluationArrays"
25182764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
25192764a2aaSMatthew G. Knepley {
25202764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25212764a2aaSMatthew G. Knepley 
25222764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25232764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25242764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25252764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
25262764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
25272764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
25282764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25292764a2aaSMatthew G. Knepley }
25302764a2aaSMatthew G. Knepley 
25312764a2aaSMatthew G. Knepley #undef __FUNCT__
25322764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetWeakFormArrays"
25332764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
25342764a2aaSMatthew G. Knepley {
25352764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25362764a2aaSMatthew G. Knepley 
25372764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25382764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25392764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25402764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
25412764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
25422764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
25432764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
25442764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
25452764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
25462764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25472764a2aaSMatthew G. Knepley }
25482764a2aaSMatthew G. Knepley 
25492764a2aaSMatthew G. Knepley #undef __FUNCT__
25502764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetRefCoordArrays"
25512764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer)
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 (x)           {PetscValidPointer(x, 2);           *x           = prob->x;}
25592764a2aaSMatthew G. Knepley   if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;}
25602764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25612764a2aaSMatthew G. Knepley }
25622764a2aaSMatthew G. Knepley 
25632764a2aaSMatthew G. Knepley #undef __FUNCT__
256458ebd649SToby Isaac #define __FUNCT__ "PetscDSAddBoundary"
256558ebd649SToby Isaac /*@C
256658ebd649SToby Isaac   PetscDSAddBoundary - Add a boundary condition to the model
256758ebd649SToby Isaac 
256858ebd649SToby Isaac   Input Parameters:
256958ebd649SToby Isaac + ds          - The PetscDS object
257058ebd649SToby Isaac . isEssential - Flag for an essential (Dirichlet) condition, as opposed to a natural (Neumann) condition
257158ebd649SToby Isaac . name        - The BC name
257258ebd649SToby Isaac . labelname   - The label defining constrained points
257358ebd649SToby Isaac . field       - The field to constrain
257458ebd649SToby Isaac . numcomps    - The number of constrained field components
257558ebd649SToby Isaac . comps       - An array of constrained component numbers
257658ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
257758ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
257858ebd649SToby Isaac . ids         - An array of ids for constrained points
257958ebd649SToby Isaac - ctx         - An optional user context for bcFunc
258058ebd649SToby Isaac 
258158ebd649SToby Isaac   Options Database Keys:
258258ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
258358ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
258458ebd649SToby Isaac 
258558ebd649SToby Isaac   Level: developer
258658ebd649SToby Isaac 
258758ebd649SToby Isaac .seealso: PetscDSGetBoundary()
258858ebd649SToby Isaac @*/
258958ebd649SToby 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)
259058ebd649SToby Isaac {
259158ebd649SToby Isaac   DSBoundary     b;
259258ebd649SToby Isaac   PetscErrorCode ierr;
259358ebd649SToby Isaac 
259458ebd649SToby Isaac   PetscFunctionBegin;
259558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
259658ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
259758ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
259858ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
259958ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
260058ebd649SToby Isaac   if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
260158ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
260258ebd649SToby Isaac   if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
260358ebd649SToby Isaac   b->essential       = isEssential;
260458ebd649SToby Isaac   b->field           = field;
260558ebd649SToby Isaac   b->numcomps        = numcomps;
260658ebd649SToby Isaac   b->func            = bcFunc;
260758ebd649SToby Isaac   b->numids          = numids;
260858ebd649SToby Isaac   b->ctx             = ctx;
260958ebd649SToby Isaac   b->next            = ds->boundary;
261058ebd649SToby Isaac   ds->boundary       = b;
261158ebd649SToby Isaac   PetscFunctionReturn(0);
261258ebd649SToby Isaac }
261358ebd649SToby Isaac 
261458ebd649SToby Isaac #undef __FUNCT__
261558ebd649SToby Isaac #define __FUNCT__ "PetscDSGetNumBoundary"
261658ebd649SToby Isaac /*@
261758ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
261858ebd649SToby Isaac 
261958ebd649SToby Isaac   Input Parameters:
262058ebd649SToby Isaac . ds - The PetscDS object
262158ebd649SToby Isaac 
262258ebd649SToby Isaac   Output Parameters:
262358ebd649SToby Isaac . numBd - The number of BC
262458ebd649SToby Isaac 
262558ebd649SToby Isaac   Level: intermediate
262658ebd649SToby Isaac 
262758ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
262858ebd649SToby Isaac @*/
262958ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
263058ebd649SToby Isaac {
263158ebd649SToby Isaac   DSBoundary b = ds->boundary;
263258ebd649SToby Isaac 
263358ebd649SToby Isaac   PetscFunctionBegin;
263458ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
263558ebd649SToby Isaac   PetscValidPointer(numBd, 2);
263658ebd649SToby Isaac   *numBd = 0;
263758ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
263858ebd649SToby Isaac   PetscFunctionReturn(0);
263958ebd649SToby Isaac }
264058ebd649SToby Isaac 
264158ebd649SToby Isaac #undef __FUNCT__
264258ebd649SToby Isaac #define __FUNCT__ "PetscDSGetBoundary"
264358ebd649SToby Isaac /*@C
264458ebd649SToby Isaac   PetscDSGetBoundary - Add a boundary condition to the model
264558ebd649SToby Isaac 
264658ebd649SToby Isaac   Input Parameters:
264758ebd649SToby Isaac + ds          - The PetscDS object
264858ebd649SToby Isaac - bd          - The BC number
264958ebd649SToby Isaac 
265058ebd649SToby Isaac   Output Parameters:
265158ebd649SToby Isaac + isEssential - Flag for an essential (Dirichlet) condition, as opposed to a natural (Neumann) condition
265258ebd649SToby Isaac . name        - The BC name
265358ebd649SToby Isaac . labelname   - The label defining constrained points
265458ebd649SToby Isaac . field       - The field to constrain
265558ebd649SToby Isaac . numcomps    - The number of constrained field components
265658ebd649SToby Isaac . comps       - An array of constrained component numbers
265758ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
265858ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
265958ebd649SToby Isaac . ids         - An array of ids for constrained points
266058ebd649SToby Isaac - ctx         - An optional user context for bcFunc
266158ebd649SToby Isaac 
266258ebd649SToby Isaac   Options Database Keys:
266358ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
266458ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
266558ebd649SToby Isaac 
266658ebd649SToby Isaac   Level: developer
266758ebd649SToby Isaac 
266858ebd649SToby Isaac .seealso: PetscDSAddBoundary()
266958ebd649SToby Isaac @*/
267058ebd649SToby 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)
267158ebd649SToby Isaac {
267258ebd649SToby Isaac   DSBoundary b    = ds->boundary;
267358ebd649SToby Isaac   PetscInt   n    = 0;
267458ebd649SToby Isaac 
267558ebd649SToby Isaac   PetscFunctionBegin;
267658ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
267758ebd649SToby Isaac   while (b) {
267858ebd649SToby Isaac     if (n == bd) break;
267958ebd649SToby Isaac     b = b->next;
268058ebd649SToby Isaac     ++n;
268158ebd649SToby Isaac   }
268258ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
268358ebd649SToby Isaac   if (isEssential) {
268458ebd649SToby Isaac     PetscValidPointer(isEssential, 3);
268558ebd649SToby Isaac     *isEssential = b->essential;
268658ebd649SToby Isaac   }
268758ebd649SToby Isaac   if (name) {
268858ebd649SToby Isaac     PetscValidPointer(name, 4);
268958ebd649SToby Isaac     *name = b->name;
269058ebd649SToby Isaac   }
269158ebd649SToby Isaac   if (labelname) {
269258ebd649SToby Isaac     PetscValidPointer(labelname, 5);
269358ebd649SToby Isaac     *labelname = b->labelname;
269458ebd649SToby Isaac   }
269558ebd649SToby Isaac   if (field) {
269658ebd649SToby Isaac     PetscValidPointer(field, 6);
269758ebd649SToby Isaac     *field = b->field;
269858ebd649SToby Isaac   }
269958ebd649SToby Isaac   if (numcomps) {
270058ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
270158ebd649SToby Isaac     *numcomps = b->numcomps;
270258ebd649SToby Isaac   }
270358ebd649SToby Isaac   if (comps) {
270458ebd649SToby Isaac     PetscValidPointer(comps, 8);
270558ebd649SToby Isaac     *comps = b->comps;
270658ebd649SToby Isaac   }
270758ebd649SToby Isaac   if (func) {
270858ebd649SToby Isaac     PetscValidPointer(func, 9);
270958ebd649SToby Isaac     *func = b->func;
271058ebd649SToby Isaac   }
271158ebd649SToby Isaac   if (numids) {
271258ebd649SToby Isaac     PetscValidPointer(numids, 10);
271358ebd649SToby Isaac     *numids = b->numids;
271458ebd649SToby Isaac   }
271558ebd649SToby Isaac   if (ids) {
271658ebd649SToby Isaac     PetscValidPointer(ids, 11);
271758ebd649SToby Isaac     *ids = b->ids;
271858ebd649SToby Isaac   }
271958ebd649SToby Isaac   if (ctx) {
272058ebd649SToby Isaac     PetscValidPointer(ctx, 12);
272158ebd649SToby Isaac     *ctx = b->ctx;
272258ebd649SToby Isaac   }
272358ebd649SToby Isaac   PetscFunctionReturn(0);
272458ebd649SToby Isaac }
272558ebd649SToby Isaac 
272658ebd649SToby Isaac #undef __FUNCT__
2727dff059c6SToby Isaac #define __FUNCT__ "PetscDSCopyBoundary"
2728dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB)
2729dff059c6SToby Isaac {
2730dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
2731dff059c6SToby Isaac   PetscErrorCode ierr;
2732dff059c6SToby Isaac 
2733dff059c6SToby Isaac   PetscFunctionBegin;
2734dff059c6SToby Isaac   PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1);
2735dff059c6SToby Isaac   PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2);
2736dff059c6SToby Isaac   if (probA == probB) PetscFunctionReturn(0);
2737dff059c6SToby Isaac   next = probB->boundary;
2738dff059c6SToby Isaac   while (next) {
2739dff059c6SToby Isaac     DSBoundary b = next;
2740dff059c6SToby Isaac 
2741dff059c6SToby Isaac     next = b->next;
2742dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2743dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2744dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
2745dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2746dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
2747dff059c6SToby Isaac   }
2748dff059c6SToby Isaac   lastnext = &(probB->boundary);
2749dff059c6SToby Isaac   for (b = probA->boundary; b; b = b->next) {
2750dff059c6SToby Isaac     DSBoundary bNew;
2751dff059c6SToby Isaac 
2752dff059c6SToby Isaac     ierr = PetscNew(&bNew);
2753dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
2754dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
2755dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr);
2756dff059c6SToby Isaac     bNew->numids = b->numids;
2757dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
2758dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr);
2759dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
2760dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
2761dff059c6SToby Isaac     bNew->ctx       = b->ctx;
2762dff059c6SToby Isaac     bNew->essential = b->essential;
2763dff059c6SToby Isaac     bNew->field     = b->field;
2764dff059c6SToby Isaac     bNew->func      = b->func;
2765dff059c6SToby Isaac 
2766dff059c6SToby Isaac     *lastnext = bNew;
2767dff059c6SToby Isaac     lastnext = &(bNew->next);
2768dff059c6SToby Isaac   }
2769dff059c6SToby Isaac   PetscFunctionReturn(0);
2770dff059c6SToby Isaac }
2771dff059c6SToby Isaac 
2772dff059c6SToby Isaac #undef __FUNCT__
2773da51fcedSMatthew G. Knepley #define __FUNCT__ "PetscDSCopyEquations"
2774da51fcedSMatthew G. Knepley /*@
2775da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
2776da51fcedSMatthew G. Knepley 
2777da51fcedSMatthew G. Knepley   Not collective
2778da51fcedSMatthew G. Knepley 
2779da51fcedSMatthew G. Knepley   Input Parameter:
2780da51fcedSMatthew G. Knepley . prob - The PetscDS object
2781da51fcedSMatthew G. Knepley 
2782da51fcedSMatthew G. Knepley   Output Parameter:
2783da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
2784da51fcedSMatthew G. Knepley 
2785da51fcedSMatthew G. Knepley   Level: intermediate
2786da51fcedSMatthew G. Knepley 
2787da51fcedSMatthew G. Knepley .seealso: PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
2788da51fcedSMatthew G. Knepley @*/
2789da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
2790da51fcedSMatthew G. Knepley {
2791da51fcedSMatthew G. Knepley   PetscInt       Nf, Ng, f, g;
2792da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
2793da51fcedSMatthew G. Knepley 
2794da51fcedSMatthew G. Knepley   PetscFunctionBegin;
2795da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2796da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
2797da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
2798da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
2799da51fcedSMatthew G. Knepley   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);CHKERRQ(ierr);
2800da51fcedSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
2801da51fcedSMatthew G. Knepley     PetscPointFunc   obj;
2802da51fcedSMatthew G. Knepley     PetscPointFunc   f0, f1;
2803da51fcedSMatthew G. Knepley     PetscPointJac    g0, g1, g2, g3;
2804da51fcedSMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
2805da51fcedSMatthew G. Knepley     PetscBdPointJac  g0Bd, g1Bd, g2Bd, g3Bd;
2806da51fcedSMatthew G. Knepley     PetscRiemannFunc r;
2807da51fcedSMatthew G. Knepley 
2808da51fcedSMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
2809da51fcedSMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
2810da51fcedSMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
2811da51fcedSMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
2812da51fcedSMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, f, obj);CHKERRQ(ierr);
2813da51fcedSMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, f, f0, f1);CHKERRQ(ierr);
2814da51fcedSMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, f, f0Bd, f1Bd);CHKERRQ(ierr);
2815da51fcedSMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, f, r);CHKERRQ(ierr);
2816da51fcedSMatthew G. Knepley     for (g = 0; g < Nf; ++g) {
2817da51fcedSMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
2818da51fcedSMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
2819da51fcedSMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, f, g, g0, g1, g2, g3);CHKERRQ(ierr);
2820da51fcedSMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, f, g, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
2821da51fcedSMatthew G. Knepley     }
2822da51fcedSMatthew G. Knepley   }
2823da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
2824da51fcedSMatthew G. Knepley }
2825da51fcedSMatthew G. Knepley 
2826da51fcedSMatthew G. Knepley #undef __FUNCT__
28272764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroy_Basic"
2828bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob)
28292764a2aaSMatthew G. Knepley {
2830931fb3b8SToby Isaac   PetscErrorCode      ierr;
2831931fb3b8SToby Isaac 
28322764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2833931fb3b8SToby Isaac   ierr = PetscFree(prob->data);CHKERRQ(ierr);
28342764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28352764a2aaSMatthew G. Knepley }
28362764a2aaSMatthew G. Knepley 
28372764a2aaSMatthew G. Knepley #undef __FUNCT__
28382764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSInitialize_Basic"
2839bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob)
28402764a2aaSMatthew G. Knepley {
28412764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28422764a2aaSMatthew G. Knepley   prob->ops->setfromoptions = NULL;
28432764a2aaSMatthew G. Knepley   prob->ops->setup          = NULL;
28442764a2aaSMatthew G. Knepley   prob->ops->view           = NULL;
28452764a2aaSMatthew G. Knepley   prob->ops->destroy        = PetscDSDestroy_Basic;
28462764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28472764a2aaSMatthew G. Knepley }
28482764a2aaSMatthew G. Knepley 
28492764a2aaSMatthew G. Knepley /*MC
28502764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
28512764a2aaSMatthew G. Knepley 
28522764a2aaSMatthew G. Knepley   Level: intermediate
28532764a2aaSMatthew G. Knepley 
28542764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
28552764a2aaSMatthew G. Knepley M*/
28562764a2aaSMatthew G. Knepley 
28572764a2aaSMatthew G. Knepley #undef __FUNCT__
28582764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSCreate_Basic"
28592764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob)
28602764a2aaSMatthew G. Knepley {
28612764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
28622764a2aaSMatthew G. Knepley   PetscErrorCode      ierr;
28632764a2aaSMatthew G. Knepley 
28642764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2865931fb3b8SToby Isaac   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28662764a2aaSMatthew G. Knepley   ierr       = PetscNewLog(prob, &b);CHKERRQ(ierr);
28672764a2aaSMatthew G. Knepley   prob->data = b;
28682764a2aaSMatthew G. Knepley 
28692764a2aaSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr);
28702764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28712764a2aaSMatthew G. Knepley }
2872