xref: /petsc/src/dm/dt/interface/dtds.c (revision 2d47a1893579915dae92dcad7c12483b1cda8a0c)
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     }
254e7b0402cSSander Arens     len = 1024;
255f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
256f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
257f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
258f1fd5e65SToby Isaac     if (flg) {
259f1fd5e65SToby Isaac       b->numcomps = len;
260f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
261f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
262f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->comps, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
263f1fd5e65SToby Isaac     }
264f1fd5e65SToby Isaac   }
2652764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
2662764a2aaSMatthew G. Knepley   if (flg) {
2672764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
2682764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
2692764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
2702764a2aaSMatthew G. Knepley   }
2712764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
2722764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
2730633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
2742764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
2752764a2aaSMatthew G. Knepley   ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);
2762764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2772764a2aaSMatthew G. Knepley }
2782764a2aaSMatthew G. Knepley 
2792764a2aaSMatthew G. Knepley #undef __FUNCT__
2802764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetUp"
2812764a2aaSMatthew G. Knepley /*@C
2822764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
2832764a2aaSMatthew G. Knepley 
2842764a2aaSMatthew G. Knepley   Collective on PetscDS
2852764a2aaSMatthew G. Knepley 
2862764a2aaSMatthew G. Knepley   Input Parameter:
2872764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
2882764a2aaSMatthew G. Knepley 
2892764a2aaSMatthew G. Knepley   Level: developer
2902764a2aaSMatthew G. Knepley 
2912764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
2922764a2aaSMatthew G. Knepley @*/
2932764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
2942764a2aaSMatthew G. Knepley {
2952764a2aaSMatthew G. Knepley   const PetscInt Nf = prob->Nf;
2962764a2aaSMatthew G. Knepley   PetscInt       dim, work, NcMax = 0, NqMax = 0, f;
2972764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2982764a2aaSMatthew G. Knepley 
2992764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3002764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3012764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3022764a2aaSMatthew G. Knepley   /* Calculate sizes */
3032764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
304f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
30547e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
306f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
307f744cafaSSander Arens   ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisFace,Nf,&prob->basisDerFace);CHKERRQ(ierr);
3082764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++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);
3234d0b9603SSander Arens       ierr = PetscFEGetFaceTabulation(fe, &prob->basisFace[f], &prob->basisDerFace[f], NULL);CHKERRQ(ierr);
3249de99aefSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
3259de99aefSMatthew G. Knepley       PetscFV fv = (PetscFV) obj;
3269de99aefSMatthew G. Knepley 
3279de99aefSMatthew G. Knepley       ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
3289de99aefSMatthew G. Knepley       Nb   = 1;
3299de99aefSMatthew G. Knepley       ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
3306c1a3d01SMatthew G. Knepley       ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3314d0b9603SSander Arens       /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
332abac5ca0SMatthew G. Knepley     } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
33347e57110SSander Arens     prob->Nc[f]       = Nc;
33447e57110SSander Arens     prob->Nb[f]       = Nb;
335194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
336194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
3379de99aefSMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
3382764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
3392764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
3402764a2aaSMatthew G. Knepley     prob->totDim  += Nb*Nc;
3412764a2aaSMatthew G. Knepley     prob->totComp += Nc;
3422764a2aaSMatthew G. Knepley   }
3432764a2aaSMatthew G. Knepley   work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim));
3442764a2aaSMatthew G. Knepley   /* Allocate works space */
3452764a2aaSMatthew 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);
3462764a2aaSMatthew 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);
3472764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
3482764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
3492764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3502764a2aaSMatthew G. Knepley }
3512764a2aaSMatthew G. Knepley 
3522764a2aaSMatthew G. Knepley #undef __FUNCT__
3532764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroyStructs_Static"
3542764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
3552764a2aaSMatthew G. Knepley {
3562764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3572764a2aaSMatthew G. Knepley 
3582764a2aaSMatthew G. Knepley   PetscFunctionBegin;
35947e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
360f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
361f744cafaSSander Arens   ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisFace,prob->basisDerFace);CHKERRQ(ierr);
3622764a2aaSMatthew G. Knepley   ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr);
3632764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
3642764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3652764a2aaSMatthew G. Knepley }
3662764a2aaSMatthew G. Knepley 
3672764a2aaSMatthew G. Knepley #undef __FUNCT__
3682764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSEnlarge_Static"
3692764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
3702764a2aaSMatthew G. Knepley {
371f744cafaSSander Arens   PetscObject      *tmpd;
372a6cbbb48SMatthew G. Knepley   PetscBool        *tmpi, *tmpa;
3732aa1fc23SMatthew G. Knepley   PetscPointFunc   *tmpobj, *tmpf;
374b7e05686SMatthew G. Knepley   PetscPointJac    *tmpg, *tmpgp, *tmpgt;
3752aa1fc23SMatthew G. Knepley   PetscBdPointFunc *tmpfbd;
3762aa1fc23SMatthew G. Knepley   PetscBdPointJac  *tmpgbd;
377194d53e6SMatthew G. Knepley   PetscRiemannFunc *tmpr;
3780c2f2876SMatthew G. Knepley   void            **tmpctx;
379a6cbbb48SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f, i;
3802764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
3812764a2aaSMatthew G. Knepley 
3822764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3832764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
3842764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
3852764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
386f744cafaSSander Arens   ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr);
387f744cafaSSander Arens   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; for (i = 0; i < 2; ++i) tmpa[f*2+i] = prob->adjacency[f*2+i];}
388f744cafaSSander Arens   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpa[f*2+0] = PETSC_FALSE; tmpa[f*2+1] = PETSC_TRUE;}
389f744cafaSSander Arens   ierr = PetscFree3(prob->disc, prob->implicit, prob->adjacency);CHKERRQ(ierr);
3902764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
3912764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
392249df284SMatthew G. Knepley   prob->implicit  = tmpi;
393a6cbbb48SMatthew G. Knepley   prob->adjacency = tmpa;
394b7e05686SMatthew 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);
3952764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f];
3962764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f];
3972764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f];
398475e0ac9SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f];
3990c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f];
4000c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
4012764a2aaSMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL;
4022764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL;
4032764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL;
404475e0ac9SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL;
405b7e05686SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL;
4060c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL;
4070c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
408b7e05686SMatthew G. Knepley   ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr);
4092764a2aaSMatthew G. Knepley   prob->obj = tmpobj;
4102764a2aaSMatthew G. Knepley   prob->f   = tmpf;
4112764a2aaSMatthew G. Knepley   prob->g   = tmpg;
412475e0ac9SMatthew G. Knepley   prob->gp  = tmpgp;
413b7e05686SMatthew G. Knepley   prob->gt  = tmpgt;
4140c2f2876SMatthew G. Knepley   prob->r   = tmpr;
4150c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
4162764a2aaSMatthew G. Knepley   ierr = PetscCalloc2(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd);CHKERRQ(ierr);
4172764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f];
4182764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f];
4192764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL;
4202764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL;
4212764a2aaSMatthew G. Knepley   ierr = PetscFree2(prob->fBd, prob->gBd);CHKERRQ(ierr);
4222764a2aaSMatthew G. Knepley   prob->fBd = tmpfbd;
4232764a2aaSMatthew G. Knepley   prob->gBd = tmpgbd;
4242764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4252764a2aaSMatthew G. Knepley }
4262764a2aaSMatthew G. Knepley 
4272764a2aaSMatthew G. Knepley #undef __FUNCT__
4282764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroy"
4292764a2aaSMatthew G. Knepley /*@
4302764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
4312764a2aaSMatthew G. Knepley 
4322764a2aaSMatthew G. Knepley   Collective on PetscDS
4332764a2aaSMatthew G. Knepley 
4342764a2aaSMatthew G. Knepley   Input Parameter:
4352764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
4362764a2aaSMatthew G. Knepley 
4372764a2aaSMatthew G. Knepley   Level: developer
4382764a2aaSMatthew G. Knepley 
4392764a2aaSMatthew G. Knepley .seealso PetscDSView()
4402764a2aaSMatthew G. Knepley @*/
4412764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob)
4422764a2aaSMatthew G. Knepley {
4432764a2aaSMatthew G. Knepley   PetscInt       f;
44458ebd649SToby Isaac   DSBoundary     next;
4452764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4462764a2aaSMatthew G. Knepley 
4472764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4482764a2aaSMatthew G. Knepley   if (!*prob) PetscFunctionReturn(0);
4492764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1);
4502764a2aaSMatthew G. Knepley 
4512764a2aaSMatthew G. Knepley   if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);}
4522764a2aaSMatthew G. Knepley   ((PetscObject) (*prob))->refct = 0;
4532764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr);
4542764a2aaSMatthew G. Knepley   for (f = 0; f < (*prob)->Nf; ++f) {
4552764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr);
4562764a2aaSMatthew G. Knepley   }
457f744cafaSSander Arens   ierr = PetscFree3((*prob)->disc, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr);
458b7e05686SMatthew G. Knepley   ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr);
4592764a2aaSMatthew G. Knepley   ierr = PetscFree2((*prob)->fBd,(*prob)->gBd);CHKERRQ(ierr);
4602764a2aaSMatthew G. Knepley   if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);}
46158ebd649SToby Isaac   next = (*prob)->boundary;
46258ebd649SToby Isaac   while (next) {
46358ebd649SToby Isaac     DSBoundary b = next;
46458ebd649SToby Isaac 
46558ebd649SToby Isaac     next = b->next;
46658ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
46758ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
46858ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
46958ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
47058ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
47158ebd649SToby Isaac   }
4722764a2aaSMatthew G. Knepley   ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr);
4732764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4742764a2aaSMatthew G. Knepley }
4752764a2aaSMatthew G. Knepley 
4762764a2aaSMatthew G. Knepley #undef __FUNCT__
4772764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSCreate"
4782764a2aaSMatthew G. Knepley /*@
4792764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
4802764a2aaSMatthew G. Knepley 
4812764a2aaSMatthew G. Knepley   Collective on MPI_Comm
4822764a2aaSMatthew G. Knepley 
4832764a2aaSMatthew G. Knepley   Input Parameter:
4842764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
4852764a2aaSMatthew G. Knepley 
4862764a2aaSMatthew G. Knepley   Output Parameter:
4872764a2aaSMatthew G. Knepley . prob - The PetscDS object
4882764a2aaSMatthew G. Knepley 
4892764a2aaSMatthew G. Knepley   Level: beginner
4902764a2aaSMatthew G. Knepley 
4912764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
4922764a2aaSMatthew G. Knepley @*/
4932764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob)
4942764a2aaSMatthew G. Knepley {
4952764a2aaSMatthew G. Knepley   PetscDS   p;
4962764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4972764a2aaSMatthew G. Knepley 
4982764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4992764a2aaSMatthew G. Knepley   PetscValidPointer(prob, 2);
5002764a2aaSMatthew G. Knepley   *prob  = NULL;
5012764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5022764a2aaSMatthew G. Knepley 
50373107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5042764a2aaSMatthew G. Knepley 
5052764a2aaSMatthew G. Knepley   p->Nf    = 0;
5062764a2aaSMatthew G. Knepley   p->setup = PETSC_FALSE;
5072764a2aaSMatthew G. Knepley 
5082764a2aaSMatthew G. Knepley   *prob = p;
5092764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5102764a2aaSMatthew G. Knepley }
5112764a2aaSMatthew G. Knepley 
5122764a2aaSMatthew G. Knepley #undef __FUNCT__
5132764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetNumFields"
514bc4ae4beSMatthew G. Knepley /*@
515bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
516bc4ae4beSMatthew G. Knepley 
517bc4ae4beSMatthew G. Knepley   Not collective
518bc4ae4beSMatthew G. Knepley 
519bc4ae4beSMatthew G. Knepley   Input Parameter:
520bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
521bc4ae4beSMatthew G. Knepley 
522bc4ae4beSMatthew G. Knepley   Output Parameter:
523bc4ae4beSMatthew G. Knepley . Nf - The number of fields
524bc4ae4beSMatthew G. Knepley 
525bc4ae4beSMatthew G. Knepley   Level: beginner
526bc4ae4beSMatthew G. Knepley 
527bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
528bc4ae4beSMatthew G. Knepley @*/
5292764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
5302764a2aaSMatthew G. Knepley {
5312764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5322764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5332764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
5342764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
5352764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5362764a2aaSMatthew G. Knepley }
5372764a2aaSMatthew G. Knepley 
5382764a2aaSMatthew G. Knepley #undef __FUNCT__
5392764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetSpatialDimension"
540bc4ae4beSMatthew G. Knepley /*@
541bc4ae4beSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS
542bc4ae4beSMatthew G. Knepley 
543bc4ae4beSMatthew G. Knepley   Not collective
544bc4ae4beSMatthew G. Knepley 
545bc4ae4beSMatthew G. Knepley   Input Parameter:
546bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
547bc4ae4beSMatthew G. Knepley 
548bc4ae4beSMatthew G. Knepley   Output Parameter:
549bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
550bc4ae4beSMatthew G. Knepley 
551bc4ae4beSMatthew G. Knepley   Level: beginner
552bc4ae4beSMatthew G. Knepley 
553bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
554bc4ae4beSMatthew G. Knepley @*/
5552764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
5562764a2aaSMatthew G. Knepley {
5572764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5582764a2aaSMatthew G. Knepley 
5592764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5602764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5612764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
5622764a2aaSMatthew G. Knepley   *dim = 0;
5639de99aefSMatthew G. Knepley   if (prob->Nf) {
5649de99aefSMatthew G. Knepley     PetscObject  obj;
5659de99aefSMatthew G. Knepley     PetscClassId id;
5669de99aefSMatthew G. Knepley 
5679de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
5689de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
5699de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
5709de99aefSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
5719de99aefSMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
5729de99aefSMatthew G. Knepley   }
5732764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5742764a2aaSMatthew G. Knepley }
5752764a2aaSMatthew G. Knepley 
5762764a2aaSMatthew G. Knepley #undef __FUNCT__
5772764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalDimension"
578bc4ae4beSMatthew G. Knepley /*@
579bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
580bc4ae4beSMatthew G. Knepley 
581bc4ae4beSMatthew G. Knepley   Not collective
582bc4ae4beSMatthew G. Knepley 
583bc4ae4beSMatthew G. Knepley   Input Parameter:
584bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
585bc4ae4beSMatthew G. Knepley 
586bc4ae4beSMatthew G. Knepley   Output Parameter:
587bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
588bc4ae4beSMatthew G. Knepley 
589bc4ae4beSMatthew G. Knepley   Level: beginner
590bc4ae4beSMatthew G. Knepley 
591bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
592bc4ae4beSMatthew G. Knepley @*/
5932764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
5942764a2aaSMatthew G. Knepley {
5952764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5962764a2aaSMatthew G. Knepley 
5972764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5982764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5992764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6002764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6012764a2aaSMatthew G. Knepley   *dim = prob->totDim;
6022764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6032764a2aaSMatthew G. Knepley }
6042764a2aaSMatthew G. Knepley 
6052764a2aaSMatthew G. Knepley #undef __FUNCT__
6062764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTotalComponents"
607bc4ae4beSMatthew G. Knepley /*@
608bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
609bc4ae4beSMatthew G. Knepley 
610bc4ae4beSMatthew G. Knepley   Not collective
611bc4ae4beSMatthew G. Knepley 
612bc4ae4beSMatthew G. Knepley   Input Parameter:
613bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
614bc4ae4beSMatthew G. Knepley 
615bc4ae4beSMatthew G. Knepley   Output Parameter:
616bc4ae4beSMatthew G. Knepley . dim - The total number of components
617bc4ae4beSMatthew G. Knepley 
618bc4ae4beSMatthew G. Knepley   Level: beginner
619bc4ae4beSMatthew G. Knepley 
620bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
621bc4ae4beSMatthew G. Knepley @*/
6222764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
6232764a2aaSMatthew G. Knepley {
6242764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6252764a2aaSMatthew G. Knepley 
6262764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6272764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6282764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6292764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
6302764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
6312764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6322764a2aaSMatthew G. Knepley }
6332764a2aaSMatthew G. Knepley 
6342764a2aaSMatthew G. Knepley #undef __FUNCT__
6352764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetDiscretization"
636bc4ae4beSMatthew G. Knepley /*@
637bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
638bc4ae4beSMatthew G. Knepley 
639bc4ae4beSMatthew G. Knepley   Not collective
640bc4ae4beSMatthew G. Knepley 
641bc4ae4beSMatthew G. Knepley   Input Parameters:
642bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
643bc4ae4beSMatthew G. Knepley - f - The field number
644bc4ae4beSMatthew G. Knepley 
645bc4ae4beSMatthew G. Knepley   Output Parameter:
646bc4ae4beSMatthew G. Knepley . disc - The discretization object
647bc4ae4beSMatthew G. Knepley 
648bc4ae4beSMatthew G. Knepley   Level: beginner
649bc4ae4beSMatthew G. Knepley 
650f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
651bc4ae4beSMatthew G. Knepley @*/
6522764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
6532764a2aaSMatthew G. Knepley {
6542764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6552764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6562764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
6572764a2aaSMatthew 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);
6582764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
6592764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6602764a2aaSMatthew G. Knepley }
6612764a2aaSMatthew G. Knepley 
6622764a2aaSMatthew G. Knepley #undef __FUNCT__
6632764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetDiscretization"
664bc4ae4beSMatthew G. Knepley /*@
665bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
666bc4ae4beSMatthew G. Knepley 
667bc4ae4beSMatthew G. Knepley   Not collective
668bc4ae4beSMatthew G. Knepley 
669bc4ae4beSMatthew G. Knepley   Input Parameters:
670bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
671bc4ae4beSMatthew G. Knepley . f - The field number
672bc4ae4beSMatthew G. Knepley - disc - The discretization object
673bc4ae4beSMatthew G. Knepley 
674bc4ae4beSMatthew G. Knepley   Level: beginner
675bc4ae4beSMatthew G. Knepley 
676bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
677bc4ae4beSMatthew G. Knepley @*/
6782764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
6792764a2aaSMatthew G. Knepley {
6802764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6812764a2aaSMatthew G. Knepley 
6822764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6832764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6842764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
6852764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
6862764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
6872764a2aaSMatthew G. Knepley   if (prob->disc[f]) {ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);}
6882764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
6892764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
690249df284SMatthew G. Knepley   {
691249df284SMatthew G. Knepley     PetscClassId id;
692249df284SMatthew G. Knepley 
693249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
694a6cbbb48SMatthew G. Knepley     if (id == PETSCFV_CLASSID) {
695a6cbbb48SMatthew G. Knepley       prob->implicit[f]      = PETSC_FALSE;
696a6cbbb48SMatthew G. Knepley       prob->adjacency[f*2+0] = PETSC_TRUE;
697a6cbbb48SMatthew G. Knepley       prob->adjacency[f*2+1] = PETSC_FALSE;
698a6cbbb48SMatthew G. Knepley     }
699249df284SMatthew G. Knepley   }
7002764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7012764a2aaSMatthew G. Knepley }
7022764a2aaSMatthew G. Knepley 
7032764a2aaSMatthew G. Knepley #undef __FUNCT__
7042764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSAddDiscretization"
705bc4ae4beSMatthew G. Knepley /*@
706bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
707bc4ae4beSMatthew G. Knepley 
708bc4ae4beSMatthew G. Knepley   Not collective
709bc4ae4beSMatthew G. Knepley 
710bc4ae4beSMatthew G. Knepley   Input Parameters:
711bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
712bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
713bc4ae4beSMatthew G. Knepley 
714bc4ae4beSMatthew G. Knepley   Level: beginner
715bc4ae4beSMatthew G. Knepley 
716bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
717bc4ae4beSMatthew G. Knepley @*/
7182764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
7192764a2aaSMatthew G. Knepley {
7202764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7212764a2aaSMatthew G. Knepley 
7222764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7232764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
7242764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7252764a2aaSMatthew G. Knepley }
7262764a2aaSMatthew G. Knepley 
7272764a2aaSMatthew G. Knepley #undef __FUNCT__
728249df284SMatthew G. Knepley #define __FUNCT__ "PetscDSGetImplicit"
729249df284SMatthew G. Knepley /*@
730249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
731249df284SMatthew G. Knepley 
732249df284SMatthew G. Knepley   Not collective
733249df284SMatthew G. Knepley 
734249df284SMatthew G. Knepley   Input Parameters:
735249df284SMatthew G. Knepley + prob - The PetscDS object
736249df284SMatthew G. Knepley - f - The field number
737249df284SMatthew G. Knepley 
738249df284SMatthew G. Knepley   Output Parameter:
739249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
740249df284SMatthew G. Knepley 
741249df284SMatthew G. Knepley   Level: developer
742249df284SMatthew G. Knepley 
743f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
744249df284SMatthew G. Knepley @*/
745249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
746249df284SMatthew G. Knepley {
747249df284SMatthew G. Knepley   PetscFunctionBegin;
748249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
749249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
750249df284SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
751249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
752249df284SMatthew G. Knepley   PetscFunctionReturn(0);
753249df284SMatthew G. Knepley }
754249df284SMatthew G. Knepley 
755249df284SMatthew G. Knepley #undef __FUNCT__
756249df284SMatthew G. Knepley #define __FUNCT__ "PetscDSSetImplicit"
757249df284SMatthew G. Knepley /*@
758249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
759249df284SMatthew G. Knepley 
760249df284SMatthew G. Knepley   Not collective
761249df284SMatthew G. Knepley 
762249df284SMatthew G. Knepley   Input Parameters:
763249df284SMatthew G. Knepley + prob - The PetscDS object
764249df284SMatthew G. Knepley . f - The field number
765249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
766249df284SMatthew G. Knepley 
767249df284SMatthew G. Knepley   Level: developer
768249df284SMatthew G. Knepley 
769f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
770249df284SMatthew G. Knepley @*/
771249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
772249df284SMatthew G. Knepley {
773249df284SMatthew G. Knepley   PetscFunctionBegin;
774249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
775249df284SMatthew 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);
776249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
777249df284SMatthew G. Knepley   PetscFunctionReturn(0);
778249df284SMatthew G. Knepley }
779249df284SMatthew G. Knepley 
780249df284SMatthew G. Knepley #undef __FUNCT__
781a6cbbb48SMatthew G. Knepley #define __FUNCT__ "PetscDSGetAdjacency"
782a6cbbb48SMatthew G. Knepley /*@
783a6cbbb48SMatthew G. Knepley   PetscDSGetAdjacency - Returns the flags for determining variable influence
784a6cbbb48SMatthew G. Knepley 
785a6cbbb48SMatthew G. Knepley   Not collective
786a6cbbb48SMatthew G. Knepley 
787a6cbbb48SMatthew G. Knepley   Input Parameters:
788a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
789a6cbbb48SMatthew G. Knepley - f - The field number
790a6cbbb48SMatthew G. Knepley 
791a6cbbb48SMatthew G. Knepley   Output Parameter:
792a6cbbb48SMatthew G. Knepley + useCone    - Flag for variable influence starting with the cone operation
793a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
794a6cbbb48SMatthew G. Knepley 
795a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
796a6cbbb48SMatthew G. Knepley 
797a6cbbb48SMatthew G. Knepley   Level: developer
798a6cbbb48SMatthew G. Knepley 
799f744cafaSSander Arens .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
800a6cbbb48SMatthew G. Knepley @*/
801a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure)
802a6cbbb48SMatthew G. Knepley {
803a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
804a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
805a6cbbb48SMatthew G. Knepley   PetscValidPointer(useCone, 3);
806a6cbbb48SMatthew G. Knepley   PetscValidPointer(useClosure, 4);
807a6cbbb48SMatthew G. Knepley   if ((f < 0) || (f >= prob->Nf)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
808a6cbbb48SMatthew G. Knepley   *useCone    = prob->adjacency[f*2+0];
809a6cbbb48SMatthew G. Knepley   *useClosure = prob->adjacency[f*2+1];
810a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
811a6cbbb48SMatthew G. Knepley }
812a6cbbb48SMatthew G. Knepley 
813a6cbbb48SMatthew G. Knepley #undef __FUNCT__
814a6cbbb48SMatthew G. Knepley #define __FUNCT__ "PetscDSSetAdjacency"
815a6cbbb48SMatthew G. Knepley /*@
816a6cbbb48SMatthew G. Knepley   PetscDSSetAdjacency - Set the flags for determining variable influence
817a6cbbb48SMatthew G. Knepley 
818a6cbbb48SMatthew G. Knepley   Not collective
819a6cbbb48SMatthew G. Knepley 
820a6cbbb48SMatthew G. Knepley   Input Parameters:
821a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
822a6cbbb48SMatthew G. Knepley . f - The field number
823a6cbbb48SMatthew G. Knepley . useCone    - Flag for variable influence starting with the cone operation
824a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
825a6cbbb48SMatthew G. Knepley 
826a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
827a6cbbb48SMatthew G. Knepley 
828a6cbbb48SMatthew G. Knepley   Level: developer
829a6cbbb48SMatthew G. Knepley 
830f744cafaSSander Arens .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
831a6cbbb48SMatthew G. Knepley @*/
832a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure)
833a6cbbb48SMatthew G. Knepley {
834a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
835a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
836a6cbbb48SMatthew 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);
837a6cbbb48SMatthew G. Knepley   prob->adjacency[f*2+0] = useCone;
838a6cbbb48SMatthew G. Knepley   prob->adjacency[f*2+1] = useClosure;
839a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
840a6cbbb48SMatthew G. Knepley }
841a6cbbb48SMatthew G. Knepley 
842a6cbbb48SMatthew G. Knepley #undef __FUNCT__
8432764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetObjective"
8442764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f,
84530b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
846194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
847194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
84830b9ff8bSMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscScalar obj[]))
8492764a2aaSMatthew G. Knepley {
8502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8512764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8522764a2aaSMatthew G. Knepley   PetscValidPointer(obj, 2);
8532764a2aaSMatthew 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);
8542764a2aaSMatthew G. Knepley   *obj = prob->obj[f];
8552764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8562764a2aaSMatthew G. Knepley }
8572764a2aaSMatthew G. Knepley 
8582764a2aaSMatthew G. Knepley #undef __FUNCT__
8592764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetObjective"
8602764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f,
86130b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
862194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
863194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
86430b9ff8bSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscScalar obj[]))
8652764a2aaSMatthew G. Knepley {
8662764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8672764a2aaSMatthew G. Knepley 
8682764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8692764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
870de716cbcSToby Isaac   if (obj) PetscValidFunction(obj, 2);
8712764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
8722764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
8732764a2aaSMatthew G. Knepley   prob->obj[f] = obj;
8742764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8752764a2aaSMatthew G. Knepley }
8762764a2aaSMatthew G. Knepley 
8772764a2aaSMatthew G. Knepley #undef __FUNCT__
8782764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetResidual"
879194d53e6SMatthew G. Knepley /*@C
880194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
881194d53e6SMatthew G. Knepley 
882194d53e6SMatthew G. Knepley   Not collective
883194d53e6SMatthew G. Knepley 
884194d53e6SMatthew G. Knepley   Input Parameters:
885194d53e6SMatthew G. Knepley + prob - The PetscDS
886194d53e6SMatthew G. Knepley - f    - The test field number
887194d53e6SMatthew G. Knepley 
888194d53e6SMatthew G. Knepley   Output Parameters:
889194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
890194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
891194d53e6SMatthew G. Knepley 
892194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
893194d53e6SMatthew G. Knepley 
894194d53e6SMatthew 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)
895194d53e6SMatthew G. Knepley 
896194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
897194d53e6SMatthew G. Knepley 
89830b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
899194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
900194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
90130b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
902194d53e6SMatthew G. Knepley 
903194d53e6SMatthew G. Knepley + dim - the spatial dimension
904194d53e6SMatthew G. Knepley . Nf - the number of fields
905194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
906194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
907194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
908194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
909194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
910194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
911194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
912194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
913194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
914194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
915194d53e6SMatthew G. Knepley . t - current time
916194d53e6SMatthew G. Knepley . x - coordinates of the current point
917194d53e6SMatthew G. Knepley - f0 - output values at the current point
918194d53e6SMatthew G. Knepley 
919194d53e6SMatthew G. Knepley   Level: intermediate
920194d53e6SMatthew G. Knepley 
921194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
922194d53e6SMatthew G. Knepley @*/
9232764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f,
92430b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
925194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
926194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
92730b9ff8bSMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscScalar f0[]),
92830b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
929194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
930194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
93130b9ff8bSMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscScalar f1[]))
9322764a2aaSMatthew G. Knepley {
9332764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9342764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9352764a2aaSMatthew 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);
9362764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];}
9372764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];}
9382764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9392764a2aaSMatthew G. Knepley }
9402764a2aaSMatthew G. Knepley 
9412764a2aaSMatthew G. Knepley #undef __FUNCT__
9422764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetResidual"
943194d53e6SMatthew G. Knepley /*@C
944194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
945194d53e6SMatthew G. Knepley 
946194d53e6SMatthew G. Knepley   Not collective
947194d53e6SMatthew G. Knepley 
948194d53e6SMatthew G. Knepley   Input Parameters:
949194d53e6SMatthew G. Knepley + prob - The PetscDS
950194d53e6SMatthew G. Knepley . f    - The test field number
951194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
952194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
953194d53e6SMatthew G. Knepley 
954194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
955194d53e6SMatthew G. Knepley 
956194d53e6SMatthew 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)
957194d53e6SMatthew G. Knepley 
958194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
959194d53e6SMatthew G. Knepley 
96030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
961194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
962194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
96330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
964194d53e6SMatthew G. Knepley 
965194d53e6SMatthew G. Knepley + dim - the spatial dimension
966194d53e6SMatthew G. Knepley . Nf - the number of fields
967194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
968194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
969194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
970194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
971194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
972194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
973194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
974194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
975194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
976194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
977194d53e6SMatthew G. Knepley . t - current time
978194d53e6SMatthew G. Knepley . x - coordinates of the current point
979194d53e6SMatthew G. Knepley - f0 - output values at the current point
980194d53e6SMatthew G. Knepley 
981194d53e6SMatthew G. Knepley   Level: intermediate
982194d53e6SMatthew G. Knepley 
983194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
984194d53e6SMatthew G. Knepley @*/
9852764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f,
98630b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
987194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
988194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
98930b9ff8bSMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscScalar f0[]),
99030b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
991194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
992194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
99330b9ff8bSMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscScalar f1[]))
9942764a2aaSMatthew G. Knepley {
9952764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9962764a2aaSMatthew G. Knepley 
9972764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9982764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
999f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1000f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
10012764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
10022764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
10032764a2aaSMatthew G. Knepley   prob->f[f*2+0] = f0;
10042764a2aaSMatthew G. Knepley   prob->f[f*2+1] = f1;
10052764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10062764a2aaSMatthew G. Knepley }
10072764a2aaSMatthew G. Knepley 
10082764a2aaSMatthew G. Knepley #undef __FUNCT__
10093e75805dSMatthew G. Knepley #define __FUNCT__ "PetscDSHasJacobian"
10103e75805dSMatthew G. Knepley /*@C
10113e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
10123e75805dSMatthew G. Knepley 
10133e75805dSMatthew G. Knepley   Not collective
10143e75805dSMatthew G. Knepley 
10153e75805dSMatthew G. Knepley   Input Parameter:
10163e75805dSMatthew G. Knepley . prob - The PetscDS
10173e75805dSMatthew G. Knepley 
10183e75805dSMatthew G. Knepley   Output Parameter:
10193e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
10203e75805dSMatthew G. Knepley 
10213e75805dSMatthew G. Knepley   Level: intermediate
10223e75805dSMatthew G. Knepley 
10233e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
10243e75805dSMatthew G. Knepley @*/
10253e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac)
10263e75805dSMatthew G. Knepley {
10273e75805dSMatthew G. Knepley   PetscInt f, g, h;
10283e75805dSMatthew G. Knepley 
10293e75805dSMatthew G. Knepley   PetscFunctionBegin;
10303e75805dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10313e75805dSMatthew G. Knepley   *hasJac = PETSC_FALSE;
10323e75805dSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
10333e75805dSMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
10343e75805dSMatthew G. Knepley       for (h = 0; h < 4; ++h) {
10353e75805dSMatthew G. Knepley         if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE;
10363e75805dSMatthew G. Knepley       }
10373e75805dSMatthew G. Knepley     }
10383e75805dSMatthew G. Knepley   }
10393e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
10403e75805dSMatthew G. Knepley }
10413e75805dSMatthew G. Knepley 
10423e75805dSMatthew G. Knepley #undef __FUNCT__
10432764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetJacobian"
1044194d53e6SMatthew G. Knepley /*@C
1045194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1046194d53e6SMatthew G. Knepley 
1047194d53e6SMatthew G. Knepley   Not collective
1048194d53e6SMatthew G. Knepley 
1049194d53e6SMatthew G. Knepley   Input Parameters:
1050194d53e6SMatthew G. Knepley + prob - The PetscDS
1051194d53e6SMatthew G. Knepley . f    - The test field number
1052194d53e6SMatthew G. Knepley - g    - The field number
1053194d53e6SMatthew G. Knepley 
1054194d53e6SMatthew G. Knepley   Output Parameters:
1055194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1056194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1057194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1058194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1059194d53e6SMatthew G. Knepley 
1060194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1061194d53e6SMatthew G. Knepley 
1062194d53e6SMatthew 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
1063194d53e6SMatthew G. Knepley 
1064194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1065194d53e6SMatthew G. Knepley 
106630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1067194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1068194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
106930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1070194d53e6SMatthew G. Knepley 
1071194d53e6SMatthew G. Knepley + dim - the spatial dimension
1072194d53e6SMatthew G. Knepley . Nf - the number of fields
1073194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1074194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1075194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1076194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1077194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1078194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1079194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1080194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1081194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1082194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1083194d53e6SMatthew G. Knepley . t - current time
10842aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1085194d53e6SMatthew G. Knepley . x - coordinates of the current point
1086194d53e6SMatthew G. Knepley - g0 - output values at the current point
1087194d53e6SMatthew G. Knepley 
1088194d53e6SMatthew G. Knepley   Level: intermediate
1089194d53e6SMatthew G. Knepley 
1090194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1091194d53e6SMatthew G. Knepley @*/
10922764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g,
109330b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1094194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1095194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
10962aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
109730b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1098194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1099194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
11002aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
110130b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1102194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1103194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
11042aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
110530b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1106194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1107194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
11082aa1fc23SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
11092764a2aaSMatthew G. Knepley {
11102764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11112764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11122764a2aaSMatthew 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);
11132764a2aaSMatthew 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);
11142764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];}
11152764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];}
11162764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];}
11172764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];}
11182764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11192764a2aaSMatthew G. Knepley }
11202764a2aaSMatthew G. Knepley 
11212764a2aaSMatthew G. Knepley #undef __FUNCT__
11222764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetJacobian"
1123194d53e6SMatthew G. Knepley /*@C
1124194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1125194d53e6SMatthew G. Knepley 
1126194d53e6SMatthew G. Knepley   Not collective
1127194d53e6SMatthew G. Knepley 
1128194d53e6SMatthew G. Knepley   Input Parameters:
1129194d53e6SMatthew G. Knepley + prob - The PetscDS
1130194d53e6SMatthew G. Knepley . f    - The test field number
1131194d53e6SMatthew G. Knepley . g    - The field number
1132194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1133194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1134194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1135194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1136194d53e6SMatthew G. Knepley 
1137194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1138194d53e6SMatthew G. Knepley 
1139194d53e6SMatthew 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
1140194d53e6SMatthew G. Knepley 
1141194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1142194d53e6SMatthew G. Knepley 
114330b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1144194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1145194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
114630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1147194d53e6SMatthew G. Knepley 
1148194d53e6SMatthew G. Knepley + dim - the spatial dimension
1149194d53e6SMatthew G. Knepley . Nf - the number of fields
1150194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1151194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1152194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1153194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1154194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1155194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1156194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1157194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1158194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1159194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1160194d53e6SMatthew G. Knepley . t - current time
11612aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1162194d53e6SMatthew G. Knepley . x - coordinates of the current point
1163194d53e6SMatthew G. Knepley - g0 - output values at the current point
1164194d53e6SMatthew G. Knepley 
1165194d53e6SMatthew G. Knepley   Level: intermediate
1166194d53e6SMatthew G. Knepley 
1167194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1168194d53e6SMatthew G. Knepley @*/
11692764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g,
117030b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1171194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1172194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117330b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
117430b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1175194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1176194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117730b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
117830b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1179194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1180194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
118130b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
118230b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1183194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1184194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
118530b9ff8bSMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
11862764a2aaSMatthew G. Knepley {
11872764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
11882764a2aaSMatthew G. Knepley 
11892764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11902764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11912764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
11922764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
11932764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
11942764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
11952764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
11962764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
11972764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
11982764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+0] = g0;
11992764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+1] = g1;
12002764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+2] = g2;
12012764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+3] = g3;
12022764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12032764a2aaSMatthew G. Knepley }
12042764a2aaSMatthew G. Knepley 
12052764a2aaSMatthew G. Knepley #undef __FUNCT__
1206475e0ac9SMatthew G. Knepley #define __FUNCT__ "PetscDSHasJacobianPreconditioner"
1207475e0ac9SMatthew G. Knepley /*@C
1208475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1209475e0ac9SMatthew G. Knepley 
1210475e0ac9SMatthew G. Knepley   Not collective
1211475e0ac9SMatthew G. Knepley 
1212475e0ac9SMatthew G. Knepley   Input Parameter:
1213475e0ac9SMatthew G. Knepley . prob - The PetscDS
1214475e0ac9SMatthew G. Knepley 
1215475e0ac9SMatthew G. Knepley   Output Parameter:
1216475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1217475e0ac9SMatthew G. Knepley 
1218475e0ac9SMatthew G. Knepley   Level: intermediate
1219475e0ac9SMatthew G. Knepley 
1220475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1221475e0ac9SMatthew G. Knepley @*/
1222475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre)
1223475e0ac9SMatthew G. Knepley {
1224475e0ac9SMatthew G. Knepley   PetscInt f, g, h;
1225475e0ac9SMatthew G. Knepley 
1226475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1227475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1228475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
1229475e0ac9SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1230475e0ac9SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1231475e0ac9SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1232475e0ac9SMatthew G. Knepley         if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE;
1233475e0ac9SMatthew G. Knepley       }
1234475e0ac9SMatthew G. Knepley     }
1235475e0ac9SMatthew G. Knepley   }
1236475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1237475e0ac9SMatthew G. Knepley }
1238475e0ac9SMatthew G. Knepley 
1239475e0ac9SMatthew G. Knepley #undef __FUNCT__
1240475e0ac9SMatthew G. Knepley #define __FUNCT__ "PetscDSGetJacobianPreconditioner"
1241475e0ac9SMatthew G. Knepley /*@C
1242475e0ac9SMatthew 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.
1243475e0ac9SMatthew G. Knepley 
1244475e0ac9SMatthew G. Knepley   Not collective
1245475e0ac9SMatthew G. Knepley 
1246475e0ac9SMatthew G. Knepley   Input Parameters:
1247475e0ac9SMatthew G. Knepley + prob - The PetscDS
1248475e0ac9SMatthew G. Knepley . f    - The test field number
1249475e0ac9SMatthew G. Knepley - g    - The field number
1250475e0ac9SMatthew G. Knepley 
1251475e0ac9SMatthew G. Knepley   Output Parameters:
1252475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1253475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1254475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1255475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1256475e0ac9SMatthew G. Knepley 
1257475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1258475e0ac9SMatthew G. Knepley 
1259475e0ac9SMatthew 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
1260475e0ac9SMatthew G. Knepley 
1261475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1262475e0ac9SMatthew G. Knepley 
1263475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1264475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1265475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1266475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1267475e0ac9SMatthew G. Knepley 
1268475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1269475e0ac9SMatthew G. Knepley . Nf - the number of fields
1270475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1271475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1272475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1273475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1274475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1275475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1276475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1277475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1278475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1279475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1280475e0ac9SMatthew G. Knepley . t - current time
1281475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1282475e0ac9SMatthew G. Knepley . x - coordinates of the current point
1283475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1284475e0ac9SMatthew G. Knepley 
1285475e0ac9SMatthew G. Knepley   Level: intermediate
1286475e0ac9SMatthew G. Knepley 
1287475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1288475e0ac9SMatthew G. Knepley @*/
1289475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1290475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1291475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1292475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1293475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1294475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1295475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1296475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1297475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1298475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1299475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1300475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1301475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1302475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1303475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1304475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1305475e0ac9SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1306475e0ac9SMatthew G. Knepley {
1307475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1308475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1309475e0ac9SMatthew 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);
1310475e0ac9SMatthew 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);
1311475e0ac9SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];}
1312475e0ac9SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];}
1313475e0ac9SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];}
1314475e0ac9SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];}
1315475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1316475e0ac9SMatthew G. Knepley }
1317475e0ac9SMatthew G. Knepley 
1318475e0ac9SMatthew G. Knepley #undef __FUNCT__
1319475e0ac9SMatthew G. Knepley #define __FUNCT__ "PetscDSSetJacobianPreconditioner"
1320475e0ac9SMatthew G. Knepley /*@C
1321475e0ac9SMatthew 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.
1322475e0ac9SMatthew G. Knepley 
1323475e0ac9SMatthew G. Knepley   Not collective
1324475e0ac9SMatthew G. Knepley 
1325475e0ac9SMatthew G. Knepley   Input Parameters:
1326475e0ac9SMatthew G. Knepley + prob - The PetscDS
1327475e0ac9SMatthew G. Knepley . f    - The test field number
1328475e0ac9SMatthew G. Knepley . g    - The field number
1329475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1330475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1331475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1332475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1333475e0ac9SMatthew G. Knepley 
1334475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1335475e0ac9SMatthew G. Knepley 
1336475e0ac9SMatthew 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
1337475e0ac9SMatthew G. Knepley 
1338475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1339475e0ac9SMatthew G. Knepley 
1340475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1341475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1342475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1343475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1344475e0ac9SMatthew G. Knepley 
1345475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1346475e0ac9SMatthew G. Knepley . Nf - the number of fields
1347475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1348475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1349475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1350475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1351475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1352475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1353475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1354475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1355475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1356475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1357475e0ac9SMatthew G. Knepley . t - current time
1358475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1359475e0ac9SMatthew G. Knepley . x - coordinates of the current point
1360475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1361475e0ac9SMatthew G. Knepley 
1362475e0ac9SMatthew G. Knepley   Level: intermediate
1363475e0ac9SMatthew G. Knepley 
1364475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1365475e0ac9SMatthew G. Knepley @*/
1366475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1367475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1368475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1369475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1370475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1371475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1372475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1373475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1374475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1375475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1376475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1377475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1378475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1379475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1380475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1381475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1382475e0ac9SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1383475e0ac9SMatthew G. Knepley {
1384475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1385475e0ac9SMatthew G. Knepley 
1386475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1387475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1388475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1389475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1390475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1391475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1392475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1393475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1394475e0ac9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1395475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+0] = g0;
1396475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+1] = g1;
1397475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+2] = g2;
1398475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+3] = g3;
1399475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1400475e0ac9SMatthew G. Knepley }
1401475e0ac9SMatthew G. Knepley 
1402475e0ac9SMatthew G. Knepley #undef __FUNCT__
1403b7e05686SMatthew G. Knepley #define __FUNCT__ "PetscDSHasDynamicJacobian"
1404b7e05686SMatthew G. Knepley /*@C
1405b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1406b7e05686SMatthew G. Knepley 
1407b7e05686SMatthew G. Knepley   Not collective
1408b7e05686SMatthew G. Knepley 
1409b7e05686SMatthew G. Knepley   Input Parameter:
1410b7e05686SMatthew G. Knepley . prob - The PetscDS
1411b7e05686SMatthew G. Knepley 
1412b7e05686SMatthew G. Knepley   Output Parameter:
1413b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1414b7e05686SMatthew G. Knepley 
1415b7e05686SMatthew G. Knepley   Level: intermediate
1416b7e05686SMatthew G. Knepley 
1417b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1418b7e05686SMatthew G. Knepley @*/
1419b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac)
1420b7e05686SMatthew G. Knepley {
1421b7e05686SMatthew G. Knepley   PetscInt f, g, h;
1422b7e05686SMatthew G. Knepley 
1423b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1424b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1425b7e05686SMatthew G. Knepley   *hasDynJac = PETSC_FALSE;
1426b7e05686SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1427b7e05686SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1428b7e05686SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1429b7e05686SMatthew G. Knepley         if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE;
1430b7e05686SMatthew G. Knepley       }
1431b7e05686SMatthew G. Knepley     }
1432b7e05686SMatthew G. Knepley   }
1433b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1434b7e05686SMatthew G. Knepley }
1435b7e05686SMatthew G. Knepley 
1436b7e05686SMatthew G. Knepley #undef __FUNCT__
1437b7e05686SMatthew G. Knepley #define __FUNCT__ "PetscDSGetDynamicJacobian"
1438b7e05686SMatthew G. Knepley /*@C
1439b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1440b7e05686SMatthew G. Knepley 
1441b7e05686SMatthew G. Knepley   Not collective
1442b7e05686SMatthew G. Knepley 
1443b7e05686SMatthew G. Knepley   Input Parameters:
1444b7e05686SMatthew G. Knepley + prob - The PetscDS
1445b7e05686SMatthew G. Knepley . f    - The test field number
1446b7e05686SMatthew G. Knepley - g    - The field number
1447b7e05686SMatthew G. Knepley 
1448b7e05686SMatthew G. Knepley   Output Parameters:
1449b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1450b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1451b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1452b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1453b7e05686SMatthew G. Knepley 
1454b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1455b7e05686SMatthew G. Knepley 
1456b7e05686SMatthew 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
1457b7e05686SMatthew G. Knepley 
1458b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1459b7e05686SMatthew G. Knepley 
1460b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1461b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1462b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1463b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1464b7e05686SMatthew G. Knepley 
1465b7e05686SMatthew G. Knepley + dim - the spatial dimension
1466b7e05686SMatthew G. Knepley . Nf - the number of fields
1467b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1468b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1469b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1470b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1471b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1472b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1473b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1474b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1475b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1476b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1477b7e05686SMatthew G. Knepley . t - current time
1478b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1479b7e05686SMatthew G. Knepley . x - coordinates of the current point
1480b7e05686SMatthew G. Knepley - g0 - output values at the current point
1481b7e05686SMatthew G. Knepley 
1482b7e05686SMatthew G. Knepley   Level: intermediate
1483b7e05686SMatthew G. Knepley 
1484b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1485b7e05686SMatthew G. Knepley @*/
1486b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1487b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1488b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1489b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1490b7e05686SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1491b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1492b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1493b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1494b7e05686SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1495b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1496b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1497b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1498b7e05686SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1499b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1500b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1501b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1502b7e05686SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1503b7e05686SMatthew G. Knepley {
1504b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1505b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1506b7e05686SMatthew 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);
1507b7e05686SMatthew 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);
1508b7e05686SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];}
1509b7e05686SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];}
1510b7e05686SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];}
1511b7e05686SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];}
1512b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1513b7e05686SMatthew G. Knepley }
1514b7e05686SMatthew G. Knepley 
1515b7e05686SMatthew G. Knepley #undef __FUNCT__
1516b7e05686SMatthew G. Knepley #define __FUNCT__ "PetscDSSetDynamicJacobian"
1517b7e05686SMatthew G. Knepley /*@C
1518b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1519b7e05686SMatthew G. Knepley 
1520b7e05686SMatthew G. Knepley   Not collective
1521b7e05686SMatthew G. Knepley 
1522b7e05686SMatthew G. Knepley   Input Parameters:
1523b7e05686SMatthew G. Knepley + prob - The PetscDS
1524b7e05686SMatthew G. Knepley . f    - The test field number
1525b7e05686SMatthew G. Knepley . g    - The field number
1526b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1527b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1528b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1529b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1530b7e05686SMatthew G. Knepley 
1531b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1532b7e05686SMatthew G. Knepley 
1533b7e05686SMatthew 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
1534b7e05686SMatthew G. Knepley 
1535b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1536b7e05686SMatthew G. Knepley 
1537b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1538b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1539b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1540b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1541b7e05686SMatthew G. Knepley 
1542b7e05686SMatthew G. Knepley + dim - the spatial dimension
1543b7e05686SMatthew G. Knepley . Nf - the number of fields
1544b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1545b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1546b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1547b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1548b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1549b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1550b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1551b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1552b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1553b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1554b7e05686SMatthew G. Knepley . t - current time
1555b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1556b7e05686SMatthew G. Knepley . x - coordinates of the current point
1557b7e05686SMatthew G. Knepley - g0 - output values at the current point
1558b7e05686SMatthew G. Knepley 
1559b7e05686SMatthew G. Knepley   Level: intermediate
1560b7e05686SMatthew G. Knepley 
1561b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1562b7e05686SMatthew G. Knepley @*/
1563b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1564b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1565b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1566b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1567b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g0[]),
1568b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1569b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1570b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1571b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g1[]),
1572b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1573b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1574b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1575b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g2[]),
1576b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1577b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1578b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1579b7e05686SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscScalar g3[]))
1580b7e05686SMatthew G. Knepley {
1581b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1582b7e05686SMatthew G. Knepley 
1583b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1584b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1585b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1586b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1587b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1588b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1589b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1590b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1591b7e05686SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1592b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+0] = g0;
1593b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+1] = g1;
1594b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+2] = g2;
1595b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+3] = g3;
1596b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1597b7e05686SMatthew G. Knepley }
1598b7e05686SMatthew G. Knepley 
1599b7e05686SMatthew G. Knepley #undef __FUNCT__
16000c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSGetRiemannSolver"
16010c2f2876SMatthew G. Knepley /*@C
16020c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
16030c2f2876SMatthew G. Knepley 
16040c2f2876SMatthew G. Knepley   Not collective
16050c2f2876SMatthew G. Knepley 
16060c2f2876SMatthew G. Knepley   Input Arguments:
16070c2f2876SMatthew G. Knepley + prob - The PetscDS object
16080c2f2876SMatthew G. Knepley - f    - The field number
16090c2f2876SMatthew G. Knepley 
16100c2f2876SMatthew G. Knepley   Output Argument:
16110c2f2876SMatthew G. Knepley . r    - Riemann solver
16120c2f2876SMatthew G. Knepley 
16130c2f2876SMatthew G. Knepley   Calling sequence for r:
16140c2f2876SMatthew G. Knepley 
16155db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
16160c2f2876SMatthew G. Knepley 
16175db36cf9SMatthew G. Knepley + dim  - The spatial dimension
16185db36cf9SMatthew G. Knepley . Nf   - The number of fields
16195db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
16200c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
16210c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
16220c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
16230c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
16240c2f2876SMatthew G. Knepley - ctx  - optional user context
16250c2f2876SMatthew G. Knepley 
16260c2f2876SMatthew G. Knepley   Level: intermediate
16270c2f2876SMatthew G. Knepley 
16280c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
16290c2f2876SMatthew G. Knepley @*/
16300c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f,
16315db36cf9SMatthew G. Knepley                                        void (**r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx))
16320c2f2876SMatthew G. Knepley {
16330c2f2876SMatthew G. Knepley   PetscFunctionBegin;
16340c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
16350c2f2876SMatthew 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);
16360c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
16370c2f2876SMatthew G. Knepley   *r = prob->r[f];
16380c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
16390c2f2876SMatthew G. Knepley }
16400c2f2876SMatthew G. Knepley 
16410c2f2876SMatthew G. Knepley #undef __FUNCT__
16420c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSSetRiemannSolver"
16430c2f2876SMatthew G. Knepley /*@C
16440c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
16450c2f2876SMatthew G. Knepley 
16460c2f2876SMatthew G. Knepley   Not collective
16470c2f2876SMatthew G. Knepley 
16480c2f2876SMatthew G. Knepley   Input Arguments:
16490c2f2876SMatthew G. Knepley + prob - The PetscDS object
16500c2f2876SMatthew G. Knepley . f    - The field number
16510c2f2876SMatthew G. Knepley - r    - Riemann solver
16520c2f2876SMatthew G. Knepley 
16530c2f2876SMatthew G. Knepley   Calling sequence for r:
16540c2f2876SMatthew G. Knepley 
16555db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
16560c2f2876SMatthew G. Knepley 
16575db36cf9SMatthew G. Knepley + dim  - The spatial dimension
16585db36cf9SMatthew G. Knepley . Nf   - The number of fields
16595db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
16600c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
16610c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
16620c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
16630c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
16640c2f2876SMatthew G. Knepley - ctx  - optional user context
16650c2f2876SMatthew G. Knepley 
16660c2f2876SMatthew G. Knepley   Level: intermediate
16670c2f2876SMatthew G. Knepley 
16680c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
16690c2f2876SMatthew G. Knepley @*/
16700c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f,
16715db36cf9SMatthew G. Knepley                                        void (*r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx))
16720c2f2876SMatthew G. Knepley {
16730c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
16740c2f2876SMatthew G. Knepley 
16750c2f2876SMatthew G. Knepley   PetscFunctionBegin;
16760c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1677de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
16780c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
16790c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
16800c2f2876SMatthew G. Knepley   prob->r[f] = r;
16810c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
16820c2f2876SMatthew G. Knepley }
16830c2f2876SMatthew G. Knepley 
16840c2f2876SMatthew G. Knepley #undef __FUNCT__
16850c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSGetContext"
16860c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx)
16870c2f2876SMatthew G. Knepley {
16880c2f2876SMatthew G. Knepley   PetscFunctionBegin;
16890c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
16900c2f2876SMatthew 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);
16910c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
16920c2f2876SMatthew G. Knepley   *ctx = prob->ctx[f];
16930c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
16940c2f2876SMatthew G. Knepley }
16950c2f2876SMatthew G. Knepley 
16960c2f2876SMatthew G. Knepley #undef __FUNCT__
16970c2f2876SMatthew G. Knepley #define __FUNCT__ "PetscDSSetContext"
16980c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx)
16990c2f2876SMatthew G. Knepley {
17000c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
17010c2f2876SMatthew G. Knepley 
17020c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17030c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
17040c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
17050c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
17060c2f2876SMatthew G. Knepley   prob->ctx[f] = ctx;
17070c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17080c2f2876SMatthew G. Knepley }
17090c2f2876SMatthew G. Knepley 
17100c2f2876SMatthew G. Knepley #undef __FUNCT__
17112764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdResidual"
1712194d53e6SMatthew G. Knepley /*@C
1713194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
1714194d53e6SMatthew G. Knepley 
1715194d53e6SMatthew G. Knepley   Not collective
1716194d53e6SMatthew G. Knepley 
1717194d53e6SMatthew G. Knepley   Input Parameters:
1718194d53e6SMatthew G. Knepley + prob - The PetscDS
1719194d53e6SMatthew G. Knepley - f    - The test field number
1720194d53e6SMatthew G. Knepley 
1721194d53e6SMatthew G. Knepley   Output Parameters:
1722194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
1723194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1724194d53e6SMatthew G. Knepley 
1725194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1726194d53e6SMatthew G. Knepley 
1727194d53e6SMatthew 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
1728194d53e6SMatthew G. Knepley 
1729194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1730194d53e6SMatthew G. Knepley 
173130b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1732194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1733194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
173430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1735194d53e6SMatthew G. Knepley 
1736194d53e6SMatthew G. Knepley + dim - the spatial dimension
1737194d53e6SMatthew G. Knepley . Nf - the number of fields
1738194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1739194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1740194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1741194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1742194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1743194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1744194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1745194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1746194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1747194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1748194d53e6SMatthew G. Knepley . t - current time
1749194d53e6SMatthew G. Knepley . x - coordinates of the current point
1750194d53e6SMatthew G. Knepley . n - unit normal at the current point
1751194d53e6SMatthew G. Knepley - f0 - output values at the current point
1752194d53e6SMatthew G. Knepley 
1753194d53e6SMatthew G. Knepley   Level: intermediate
1754194d53e6SMatthew G. Knepley 
1755194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
1756194d53e6SMatthew G. Knepley @*/
17572764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f,
175830b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1759194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1760194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
176130b9ff8bSMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]),
176230b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1763194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1764194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
176530b9ff8bSMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f1[]))
17662764a2aaSMatthew G. Knepley {
17672764a2aaSMatthew G. Knepley   PetscFunctionBegin;
17682764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
17692764a2aaSMatthew 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);
17702764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];}
17712764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];}
17722764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
17732764a2aaSMatthew G. Knepley }
17742764a2aaSMatthew G. Knepley 
17752764a2aaSMatthew G. Knepley #undef __FUNCT__
17762764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdResidual"
1777194d53e6SMatthew G. Knepley /*@C
1778194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
1779194d53e6SMatthew G. Knepley 
1780194d53e6SMatthew G. Knepley   Not collective
1781194d53e6SMatthew G. Knepley 
1782194d53e6SMatthew G. Knepley   Input Parameters:
1783194d53e6SMatthew G. Knepley + prob - The PetscDS
1784194d53e6SMatthew G. Knepley . f    - The test field number
1785194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
1786194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1787194d53e6SMatthew G. Knepley 
1788194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1789194d53e6SMatthew G. Knepley 
1790194d53e6SMatthew 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
1791194d53e6SMatthew G. Knepley 
1792194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1793194d53e6SMatthew G. Knepley 
179430b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1795194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1796194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
179730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1798194d53e6SMatthew G. Knepley 
1799194d53e6SMatthew G. Knepley + dim - the spatial dimension
1800194d53e6SMatthew G. Knepley . Nf - the number of fields
1801194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1802194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1803194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1804194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1805194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1806194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1807194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1808194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1809194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1810194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1811194d53e6SMatthew G. Knepley . t - current time
1812194d53e6SMatthew G. Knepley . x - coordinates of the current point
1813194d53e6SMatthew G. Knepley . n - unit normal at the current point
1814194d53e6SMatthew G. Knepley - f0 - output values at the current point
1815194d53e6SMatthew G. Knepley 
1816194d53e6SMatthew G. Knepley   Level: intermediate
1817194d53e6SMatthew G. Knepley 
1818194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
1819194d53e6SMatthew G. Knepley @*/
18202764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f,
182130b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1822194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1823194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
182430b9ff8bSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[]),
182530b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1826194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1827194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
182830b9ff8bSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f1[]))
18292764a2aaSMatthew G. Knepley {
18302764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
18312764a2aaSMatthew G. Knepley 
18322764a2aaSMatthew G. Knepley   PetscFunctionBegin;
18332764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18342764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
18352764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
18362764a2aaSMatthew G. Knepley   if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;}
18372764a2aaSMatthew G. Knepley   if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;}
18382764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
18392764a2aaSMatthew G. Knepley }
18402764a2aaSMatthew G. Knepley 
18412764a2aaSMatthew G. Knepley #undef __FUNCT__
18422764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetBdJacobian"
1843194d53e6SMatthew G. Knepley /*@C
1844194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
1845194d53e6SMatthew G. Knepley 
1846194d53e6SMatthew G. Knepley   Not collective
1847194d53e6SMatthew G. Knepley 
1848194d53e6SMatthew G. Knepley   Input Parameters:
1849194d53e6SMatthew G. Knepley + prob - The PetscDS
1850194d53e6SMatthew G. Knepley . f    - The test field number
1851194d53e6SMatthew G. Knepley - g    - The field number
1852194d53e6SMatthew G. Knepley 
1853194d53e6SMatthew G. Knepley   Output Parameters:
1854194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1855194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1856194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1857194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1858194d53e6SMatthew G. Knepley 
1859194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1860194d53e6SMatthew G. Knepley 
1861194d53e6SMatthew 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
1862194d53e6SMatthew G. Knepley 
1863194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1864194d53e6SMatthew G. Knepley 
186530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1866194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1867194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
186830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
1869194d53e6SMatthew G. Knepley 
1870194d53e6SMatthew G. Knepley + dim - the spatial dimension
1871194d53e6SMatthew G. Knepley . Nf - the number of fields
1872194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1873194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1874194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1875194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1876194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1877194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1878194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1879194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1880194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1881194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1882194d53e6SMatthew G. Knepley . t - current time
18832aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1884194d53e6SMatthew G. Knepley . x - coordinates of the current point
1885194d53e6SMatthew G. Knepley . n - normal at the current point
1886194d53e6SMatthew G. Knepley - g0 - output values at the current point
1887194d53e6SMatthew G. Knepley 
1888194d53e6SMatthew G. Knepley   Level: intermediate
1889194d53e6SMatthew G. Knepley 
1890194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
1891194d53e6SMatthew G. Knepley @*/
18922764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
189330b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1894194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1895194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
18962aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g0[]),
189730b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1898194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1899194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19002aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g1[]),
190130b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1902194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1903194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19042aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g2[]),
190530b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1906194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1907194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19082aa1fc23SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g3[]))
19092764a2aaSMatthew G. Knepley {
19102764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19112764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19122764a2aaSMatthew 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);
19132764a2aaSMatthew 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);
19142764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];}
19152764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];}
19162764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];}
19172764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];}
19182764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
19192764a2aaSMatthew G. Knepley }
19202764a2aaSMatthew G. Knepley 
19212764a2aaSMatthew G. Knepley #undef __FUNCT__
19222764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSSetBdJacobian"
1923194d53e6SMatthew G. Knepley /*@C
1924194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
1925194d53e6SMatthew G. Knepley 
1926194d53e6SMatthew G. Knepley   Not collective
1927194d53e6SMatthew G. Knepley 
1928194d53e6SMatthew G. Knepley   Input Parameters:
1929194d53e6SMatthew G. Knepley + prob - The PetscDS
1930194d53e6SMatthew G. Knepley . f    - The test field number
1931194d53e6SMatthew G. Knepley . g    - The field number
1932194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1933194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1934194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1935194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1936194d53e6SMatthew G. Knepley 
1937194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1938194d53e6SMatthew G. Knepley 
1939194d53e6SMatthew 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
1940194d53e6SMatthew G. Knepley 
1941194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1942194d53e6SMatthew G. Knepley 
194330b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1944194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1945194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
1947194d53e6SMatthew G. Knepley 
1948194d53e6SMatthew G. Knepley + dim - the spatial dimension
1949194d53e6SMatthew G. Knepley . Nf - the number of fields
1950194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1951194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1952194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1953194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1954194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1955194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1956194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1957194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1958194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1959194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1960194d53e6SMatthew G. Knepley . t - current time
19612aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1962194d53e6SMatthew G. Knepley . x - coordinates of the current point
1963194d53e6SMatthew G. Knepley . n - normal at the current point
1964194d53e6SMatthew G. Knepley - g0 - output values at the current point
1965194d53e6SMatthew G. Knepley 
1966194d53e6SMatthew G. Knepley   Level: intermediate
1967194d53e6SMatthew G. Knepley 
1968194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
1969194d53e6SMatthew G. Knepley @*/
19702764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
197130b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1972194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1973194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19742aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g0[]),
197530b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1976194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1977194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19782aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g1[]),
197930b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1980194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1981194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19822aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g2[]),
198330b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1984194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1985194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
19862aa1fc23SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscScalar g3[]))
19872764a2aaSMatthew G. Knepley {
19882764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
19892764a2aaSMatthew G. Knepley 
19902764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19912764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19922764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
19932764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
19942764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
19952764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
19962764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19972764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
19982764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
19992764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+0] = g0;
20002764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+1] = g1;
20012764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+2] = g2;
20022764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+3] = g3;
20032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20042764a2aaSMatthew G. Knepley }
20052764a2aaSMatthew G. Knepley 
20062764a2aaSMatthew G. Knepley #undef __FUNCT__
20074cd1e086SMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldIndex"
20084cd1e086SMatthew G. Knepley /*@
20094cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
20104cd1e086SMatthew G. Knepley 
20114cd1e086SMatthew G. Knepley   Not collective
20124cd1e086SMatthew G. Knepley 
20134cd1e086SMatthew G. Knepley   Input Parameters:
20144cd1e086SMatthew G. Knepley + prob - The PetscDS object
20154cd1e086SMatthew G. Knepley - disc - The discretization object
20164cd1e086SMatthew G. Knepley 
20174cd1e086SMatthew G. Knepley   Output Parameter:
20184cd1e086SMatthew G. Knepley . f - The field number
20194cd1e086SMatthew G. Knepley 
20204cd1e086SMatthew G. Knepley   Level: beginner
20214cd1e086SMatthew G. Knepley 
2022f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
20234cd1e086SMatthew G. Knepley @*/
20244cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
20254cd1e086SMatthew G. Knepley {
20264cd1e086SMatthew G. Knepley   PetscInt g;
20274cd1e086SMatthew G. Knepley 
20284cd1e086SMatthew G. Knepley   PetscFunctionBegin;
20294cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20304cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
20314cd1e086SMatthew G. Knepley   *f = -1;
20324cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
20334cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
20344cd1e086SMatthew G. Knepley   *f = g;
20354cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
20364cd1e086SMatthew G. Knepley }
20374cd1e086SMatthew G. Knepley 
20384cd1e086SMatthew G. Knepley #undef __FUNCT__
20394cd1e086SMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldSize"
20404cd1e086SMatthew G. Knepley /*@
20414cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
20424cd1e086SMatthew G. Knepley 
20434cd1e086SMatthew G. Knepley   Not collective
20444cd1e086SMatthew G. Knepley 
20454cd1e086SMatthew G. Knepley   Input Parameters:
20464cd1e086SMatthew G. Knepley + prob - The PetscDS object
20474cd1e086SMatthew G. Knepley - f - The field number
20484cd1e086SMatthew G. Knepley 
20494cd1e086SMatthew G. Knepley   Output Parameter:
20504cd1e086SMatthew G. Knepley . size - The size
20514cd1e086SMatthew G. Knepley 
20524cd1e086SMatthew G. Knepley   Level: beginner
20534cd1e086SMatthew G. Knepley 
2054f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
20554cd1e086SMatthew G. Knepley @*/
20564cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
20574cd1e086SMatthew G. Knepley {
20582166fd64SMatthew G. Knepley   PetscErrorCode ierr;
20592166fd64SMatthew G. Knepley 
20604cd1e086SMatthew G. Knepley   PetscFunctionBegin;
20614cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20624cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
20634cd1e086SMatthew 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);
20642166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
206547e57110SSander Arens   *size = prob->Nc[f] * prob->Nb[f];
20664cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
20674cd1e086SMatthew G. Knepley }
20684cd1e086SMatthew G. Knepley 
20694cd1e086SMatthew G. Knepley #undef __FUNCT__
20702764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetFieldOffset"
2071bc4ae4beSMatthew G. Knepley /*@
2072bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2073bc4ae4beSMatthew G. Knepley 
2074bc4ae4beSMatthew G. Knepley   Not collective
2075bc4ae4beSMatthew G. Knepley 
2076bc4ae4beSMatthew G. Knepley   Input Parameters:
2077bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2078bc4ae4beSMatthew G. Knepley - f - The field number
2079bc4ae4beSMatthew G. Knepley 
2080bc4ae4beSMatthew G. Knepley   Output Parameter:
2081bc4ae4beSMatthew G. Knepley . off - The offset
2082bc4ae4beSMatthew G. Knepley 
2083bc4ae4beSMatthew G. Knepley   Level: beginner
2084bc4ae4beSMatthew G. Knepley 
2085f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2086bc4ae4beSMatthew G. Knepley @*/
20872764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
20882764a2aaSMatthew G. Knepley {
20894cd1e086SMatthew G. Knepley   PetscInt       size, g;
20902764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
20912764a2aaSMatthew G. Knepley 
20922764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20932764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20942764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
20952764a2aaSMatthew 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);
20962764a2aaSMatthew G. Knepley   *off = 0;
20972764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
20984cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
20994cd1e086SMatthew G. Knepley     *off += size;
21002764a2aaSMatthew G. Knepley   }
21012764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21022764a2aaSMatthew G. Knepley }
21032764a2aaSMatthew G. Knepley 
21042764a2aaSMatthew G. Knepley #undef __FUNCT__
210547e57110SSander Arens #define __FUNCT__ "PetscDSGetDimensions"
2106bc4ae4beSMatthew G. Knepley /*@
210747e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2108bc4ae4beSMatthew G. Knepley 
2109bc4ae4beSMatthew G. Knepley   Not collective
2110bc4ae4beSMatthew G. Knepley 
211147e57110SSander Arens   Input Parameter:
211247e57110SSander Arens . prob - The PetscDS object
2113bc4ae4beSMatthew G. Knepley 
2114bc4ae4beSMatthew G. Knepley   Output Parameter:
211547e57110SSander Arens . dimensions - The number of dimensions
2116bc4ae4beSMatthew G. Knepley 
2117bc4ae4beSMatthew G. Knepley   Level: beginner
2118bc4ae4beSMatthew G. Knepley 
211947e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2120bc4ae4beSMatthew G. Knepley @*/
212147e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
21222764a2aaSMatthew G. Knepley {
21232764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21242764a2aaSMatthew G. Knepley 
21252764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21262764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
212747e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
212847e57110SSander Arens   PetscValidPointer(dimensions, 2);
212947e57110SSander Arens   *dimensions = prob->Nb;
213047e57110SSander Arens   PetscFunctionReturn(0);
21316ce16762SMatthew G. Knepley }
213247e57110SSander Arens 
213347e57110SSander Arens #undef __FUNCT__
213447e57110SSander Arens #define __FUNCT__ "PetscDSGetComponents"
213547e57110SSander Arens /*@
213647e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
213747e57110SSander Arens 
213847e57110SSander Arens   Not collective
213947e57110SSander Arens 
214047e57110SSander Arens   Input Parameter:
214147e57110SSander Arens . prob - The PetscDS object
214247e57110SSander Arens 
214347e57110SSander Arens   Output Parameter:
214447e57110SSander Arens . components - The number of components
214547e57110SSander Arens 
214647e57110SSander Arens   Level: beginner
214747e57110SSander Arens 
214847e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
214947e57110SSander Arens @*/
215047e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
215147e57110SSander Arens {
215247e57110SSander Arens   PetscErrorCode ierr;
215347e57110SSander Arens 
215447e57110SSander Arens   PetscFunctionBegin;
215547e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
215647e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
215747e57110SSander Arens   PetscValidPointer(components, 2);
215847e57110SSander Arens   *components = prob->Nc;
21596ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
21606ce16762SMatthew G. Knepley }
21616ce16762SMatthew G. Knepley 
21626ce16762SMatthew G. Knepley #undef __FUNCT__
21636ce16762SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentOffset"
21646ce16762SMatthew G. Knepley /*@
21656ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
21666ce16762SMatthew G. Knepley 
21676ce16762SMatthew G. Knepley   Not collective
21686ce16762SMatthew G. Knepley 
21696ce16762SMatthew G. Knepley   Input Parameters:
21706ce16762SMatthew G. Knepley + prob - The PetscDS object
21716ce16762SMatthew G. Knepley - f - The field number
21726ce16762SMatthew G. Knepley 
21736ce16762SMatthew G. Knepley   Output Parameter:
21746ce16762SMatthew G. Knepley . off - The offset
21756ce16762SMatthew G. Knepley 
21766ce16762SMatthew G. Knepley   Level: beginner
21776ce16762SMatthew G. Knepley 
2178f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
21796ce16762SMatthew G. Knepley @*/
21806ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
21816ce16762SMatthew G. Knepley {
21826ce16762SMatthew G. Knepley   PetscFunctionBegin;
21836ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21846ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
21856ce16762SMatthew 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);
218647e57110SSander Arens   *off = prob->off[f];
21872764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21882764a2aaSMatthew G. Knepley }
21892764a2aaSMatthew G. Knepley 
21902764a2aaSMatthew G. Knepley #undef __FUNCT__
2191194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentOffsets"
2192194d53e6SMatthew G. Knepley /*@
2193194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2194194d53e6SMatthew G. Knepley 
2195194d53e6SMatthew G. Knepley   Not collective
2196194d53e6SMatthew G. Knepley 
2197194d53e6SMatthew G. Knepley   Input Parameter:
2198194d53e6SMatthew G. Knepley . prob - The PetscDS object
2199194d53e6SMatthew G. Knepley 
2200194d53e6SMatthew G. Knepley   Output Parameter:
2201194d53e6SMatthew G. Knepley . offsets - The offsets
2202194d53e6SMatthew G. Knepley 
2203194d53e6SMatthew G. Knepley   Level: beginner
2204194d53e6SMatthew G. Knepley 
2205f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2206194d53e6SMatthew G. Knepley @*/
2207194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2208194d53e6SMatthew G. Knepley {
2209194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2210194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2211194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2212194d53e6SMatthew G. Knepley   *offsets = prob->off;
2213194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2214194d53e6SMatthew G. Knepley }
2215194d53e6SMatthew G. Knepley 
2216194d53e6SMatthew G. Knepley #undef __FUNCT__
2217194d53e6SMatthew G. Knepley #define __FUNCT__ "PetscDSGetComponentDerivativeOffsets"
2218194d53e6SMatthew G. Knepley /*@
2219194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2220194d53e6SMatthew G. Knepley 
2221194d53e6SMatthew G. Knepley   Not collective
2222194d53e6SMatthew G. Knepley 
2223194d53e6SMatthew G. Knepley   Input Parameter:
2224194d53e6SMatthew G. Knepley . prob - The PetscDS object
2225194d53e6SMatthew G. Knepley 
2226194d53e6SMatthew G. Knepley   Output Parameter:
2227194d53e6SMatthew G. Knepley . offsets - The offsets
2228194d53e6SMatthew G. Knepley 
2229194d53e6SMatthew G. Knepley   Level: beginner
2230194d53e6SMatthew G. Knepley 
2231f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2232194d53e6SMatthew G. Knepley @*/
2233194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2234194d53e6SMatthew G. Knepley {
2235194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2236194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2237194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2238194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
2239194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2240194d53e6SMatthew G. Knepley }
2241194d53e6SMatthew G. Knepley 
2242194d53e6SMatthew G. Knepley #undef __FUNCT__
22432764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetTabulation"
224468c9edb9SMatthew G. Knepley /*@C
224568c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
224668c9edb9SMatthew G. Knepley 
224768c9edb9SMatthew G. Knepley   Not collective
224868c9edb9SMatthew G. Knepley 
224968c9edb9SMatthew G. Knepley   Input Parameter:
225068c9edb9SMatthew G. Knepley . prob - The PetscDS object
225168c9edb9SMatthew G. Knepley 
225268c9edb9SMatthew G. Knepley   Output Parameters:
225368c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
225468c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
225568c9edb9SMatthew G. Knepley 
225668c9edb9SMatthew G. Knepley   Level: intermediate
225768c9edb9SMatthew G. Knepley 
2258f744cafaSSander Arens .seealso: PetscDSCreate()
225968c9edb9SMatthew G. Knepley @*/
22602764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
22612764a2aaSMatthew G. Knepley {
22622764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
22632764a2aaSMatthew G. Knepley 
22642764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22652764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22662764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
22672764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basis;}
22682764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;}
22692764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
22702764a2aaSMatthew G. Knepley }
22712764a2aaSMatthew G. Knepley 
22722764a2aaSMatthew G. Knepley #undef __FUNCT__
22734d0b9603SSander Arens #define __FUNCT__ "PetscDSGetFaceTabulation"
227468c9edb9SMatthew G. Knepley /*@C
22754d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
227668c9edb9SMatthew G. Knepley 
227768c9edb9SMatthew G. Knepley   Not collective
227868c9edb9SMatthew G. Knepley 
227968c9edb9SMatthew G. Knepley   Input Parameter:
228068c9edb9SMatthew G. Knepley . prob - The PetscDS object
228168c9edb9SMatthew G. Knepley 
228268c9edb9SMatthew G. Knepley   Output Parameters:
22834d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points
22844d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points
228568c9edb9SMatthew G. Knepley 
228668c9edb9SMatthew G. Knepley   Level: intermediate
228768c9edb9SMatthew G. Knepley 
228868c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
228968c9edb9SMatthew G. Knepley @*/
22904d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
22912764a2aaSMatthew G. Knepley {
22922764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
22932764a2aaSMatthew G. Knepley 
22942764a2aaSMatthew G. Knepley   PetscFunctionBegin;
22952764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22962764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
22974d0b9603SSander Arens   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basisFace;}
22984d0b9603SSander Arens   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;}
22992764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23002764a2aaSMatthew G. Knepley }
23012764a2aaSMatthew G. Knepley 
23022764a2aaSMatthew G. Knepley #undef __FUNCT__
23032764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetEvaluationArrays"
23042764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
23052764a2aaSMatthew G. Knepley {
23062764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23072764a2aaSMatthew G. Knepley 
23082764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23092764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23102764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
23112764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
23122764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
23132764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
23142764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23152764a2aaSMatthew G. Knepley }
23162764a2aaSMatthew G. Knepley 
23172764a2aaSMatthew G. Knepley #undef __FUNCT__
23182764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetWeakFormArrays"
23192764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
23202764a2aaSMatthew G. Knepley {
23212764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23222764a2aaSMatthew G. Knepley 
23232764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23242764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23252764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
23262764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
23272764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
23282764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
23292764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
23302764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
23312764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
23322764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23332764a2aaSMatthew G. Knepley }
23342764a2aaSMatthew G. Knepley 
23352764a2aaSMatthew G. Knepley #undef __FUNCT__
23362764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSGetRefCoordArrays"
23372764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer)
23382764a2aaSMatthew G. Knepley {
23392764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23402764a2aaSMatthew G. Knepley 
23412764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23422764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23432764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
23442764a2aaSMatthew G. Knepley   if (x)           {PetscValidPointer(x, 2);           *x           = prob->x;}
23452764a2aaSMatthew G. Knepley   if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;}
23462764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23472764a2aaSMatthew G. Knepley }
23482764a2aaSMatthew G. Knepley 
23492764a2aaSMatthew G. Knepley #undef __FUNCT__
235058ebd649SToby Isaac #define __FUNCT__ "PetscDSAddBoundary"
235158ebd649SToby Isaac /*@C
235258ebd649SToby Isaac   PetscDSAddBoundary - Add a boundary condition to the model
235358ebd649SToby Isaac 
235458ebd649SToby Isaac   Input Parameters:
235558ebd649SToby Isaac + ds          - The PetscDS object
2356*2d47a189SJulian Andrej . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
235758ebd649SToby Isaac . name        - The BC name
235858ebd649SToby Isaac . labelname   - The label defining constrained points
235958ebd649SToby Isaac . field       - The field to constrain
236058ebd649SToby Isaac . numcomps    - The number of constrained field components
236158ebd649SToby Isaac . comps       - An array of constrained component numbers
236258ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
236358ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
236458ebd649SToby Isaac . ids         - An array of ids for constrained points
236558ebd649SToby Isaac - ctx         - An optional user context for bcFunc
236658ebd649SToby Isaac 
236758ebd649SToby Isaac   Options Database Keys:
236858ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
236958ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
237058ebd649SToby Isaac 
237158ebd649SToby Isaac   Level: developer
237258ebd649SToby Isaac 
237358ebd649SToby Isaac .seealso: PetscDSGetBoundary()
237458ebd649SToby Isaac @*/
2375f971fd6bSMatthew G. Knepley PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(), PetscInt numids, const PetscInt *ids, void *ctx)
237658ebd649SToby Isaac {
237758ebd649SToby Isaac   DSBoundary     b;
237858ebd649SToby Isaac   PetscErrorCode ierr;
237958ebd649SToby Isaac 
238058ebd649SToby Isaac   PetscFunctionBegin;
238158ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
238258ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
238358ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
238458ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
238558ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
238658ebd649SToby Isaac   if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
238758ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
238858ebd649SToby Isaac   if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
2389f971fd6bSMatthew G. Knepley   b->type            = type;
239058ebd649SToby Isaac   b->field           = field;
239158ebd649SToby Isaac   b->numcomps        = numcomps;
239258ebd649SToby Isaac   b->func            = bcFunc;
239358ebd649SToby Isaac   b->numids          = numids;
239458ebd649SToby Isaac   b->ctx             = ctx;
239558ebd649SToby Isaac   b->next            = ds->boundary;
239658ebd649SToby Isaac   ds->boundary       = b;
239758ebd649SToby Isaac   PetscFunctionReturn(0);
239858ebd649SToby Isaac }
239958ebd649SToby Isaac 
240058ebd649SToby Isaac #undef __FUNCT__
240158ebd649SToby Isaac #define __FUNCT__ "PetscDSGetNumBoundary"
240258ebd649SToby Isaac /*@
240358ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
240458ebd649SToby Isaac 
240558ebd649SToby Isaac   Input Parameters:
240658ebd649SToby Isaac . ds - The PetscDS object
240758ebd649SToby Isaac 
240858ebd649SToby Isaac   Output Parameters:
240958ebd649SToby Isaac . numBd - The number of BC
241058ebd649SToby Isaac 
241158ebd649SToby Isaac   Level: intermediate
241258ebd649SToby Isaac 
241358ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
241458ebd649SToby Isaac @*/
241558ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
241658ebd649SToby Isaac {
241758ebd649SToby Isaac   DSBoundary b = ds->boundary;
241858ebd649SToby Isaac 
241958ebd649SToby Isaac   PetscFunctionBegin;
242058ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
242158ebd649SToby Isaac   PetscValidPointer(numBd, 2);
242258ebd649SToby Isaac   *numBd = 0;
242358ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
242458ebd649SToby Isaac   PetscFunctionReturn(0);
242558ebd649SToby Isaac }
242658ebd649SToby Isaac 
242758ebd649SToby Isaac #undef __FUNCT__
242858ebd649SToby Isaac #define __FUNCT__ "PetscDSGetBoundary"
242958ebd649SToby Isaac /*@C
243058ebd649SToby Isaac   PetscDSGetBoundary - Add a boundary condition to the model
243158ebd649SToby Isaac 
243258ebd649SToby Isaac   Input Parameters:
243358ebd649SToby Isaac + ds          - The PetscDS object
243458ebd649SToby Isaac - bd          - The BC number
243558ebd649SToby Isaac 
243658ebd649SToby Isaac   Output Parameters:
2437*2d47a189SJulian Andrej + type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
243858ebd649SToby Isaac . name        - The BC name
243958ebd649SToby Isaac . labelname   - The label defining constrained points
244058ebd649SToby Isaac . field       - The field to constrain
244158ebd649SToby Isaac . numcomps    - The number of constrained field components
244258ebd649SToby Isaac . comps       - An array of constrained component numbers
244358ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
244458ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
244558ebd649SToby Isaac . ids         - An array of ids for constrained points
244658ebd649SToby Isaac - ctx         - An optional user context for bcFunc
244758ebd649SToby Isaac 
244858ebd649SToby Isaac   Options Database Keys:
244958ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
245058ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
245158ebd649SToby Isaac 
245258ebd649SToby Isaac   Level: developer
245358ebd649SToby Isaac 
245458ebd649SToby Isaac .seealso: PetscDSAddBoundary()
245558ebd649SToby Isaac @*/
2456f971fd6bSMatthew G. Knepley PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType *type, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(), PetscInt *numids, const PetscInt **ids, void **ctx)
245758ebd649SToby Isaac {
245858ebd649SToby Isaac   DSBoundary b    = ds->boundary;
245958ebd649SToby Isaac   PetscInt   n    = 0;
246058ebd649SToby Isaac 
246158ebd649SToby Isaac   PetscFunctionBegin;
246258ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
246358ebd649SToby Isaac   while (b) {
246458ebd649SToby Isaac     if (n == bd) break;
246558ebd649SToby Isaac     b = b->next;
246658ebd649SToby Isaac     ++n;
246758ebd649SToby Isaac   }
246858ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
2469f971fd6bSMatthew G. Knepley   if (type) {
2470f971fd6bSMatthew G. Knepley     PetscValidPointer(type, 3);
2471f971fd6bSMatthew G. Knepley     *type = b->type;
247258ebd649SToby Isaac   }
247358ebd649SToby Isaac   if (name) {
247458ebd649SToby Isaac     PetscValidPointer(name, 4);
247558ebd649SToby Isaac     *name = b->name;
247658ebd649SToby Isaac   }
247758ebd649SToby Isaac   if (labelname) {
247858ebd649SToby Isaac     PetscValidPointer(labelname, 5);
247958ebd649SToby Isaac     *labelname = b->labelname;
248058ebd649SToby Isaac   }
248158ebd649SToby Isaac   if (field) {
248258ebd649SToby Isaac     PetscValidPointer(field, 6);
248358ebd649SToby Isaac     *field = b->field;
248458ebd649SToby Isaac   }
248558ebd649SToby Isaac   if (numcomps) {
248658ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
248758ebd649SToby Isaac     *numcomps = b->numcomps;
248858ebd649SToby Isaac   }
248958ebd649SToby Isaac   if (comps) {
249058ebd649SToby Isaac     PetscValidPointer(comps, 8);
249158ebd649SToby Isaac     *comps = b->comps;
249258ebd649SToby Isaac   }
249358ebd649SToby Isaac   if (func) {
249458ebd649SToby Isaac     PetscValidPointer(func, 9);
249558ebd649SToby Isaac     *func = b->func;
249658ebd649SToby Isaac   }
249758ebd649SToby Isaac   if (numids) {
249858ebd649SToby Isaac     PetscValidPointer(numids, 10);
249958ebd649SToby Isaac     *numids = b->numids;
250058ebd649SToby Isaac   }
250158ebd649SToby Isaac   if (ids) {
250258ebd649SToby Isaac     PetscValidPointer(ids, 11);
250358ebd649SToby Isaac     *ids = b->ids;
250458ebd649SToby Isaac   }
250558ebd649SToby Isaac   if (ctx) {
250658ebd649SToby Isaac     PetscValidPointer(ctx, 12);
250758ebd649SToby Isaac     *ctx = b->ctx;
250858ebd649SToby Isaac   }
250958ebd649SToby Isaac   PetscFunctionReturn(0);
251058ebd649SToby Isaac }
251158ebd649SToby Isaac 
251258ebd649SToby Isaac #undef __FUNCT__
2513dff059c6SToby Isaac #define __FUNCT__ "PetscDSCopyBoundary"
2514dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB)
2515dff059c6SToby Isaac {
2516dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
2517dff059c6SToby Isaac   PetscErrorCode ierr;
2518dff059c6SToby Isaac 
2519dff059c6SToby Isaac   PetscFunctionBegin;
2520dff059c6SToby Isaac   PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1);
2521dff059c6SToby Isaac   PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2);
2522dff059c6SToby Isaac   if (probA == probB) PetscFunctionReturn(0);
2523dff059c6SToby Isaac   next = probB->boundary;
2524dff059c6SToby Isaac   while (next) {
2525dff059c6SToby Isaac     DSBoundary b = next;
2526dff059c6SToby Isaac 
2527dff059c6SToby Isaac     next = b->next;
2528dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2529dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2530dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
2531dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2532dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
2533dff059c6SToby Isaac   }
2534dff059c6SToby Isaac   lastnext = &(probB->boundary);
2535dff059c6SToby Isaac   for (b = probA->boundary; b; b = b->next) {
2536dff059c6SToby Isaac     DSBoundary bNew;
2537dff059c6SToby Isaac 
2538dff059c6SToby Isaac     ierr = PetscNew(&bNew);
2539dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
2540dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
2541dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr);
2542dff059c6SToby Isaac     bNew->numids = b->numids;
2543dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
2544dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr);
2545dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
2546dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
2547dff059c6SToby Isaac     bNew->ctx   = b->ctx;
2548f971fd6bSMatthew G. Knepley     bNew->type  = b->type;
2549dff059c6SToby Isaac     bNew->field = b->field;
2550dff059c6SToby Isaac     bNew->func  = b->func;
2551dff059c6SToby Isaac 
2552dff059c6SToby Isaac     *lastnext = bNew;
2553dff059c6SToby Isaac     lastnext = &(bNew->next);
2554dff059c6SToby Isaac   }
2555dff059c6SToby Isaac   PetscFunctionReturn(0);
2556dff059c6SToby Isaac }
2557dff059c6SToby Isaac 
2558dff059c6SToby Isaac #undef __FUNCT__
2559da51fcedSMatthew G. Knepley #define __FUNCT__ "PetscDSCopyEquations"
2560da51fcedSMatthew G. Knepley /*@
2561da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
2562da51fcedSMatthew G. Knepley 
2563da51fcedSMatthew G. Knepley   Not collective
2564da51fcedSMatthew G. Knepley 
2565da51fcedSMatthew G. Knepley   Input Parameter:
2566da51fcedSMatthew G. Knepley . prob - The PetscDS object
2567da51fcedSMatthew G. Knepley 
2568da51fcedSMatthew G. Knepley   Output Parameter:
2569da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
2570da51fcedSMatthew G. Knepley 
2571da51fcedSMatthew G. Knepley   Level: intermediate
2572da51fcedSMatthew G. Knepley 
2573da51fcedSMatthew G. Knepley .seealso: PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
2574da51fcedSMatthew G. Knepley @*/
2575da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
2576da51fcedSMatthew G. Knepley {
2577da51fcedSMatthew G. Knepley   PetscInt       Nf, Ng, f, g;
2578da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
2579da51fcedSMatthew G. Knepley 
2580da51fcedSMatthew G. Knepley   PetscFunctionBegin;
2581da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2582da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
2583da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
2584da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
2585da51fcedSMatthew G. Knepley   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);CHKERRQ(ierr);
2586da51fcedSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
2587da51fcedSMatthew G. Knepley     PetscPointFunc   obj;
2588da51fcedSMatthew G. Knepley     PetscPointFunc   f0, f1;
2589da51fcedSMatthew G. Knepley     PetscPointJac    g0, g1, g2, g3;
2590da51fcedSMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
2591da51fcedSMatthew G. Knepley     PetscBdPointJac  g0Bd, g1Bd, g2Bd, g3Bd;
2592da51fcedSMatthew G. Knepley     PetscRiemannFunc r;
2593da51fcedSMatthew G. Knepley 
2594da51fcedSMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
2595da51fcedSMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
2596da51fcedSMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
2597da51fcedSMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
2598da51fcedSMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, f, obj);CHKERRQ(ierr);
2599da51fcedSMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, f, f0, f1);CHKERRQ(ierr);
2600da51fcedSMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, f, f0Bd, f1Bd);CHKERRQ(ierr);
2601da51fcedSMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, f, r);CHKERRQ(ierr);
2602da51fcedSMatthew G. Knepley     for (g = 0; g < Nf; ++g) {
2603da51fcedSMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
2604da51fcedSMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
2605da51fcedSMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, f, g, g0, g1, g2, g3);CHKERRQ(ierr);
2606da51fcedSMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, f, g, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
2607da51fcedSMatthew G. Knepley     }
2608da51fcedSMatthew G. Knepley   }
2609da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
2610da51fcedSMatthew G. Knepley }
2611da51fcedSMatthew G. Knepley 
2612da51fcedSMatthew G. Knepley #undef __FUNCT__
26132764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSDestroy_Basic"
2614bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob)
26152764a2aaSMatthew G. Knepley {
2616931fb3b8SToby Isaac   PetscErrorCode      ierr;
2617931fb3b8SToby Isaac 
26182764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2619931fb3b8SToby Isaac   ierr = PetscFree(prob->data);CHKERRQ(ierr);
26202764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26212764a2aaSMatthew G. Knepley }
26222764a2aaSMatthew G. Knepley 
26232764a2aaSMatthew G. Knepley #undef __FUNCT__
26242764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSInitialize_Basic"
2625bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob)
26262764a2aaSMatthew G. Knepley {
26272764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26282764a2aaSMatthew G. Knepley   prob->ops->setfromoptions = NULL;
26292764a2aaSMatthew G. Knepley   prob->ops->setup          = NULL;
26302764a2aaSMatthew G. Knepley   prob->ops->view           = NULL;
26312764a2aaSMatthew G. Knepley   prob->ops->destroy        = PetscDSDestroy_Basic;
26322764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26332764a2aaSMatthew G. Knepley }
26342764a2aaSMatthew G. Knepley 
26352764a2aaSMatthew G. Knepley /*MC
26362764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
26372764a2aaSMatthew G. Knepley 
26382764a2aaSMatthew G. Knepley   Level: intermediate
26392764a2aaSMatthew G. Knepley 
26402764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
26412764a2aaSMatthew G. Knepley M*/
26422764a2aaSMatthew G. Knepley 
26432764a2aaSMatthew G. Knepley #undef __FUNCT__
26442764a2aaSMatthew G. Knepley #define __FUNCT__ "PetscDSCreate_Basic"
26452764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob)
26462764a2aaSMatthew G. Knepley {
26472764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
26482764a2aaSMatthew G. Knepley   PetscErrorCode      ierr;
26492764a2aaSMatthew G. Knepley 
26502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2651931fb3b8SToby Isaac   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26522764a2aaSMatthew G. Knepley   ierr       = PetscNewLog(prob, &b);CHKERRQ(ierr);
26532764a2aaSMatthew G. Knepley   prob->data = b;
26542764a2aaSMatthew G. Knepley 
26552764a2aaSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr);
26562764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26572764a2aaSMatthew G. Knepley }
2658