xref: /petsc/src/dm/dt/interface/dtds.c (revision 03d90f89654bdc4a93a457b23fe3abc156007552)
1af0996ceSBarry Smith #include <petsc/private/petscdsimpl.h> /*I "petscds.h" I*/
22764a2aaSMatthew G. Knepley 
32764a2aaSMatthew G. Knepley PetscClassId PETSCDS_CLASSID = 0;
42764a2aaSMatthew G. Knepley 
52764a2aaSMatthew G. Knepley PetscFunctionList PetscDSList              = NULL;
62764a2aaSMatthew G. Knepley PetscBool         PetscDSRegisterAllCalled = PETSC_FALSE;
72764a2aaSMatthew G. Knepley 
82764a2aaSMatthew G. Knepley /*@C
92764a2aaSMatthew G. Knepley   PetscDSRegister - Adds a new PetscDS implementation
102764a2aaSMatthew G. Knepley 
112764a2aaSMatthew G. Knepley   Not Collective
122764a2aaSMatthew G. Knepley 
132764a2aaSMatthew G. Knepley   Input Parameters:
142764a2aaSMatthew G. Knepley + name        - The name of a new user-defined creation routine
152764a2aaSMatthew G. Knepley - create_func - The creation routine itself
162764a2aaSMatthew G. Knepley 
172764a2aaSMatthew G. Knepley   Notes:
182764a2aaSMatthew G. Knepley   PetscDSRegister() may be called multiple times to add several user-defined PetscDSs
192764a2aaSMatthew G. Knepley 
202764a2aaSMatthew G. Knepley   Sample usage:
212764a2aaSMatthew G. Knepley .vb
222764a2aaSMatthew G. Knepley     PetscDSRegister("my_ds", MyPetscDSCreate);
232764a2aaSMatthew G. Knepley .ve
242764a2aaSMatthew G. Knepley 
252764a2aaSMatthew G. Knepley   Then, your PetscDS type can be chosen with the procedural interface via
262764a2aaSMatthew G. Knepley .vb
272764a2aaSMatthew G. Knepley     PetscDSCreate(MPI_Comm, PetscDS *);
282764a2aaSMatthew G. Knepley     PetscDSSetType(PetscDS, "my_ds");
292764a2aaSMatthew G. Knepley .ve
302764a2aaSMatthew G. Knepley    or at runtime via the option
312764a2aaSMatthew G. Knepley .vb
322764a2aaSMatthew G. Knepley     -petscds_type my_ds
332764a2aaSMatthew G. Knepley .ve
342764a2aaSMatthew G. Knepley 
352764a2aaSMatthew G. Knepley   Level: advanced
362764a2aaSMatthew G. Knepley 
372764a2aaSMatthew G. Knepley .keywords: PetscDS, register
382764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy()
392764a2aaSMatthew G. Knepley 
402764a2aaSMatthew G. Knepley @*/
412764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
422764a2aaSMatthew G. Knepley {
432764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
442764a2aaSMatthew G. Knepley 
452764a2aaSMatthew G. Knepley   PetscFunctionBegin;
462764a2aaSMatthew G. Knepley   ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr);
472764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
482764a2aaSMatthew G. Knepley }
492764a2aaSMatthew G. Knepley 
502764a2aaSMatthew G. Knepley /*@C
512764a2aaSMatthew G. Knepley   PetscDSSetType - Builds a particular PetscDS
522764a2aaSMatthew G. Knepley 
532764a2aaSMatthew G. Knepley   Collective on PetscDS
542764a2aaSMatthew G. Knepley 
552764a2aaSMatthew G. Knepley   Input Parameters:
562764a2aaSMatthew G. Knepley + prob - The PetscDS object
572764a2aaSMatthew G. Knepley - name - The kind of system
582764a2aaSMatthew G. Knepley 
592764a2aaSMatthew G. Knepley   Options Database Key:
602764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
612764a2aaSMatthew G. Knepley 
622764a2aaSMatthew G. Knepley   Level: intermediate
632764a2aaSMatthew G. Knepley 
642764a2aaSMatthew G. Knepley .keywords: PetscDS, set, type
652764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate()
662764a2aaSMatthew G. Knepley @*/
672764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
682764a2aaSMatthew G. Knepley {
692764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
702764a2aaSMatthew G. Knepley   PetscBool      match;
712764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
722764a2aaSMatthew G. Knepley 
732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
742764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
752764a2aaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr);
762764a2aaSMatthew G. Knepley   if (match) PetscFunctionReturn(0);
772764a2aaSMatthew G. Knepley 
780f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
792764a2aaSMatthew G. Knepley   ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr);
802764a2aaSMatthew G. Knepley   if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
812764a2aaSMatthew G. Knepley 
822764a2aaSMatthew G. Knepley   if (prob->ops->destroy) {
832764a2aaSMatthew G. Knepley     ierr             = (*prob->ops->destroy)(prob);CHKERRQ(ierr);
842764a2aaSMatthew G. Knepley     prob->ops->destroy = NULL;
852764a2aaSMatthew G. Knepley   }
862764a2aaSMatthew G. Knepley   ierr = (*r)(prob);CHKERRQ(ierr);
872764a2aaSMatthew G. Knepley   ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr);
882764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
892764a2aaSMatthew G. Knepley }
902764a2aaSMatthew G. Knepley 
912764a2aaSMatthew G. Knepley /*@C
922764a2aaSMatthew G. Knepley   PetscDSGetType - Gets the PetscDS type name (as a string) from the object.
932764a2aaSMatthew G. Knepley 
942764a2aaSMatthew G. Knepley   Not Collective
952764a2aaSMatthew G. Knepley 
962764a2aaSMatthew G. Knepley   Input Parameter:
972764a2aaSMatthew G. Knepley . prob  - The PetscDS
982764a2aaSMatthew G. Knepley 
992764a2aaSMatthew G. Knepley   Output Parameter:
1002764a2aaSMatthew G. Knepley . name - The PetscDS type name
1012764a2aaSMatthew G. Knepley 
1022764a2aaSMatthew G. Knepley   Level: intermediate
1032764a2aaSMatthew G. Knepley 
1042764a2aaSMatthew G. Knepley .keywords: PetscDS, get, type, name
1052764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate()
1062764a2aaSMatthew G. Knepley @*/
1072764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
1082764a2aaSMatthew G. Knepley {
1092764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1102764a2aaSMatthew G. Knepley 
1112764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1122764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
113c959eef4SJed Brown   PetscValidPointer(name, 2);
1140f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
1152764a2aaSMatthew G. Knepley   *name = ((PetscObject) prob)->type_name;
1162764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1172764a2aaSMatthew G. Knepley }
1182764a2aaSMatthew G. Knepley 
1197d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer)
1207d8a60eaSMatthew G. Knepley {
1217d8a60eaSMatthew G. Knepley   PetscViewerFormat  format;
12297b6e6e8SMatthew G. Knepley   const PetscScalar *constants;
12397b6e6e8SMatthew G. Knepley   PetscInt           numConstants, f;
1247d8a60eaSMatthew G. Knepley   PetscErrorCode     ierr;
1257d8a60eaSMatthew G. Knepley 
1267d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1277d8a60eaSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
1287d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr);
1297d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1307d8a60eaSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1317d8a60eaSMatthew G. Knepley     PetscObject  obj;
1327d8a60eaSMatthew G. Knepley     PetscClassId id;
1337d8a60eaSMatthew G. Knepley     const char  *name;
1347d8a60eaSMatthew G. Knepley     PetscInt     Nc;
1357d8a60eaSMatthew G. Knepley 
1367d8a60eaSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
1377d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
1387d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr);
1397d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr);
1407d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
1417d8a60eaSMatthew G. Knepley       ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr);
1427d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr);
1437d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1447d8a60eaSMatthew G. Knepley       ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr);
1457d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr);
1467d8a60eaSMatthew G. Knepley     }
14797b6e6e8SMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f);
14897b6e6e8SMatthew G. Knepley     if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%D components", Nc);CHKERRQ(ierr);}
14997b6e6e8SMatthew G. Knepley     else        {ierr = PetscViewerASCIIPrintf(viewer, "%D component ", Nc);CHKERRQ(ierr);}
150249df284SMatthew G. Knepley     if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);}
151249df284SMatthew G. Knepley     else                   {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);}
152a6cbbb48SMatthew G. Knepley     if (prob->adjacency[f*2+0]) {
153a6cbbb48SMatthew G. Knepley       if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM++)");CHKERRQ(ierr);}
154a6cbbb48SMatthew G. Knepley       else                        {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM)");CHKERRQ(ierr);}
155a6cbbb48SMatthew G. Knepley     } else {
156a6cbbb48SMatthew G. Knepley       if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FEM)");CHKERRQ(ierr);}
157a6cbbb48SMatthew G. Knepley       else                        {ierr = PetscViewerASCIIPrintf(viewer, " (adj FUNKY)");CHKERRQ(ierr);}
158a6cbbb48SMatthew G. Knepley     }
1597d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
1607d8a60eaSMatthew G. Knepley     if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
1617d8a60eaSMatthew G. Knepley       if (id == PETSCFE_CLASSID)      {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);}
1627d8a60eaSMatthew G. Knepley       else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);}
1637d8a60eaSMatthew G. Knepley     }
1647d8a60eaSMatthew G. Knepley   }
16597b6e6e8SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr);
16697b6e6e8SMatthew G. Knepley   if (numConstants) {
16797b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr);
16897b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
16957fc01e9SMatthew G. Knepley     for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);}
17097b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
17197b6e6e8SMatthew G. Knepley   }
1727d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
1737d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
1747d8a60eaSMatthew G. Knepley }
1757d8a60eaSMatthew G. Knepley 
1762764a2aaSMatthew G. Knepley /*@C
1772764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
1782764a2aaSMatthew G. Knepley 
1792764a2aaSMatthew G. Knepley   Collective on PetscDS
1802764a2aaSMatthew G. Knepley 
1812764a2aaSMatthew G. Knepley   Input Parameter:
1822764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
1832764a2aaSMatthew G. Knepley - v  - the viewer
1842764a2aaSMatthew G. Knepley 
1852764a2aaSMatthew G. Knepley   Level: developer
1862764a2aaSMatthew G. Knepley 
1872764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
1882764a2aaSMatthew G. Knepley @*/
1892764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
1902764a2aaSMatthew G. Knepley {
1917d8a60eaSMatthew G. Knepley   PetscBool      iascii;
1922764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1932764a2aaSMatthew G. Knepley 
1942764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1952764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1962764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
1977d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
1987d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
1997d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2002764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2012764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2022764a2aaSMatthew G. Knepley }
2032764a2aaSMatthew G. Knepley 
2042764a2aaSMatthew G. Knepley /*@
2052764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2062764a2aaSMatthew G. Knepley 
2072764a2aaSMatthew G. Knepley   Collective on PetscDS
2082764a2aaSMatthew G. Knepley 
2092764a2aaSMatthew G. Knepley   Input Parameter:
2102764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2112764a2aaSMatthew G. Knepley 
2122764a2aaSMatthew G. Knepley   Options Database:
2132764a2aaSMatthew G. Knepley 
2142764a2aaSMatthew G. Knepley   Level: developer
2152764a2aaSMatthew G. Knepley 
2162764a2aaSMatthew G. Knepley .seealso PetscDSView()
2172764a2aaSMatthew G. Knepley @*/
2182764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
2192764a2aaSMatthew G. Knepley {
220f1fd5e65SToby Isaac   DSBoundary     b;
2212764a2aaSMatthew G. Knepley   const char    *defaultType;
2222764a2aaSMatthew G. Knepley   char           name[256];
2232764a2aaSMatthew G. Knepley   PetscBool      flg;
2242764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2252764a2aaSMatthew G. Knepley 
2262764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2272764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2282764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
2292764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
2302764a2aaSMatthew G. Knepley   } else {
2312764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
2322764a2aaSMatthew G. Knepley   }
2330f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
2342764a2aaSMatthew G. Knepley 
2352764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
236f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
237f1fd5e65SToby Isaac     char       optname[1024];
238f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
239f1fd5e65SToby Isaac     PetscBool  flg;
240f1fd5e65SToby Isaac 
241f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
242f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
243f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
244f1fd5e65SToby Isaac     if (flg) {
245f1fd5e65SToby Isaac       b->numids = len;
246f1fd5e65SToby Isaac       ierr = PetscFree(b->ids);CHKERRQ(ierr);
247f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr);
248f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->ids, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
249f1fd5e65SToby Isaac     }
250e7b0402cSSander Arens     len = 1024;
251f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
252f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
253f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
254f1fd5e65SToby Isaac     if (flg) {
255f1fd5e65SToby Isaac       b->numcomps = len;
256f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
257f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
258f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->comps, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
259f1fd5e65SToby Isaac     }
260f1fd5e65SToby Isaac   }
2612764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
2622764a2aaSMatthew G. Knepley   if (flg) {
2632764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
2642764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
2652764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
2662764a2aaSMatthew G. Knepley   }
2672764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
2682764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
2690633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
2702764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
2712764a2aaSMatthew G. Knepley   ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);
2722764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2732764a2aaSMatthew G. Knepley }
2742764a2aaSMatthew G. Knepley 
2752764a2aaSMatthew G. Knepley /*@C
2762764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
2772764a2aaSMatthew G. Knepley 
2782764a2aaSMatthew G. Knepley   Collective on PetscDS
2792764a2aaSMatthew G. Knepley 
2802764a2aaSMatthew G. Knepley   Input Parameter:
2812764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
2822764a2aaSMatthew G. Knepley 
2832764a2aaSMatthew G. Knepley   Level: developer
2842764a2aaSMatthew G. Knepley 
2852764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
2862764a2aaSMatthew G. Knepley @*/
2872764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
2882764a2aaSMatthew G. Knepley {
2892764a2aaSMatthew G. Knepley   const PetscInt Nf = prob->Nf;
2902764a2aaSMatthew G. Knepley   PetscInt       dim, work, NcMax = 0, NqMax = 0, f;
2912764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2922764a2aaSMatthew G. Knepley 
2932764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2942764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2952764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
2962764a2aaSMatthew G. Knepley   /* Calculate sizes */
2972764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
298f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
29947e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
300f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
301f744cafaSSander Arens   ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisFace,Nf,&prob->basisDerFace);CHKERRQ(ierr);
3022764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3039de99aefSMatthew G. Knepley     PetscObject     obj;
3049de99aefSMatthew G. Knepley     PetscClassId    id;
3052764a2aaSMatthew G. Knepley     PetscQuadrature q;
3069de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
3072764a2aaSMatthew G. Knepley 
3089de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3099de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3109de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
3119de99aefSMatthew G. Knepley       PetscFE fe = (PetscFE) obj;
3129de99aefSMatthew G. Knepley 
3132764a2aaSMatthew G. Knepley       ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
3142764a2aaSMatthew G. Knepley       ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
3152764a2aaSMatthew G. Knepley       ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
3162764a2aaSMatthew G. Knepley       ierr = PetscFEGetDefaultTabulation(fe, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3174d0b9603SSander Arens       ierr = PetscFEGetFaceTabulation(fe, &prob->basisFace[f], &prob->basisDerFace[f], NULL);CHKERRQ(ierr);
3189de99aefSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
3199de99aefSMatthew G. Knepley       PetscFV fv = (PetscFV) obj;
3209de99aefSMatthew G. Knepley 
3219de99aefSMatthew G. Knepley       ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
3229de99aefSMatthew G. Knepley       ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
3239c3cf19fSMatthew G. Knepley       Nb   = Nc;
3246c1a3d01SMatthew G. Knepley       ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3254d0b9603SSander Arens       /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
326abac5ca0SMatthew G. Knepley     } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
32747e57110SSander Arens     prob->Nc[f]       = Nc;
32847e57110SSander Arens     prob->Nb[f]       = Nb;
329194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
330194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
331a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
3322764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
3332764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
3349c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
3352764a2aaSMatthew G. Knepley     prob->totComp += Nc;
3362764a2aaSMatthew G. Knepley   }
3372764a2aaSMatthew G. Knepley   work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim));
3382764a2aaSMatthew G. Knepley   /* Allocate works space */
3392764a2aaSMatthew G. Knepley   ierr = PetscMalloc5(prob->totComp,&prob->u,prob->totComp,&prob->u_t,prob->totComp*dim,&prob->u_x,dim,&prob->x,work,&prob->refSpaceDer);CHKERRQ(ierr);
3402764a2aaSMatthew G. Knepley   ierr = PetscMalloc6(NqMax*NcMax,&prob->f0,NqMax*NcMax*dim,&prob->f1,NqMax*NcMax*NcMax,&prob->g0,NqMax*NcMax*NcMax*dim,&prob->g1,NqMax*NcMax*NcMax*dim,&prob->g2,NqMax*NcMax*NcMax*dim*dim,&prob->g3);CHKERRQ(ierr);
3412764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
3422764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
3432764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3442764a2aaSMatthew G. Knepley }
3452764a2aaSMatthew G. Knepley 
3462764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
3472764a2aaSMatthew G. Knepley {
3482764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3492764a2aaSMatthew G. Knepley 
3502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
35147e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
352f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
353f744cafaSSander Arens   ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisFace,prob->basisDerFace);CHKERRQ(ierr);
3542764a2aaSMatthew G. Knepley   ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr);
3552764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
3562764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3572764a2aaSMatthew G. Knepley }
3582764a2aaSMatthew G. Knepley 
3592764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
3602764a2aaSMatthew G. Knepley {
361f744cafaSSander Arens   PetscObject      *tmpd;
362a6cbbb48SMatthew G. Knepley   PetscBool        *tmpi, *tmpa;
36332d2bbc9SMatthew G. Knepley   PetscPointFunc   *tmpobj, *tmpf, *tmpup;
364b7e05686SMatthew G. Knepley   PetscPointJac    *tmpg, *tmpgp, *tmpgt;
3652aa1fc23SMatthew G. Knepley   PetscBdPointFunc *tmpfbd;
3662aa1fc23SMatthew G. Knepley   PetscBdPointJac  *tmpgbd;
367194d53e6SMatthew G. Knepley   PetscRiemannFunc *tmpr;
368c371a6d1SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol;
3690c2f2876SMatthew G. Knepley   void            **tmpctx;
370a6cbbb48SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f, i;
3712764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
3722764a2aaSMatthew G. Knepley 
3732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3742764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
3752764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
3762764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
377f744cafaSSander Arens   ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr);
378f744cafaSSander Arens   for (f = 0; f < Nf; ++f) {tmpd[f] = prob->disc[f]; tmpi[f] = prob->implicit[f]; for (i = 0; i < 2; ++i) tmpa[f*2+i] = prob->adjacency[f*2+i];}
379f744cafaSSander Arens   for (f = Nf; f < NfNew; ++f) {tmpd[f] = NULL; tmpi[f] = PETSC_TRUE; tmpa[f*2+0] = PETSC_FALSE; tmpa[f*2+1] = PETSC_TRUE;}
380f744cafaSSander Arens   ierr = PetscFree3(prob->disc, prob->implicit, prob->adjacency);CHKERRQ(ierr);
3812764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
3822764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
383249df284SMatthew G. Knepley   prob->implicit  = tmpi;
384a6cbbb48SMatthew G. Knepley   prob->adjacency = tmpa;
385b7e05686SMatthew G. Knepley   ierr = PetscCalloc7(NfNew, &tmpobj, NfNew*2, &tmpf, NfNew*NfNew*4, &tmpg, NfNew*NfNew*4, &tmpgp, NfNew*NfNew*4, &tmpgt, NfNew, &tmpr, NfNew, &tmpctx);CHKERRQ(ierr);
38632d2bbc9SMatthew G. Knepley   ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr);
3872764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f];
3882764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f];
3892764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f];
390475e0ac9SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f];
3910c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f];
39232d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
3930c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
3942764a2aaSMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL;
3952764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL;
3962764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL;
397475e0ac9SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL;
398b7e05686SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL;
3990c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL;
40032d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
4010c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
402b7e05686SMatthew G. Knepley   ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr);
40332d2bbc9SMatthew G. Knepley   ierr = PetscFree(prob->update);CHKERRQ(ierr);
4042764a2aaSMatthew G. Knepley   prob->obj = tmpobj;
4052764a2aaSMatthew G. Knepley   prob->f   = tmpf;
4062764a2aaSMatthew G. Knepley   prob->g   = tmpg;
407475e0ac9SMatthew G. Knepley   prob->gp  = tmpgp;
408b7e05686SMatthew G. Knepley   prob->gt  = tmpgt;
4090c2f2876SMatthew G. Knepley   prob->r   = tmpr;
41032d2bbc9SMatthew G. Knepley   prob->update = tmpup;
4110c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
412c371a6d1SMatthew G. Knepley   ierr = PetscCalloc3(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew, &tmpexactSol);CHKERRQ(ierr);
4132764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f];
4142764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f];
415c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
4162764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL;
4172764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL;
418c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
419c371a6d1SMatthew G. Knepley   ierr = PetscFree3(prob->fBd, prob->gBd, prob->exactSol);CHKERRQ(ierr);
4202764a2aaSMatthew G. Knepley   prob->fBd = tmpfbd;
4212764a2aaSMatthew G. Knepley   prob->gBd = tmpgbd;
422c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
4232764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4242764a2aaSMatthew G. Knepley }
4252764a2aaSMatthew G. Knepley 
4262764a2aaSMatthew G. Knepley /*@
4272764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
4282764a2aaSMatthew G. Knepley 
4292764a2aaSMatthew G. Knepley   Collective on PetscDS
4302764a2aaSMatthew G. Knepley 
4312764a2aaSMatthew G. Knepley   Input Parameter:
4322764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
4332764a2aaSMatthew G. Knepley 
4342764a2aaSMatthew G. Knepley   Level: developer
4352764a2aaSMatthew G. Knepley 
4362764a2aaSMatthew G. Knepley .seealso PetscDSView()
4372764a2aaSMatthew G. Knepley @*/
4382764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob)
4392764a2aaSMatthew G. Knepley {
4402764a2aaSMatthew G. Knepley   PetscInt       f;
44158ebd649SToby Isaac   DSBoundary     next;
4422764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4432764a2aaSMatthew G. Knepley 
4442764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4452764a2aaSMatthew G. Knepley   if (!*prob) PetscFunctionReturn(0);
4462764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1);
4472764a2aaSMatthew G. Knepley 
4482764a2aaSMatthew G. Knepley   if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);}
4492764a2aaSMatthew G. Knepley   ((PetscObject) (*prob))->refct = 0;
4502764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr);
4512764a2aaSMatthew G. Knepley   for (f = 0; f < (*prob)->Nf; ++f) {
4522764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr);
4532764a2aaSMatthew G. Knepley   }
454f744cafaSSander Arens   ierr = PetscFree3((*prob)->disc, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr);
455b7e05686SMatthew G. Knepley   ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr);
45632d2bbc9SMatthew G. Knepley   ierr = PetscFree((*prob)->update);CHKERRQ(ierr);
457c371a6d1SMatthew G. Knepley   ierr = PetscFree3((*prob)->fBd,(*prob)->gBd,(*prob)->exactSol);CHKERRQ(ierr);
4582764a2aaSMatthew G. Knepley   if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);}
45958ebd649SToby Isaac   next = (*prob)->boundary;
46058ebd649SToby Isaac   while (next) {
46158ebd649SToby Isaac     DSBoundary b = next;
46258ebd649SToby Isaac 
46358ebd649SToby Isaac     next = b->next;
46458ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
46558ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
46658ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
46758ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
46858ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
46958ebd649SToby Isaac   }
47097b6e6e8SMatthew G. Knepley   ierr = PetscFree((*prob)->constants);CHKERRQ(ierr);
4712764a2aaSMatthew G. Knepley   ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr);
4722764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4732764a2aaSMatthew G. Knepley }
4742764a2aaSMatthew G. Knepley 
4752764a2aaSMatthew G. Knepley /*@
4762764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
4772764a2aaSMatthew G. Knepley 
4782764a2aaSMatthew G. Knepley   Collective on MPI_Comm
4792764a2aaSMatthew G. Knepley 
4802764a2aaSMatthew G. Knepley   Input Parameter:
4812764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
4822764a2aaSMatthew G. Knepley 
4832764a2aaSMatthew G. Knepley   Output Parameter:
4842764a2aaSMatthew G. Knepley . prob - The PetscDS object
4852764a2aaSMatthew G. Knepley 
4862764a2aaSMatthew G. Knepley   Level: beginner
4872764a2aaSMatthew G. Knepley 
4882764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
4892764a2aaSMatthew G. Knepley @*/
4902764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob)
4912764a2aaSMatthew G. Knepley {
4922764a2aaSMatthew G. Knepley   PetscDS   p;
4932764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4942764a2aaSMatthew G. Knepley 
4952764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4962764a2aaSMatthew G. Knepley   PetscValidPointer(prob, 2);
4972764a2aaSMatthew G. Knepley   *prob  = NULL;
4982764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
4992764a2aaSMatthew G. Knepley 
50073107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5012764a2aaSMatthew G. Knepley 
5022764a2aaSMatthew G. Knepley   p->Nf    = 0;
5032764a2aaSMatthew G. Knepley   p->setup = PETSC_FALSE;
50497b6e6e8SMatthew G. Knepley   p->numConstants  = 0;
50597b6e6e8SMatthew G. Knepley   p->constants     = NULL;
506*03d90f89SMatthew G. Knepley   p->defaultAdj[0] = PETSC_FALSE;
507*03d90f89SMatthew G. Knepley   p->defaultAdj[1] = PETSC_TRUE;
5082764a2aaSMatthew G. Knepley 
5092764a2aaSMatthew G. Knepley   *prob = p;
5102764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5112764a2aaSMatthew G. Knepley }
5122764a2aaSMatthew G. Knepley 
513bc4ae4beSMatthew G. Knepley /*@
514bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
515bc4ae4beSMatthew G. Knepley 
516bc4ae4beSMatthew G. Knepley   Not collective
517bc4ae4beSMatthew G. Knepley 
518bc4ae4beSMatthew G. Knepley   Input Parameter:
519bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
520bc4ae4beSMatthew G. Knepley 
521bc4ae4beSMatthew G. Knepley   Output Parameter:
522bc4ae4beSMatthew G. Knepley . Nf - The number of fields
523bc4ae4beSMatthew G. Knepley 
524bc4ae4beSMatthew G. Knepley   Level: beginner
525bc4ae4beSMatthew G. Knepley 
526bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
527bc4ae4beSMatthew G. Knepley @*/
5282764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
5292764a2aaSMatthew G. Knepley {
5302764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5312764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5322764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
5332764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
5342764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5352764a2aaSMatthew G. Knepley }
5362764a2aaSMatthew G. Knepley 
537bc4ae4beSMatthew G. Knepley /*@
538bc4ae4beSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS
539bc4ae4beSMatthew G. Knepley 
540bc4ae4beSMatthew G. Knepley   Not collective
541bc4ae4beSMatthew G. Knepley 
542bc4ae4beSMatthew G. Knepley   Input Parameter:
543bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
544bc4ae4beSMatthew G. Knepley 
545bc4ae4beSMatthew G. Knepley   Output Parameter:
546bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
547bc4ae4beSMatthew G. Knepley 
548bc4ae4beSMatthew G. Knepley   Level: beginner
549bc4ae4beSMatthew G. Knepley 
550bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
551bc4ae4beSMatthew G. Knepley @*/
5522764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
5532764a2aaSMatthew G. Knepley {
5542764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5552764a2aaSMatthew G. Knepley 
5562764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5572764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5582764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
5592764a2aaSMatthew G. Knepley   *dim = 0;
5609de99aefSMatthew G. Knepley   if (prob->Nf) {
5619de99aefSMatthew G. Knepley     PetscObject  obj;
5629de99aefSMatthew G. Knepley     PetscClassId id;
5639de99aefSMatthew G. Knepley 
5649de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
5659de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
5669de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
5679de99aefSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
5689de99aefSMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
5699de99aefSMatthew G. Knepley   }
5702764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5712764a2aaSMatthew G. Knepley }
5722764a2aaSMatthew G. Knepley 
573bc4ae4beSMatthew G. Knepley /*@
574bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
575bc4ae4beSMatthew G. Knepley 
576bc4ae4beSMatthew G. Knepley   Not collective
577bc4ae4beSMatthew G. Knepley 
578bc4ae4beSMatthew G. Knepley   Input Parameter:
579bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
580bc4ae4beSMatthew G. Knepley 
581bc4ae4beSMatthew G. Knepley   Output Parameter:
582bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
583bc4ae4beSMatthew G. Knepley 
584bc4ae4beSMatthew G. Knepley   Level: beginner
585bc4ae4beSMatthew G. Knepley 
586bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
587bc4ae4beSMatthew G. Knepley @*/
5882764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
5892764a2aaSMatthew G. Knepley {
5902764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5912764a2aaSMatthew G. Knepley 
5922764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5932764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5942764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
5952764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
5962764a2aaSMatthew G. Knepley   *dim = prob->totDim;
5972764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5982764a2aaSMatthew G. Knepley }
5992764a2aaSMatthew G. Knepley 
600bc4ae4beSMatthew G. Knepley /*@
601bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
602bc4ae4beSMatthew G. Knepley 
603bc4ae4beSMatthew G. Knepley   Not collective
604bc4ae4beSMatthew G. Knepley 
605bc4ae4beSMatthew G. Knepley   Input Parameter:
606bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
607bc4ae4beSMatthew G. Knepley 
608bc4ae4beSMatthew G. Knepley   Output Parameter:
609bc4ae4beSMatthew G. Knepley . dim - The total number of components
610bc4ae4beSMatthew G. Knepley 
611bc4ae4beSMatthew G. Knepley   Level: beginner
612bc4ae4beSMatthew G. Knepley 
613bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
614bc4ae4beSMatthew G. Knepley @*/
6152764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
6162764a2aaSMatthew G. Knepley {
6172764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6182764a2aaSMatthew G. Knepley 
6192764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6202764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6212764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6222764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
6232764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
6242764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6252764a2aaSMatthew G. Knepley }
6262764a2aaSMatthew G. Knepley 
627bc4ae4beSMatthew G. Knepley /*@
628bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
629bc4ae4beSMatthew G. Knepley 
630bc4ae4beSMatthew G. Knepley   Not collective
631bc4ae4beSMatthew G. Knepley 
632bc4ae4beSMatthew G. Knepley   Input Parameters:
633bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
634bc4ae4beSMatthew G. Knepley - f - The field number
635bc4ae4beSMatthew G. Knepley 
636bc4ae4beSMatthew G. Knepley   Output Parameter:
637bc4ae4beSMatthew G. Knepley . disc - The discretization object
638bc4ae4beSMatthew G. Knepley 
639bc4ae4beSMatthew G. Knepley   Level: beginner
640bc4ae4beSMatthew G. Knepley 
641f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
642bc4ae4beSMatthew G. Knepley @*/
6432764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
6442764a2aaSMatthew G. Knepley {
6452764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6462764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6472764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
6482764a2aaSMatthew 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);
6492764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
6502764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6512764a2aaSMatthew G. Knepley }
6522764a2aaSMatthew G. Knepley 
653bc4ae4beSMatthew G. Knepley /*@
654bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
655bc4ae4beSMatthew G. Knepley 
656bc4ae4beSMatthew G. Knepley   Not collective
657bc4ae4beSMatthew G. Knepley 
658bc4ae4beSMatthew G. Knepley   Input Parameters:
659bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
660bc4ae4beSMatthew G. Knepley . f - The field number
661bc4ae4beSMatthew G. Knepley - disc - The discretization object
662bc4ae4beSMatthew G. Knepley 
663bc4ae4beSMatthew G. Knepley   Level: beginner
664bc4ae4beSMatthew G. Knepley 
665bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
666bc4ae4beSMatthew G. Knepley @*/
6672764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
6682764a2aaSMatthew G. Knepley {
6692764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6702764a2aaSMatthew G. Knepley 
6712764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6722764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6732764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
6742764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
6752764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
6762764a2aaSMatthew G. Knepley   if (prob->disc[f]) {ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);}
6772764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
6782764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
679249df284SMatthew G. Knepley   {
680249df284SMatthew G. Knepley     PetscClassId id;
681249df284SMatthew G. Knepley 
682249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
6831cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
6841cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr);
6851cf84007SMatthew G. Knepley       ierr = PetscDSSetAdjacency(prob, f, PETSC_FALSE, PETSC_TRUE);CHKERRQ(ierr);
6861cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
6871cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr);
6881cf84007SMatthew G. Knepley       ierr = PetscDSSetAdjacency(prob, f, PETSC_TRUE, PETSC_FALSE);CHKERRQ(ierr);
689a6cbbb48SMatthew G. Knepley     }
690249df284SMatthew G. Knepley   }
6912764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6922764a2aaSMatthew G. Knepley }
6932764a2aaSMatthew G. Knepley 
694bc4ae4beSMatthew G. Knepley /*@
695bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
696bc4ae4beSMatthew G. Knepley 
697bc4ae4beSMatthew G. Knepley   Not collective
698bc4ae4beSMatthew G. Knepley 
699bc4ae4beSMatthew G. Knepley   Input Parameters:
700bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
701bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
702bc4ae4beSMatthew G. Knepley 
703bc4ae4beSMatthew G. Knepley   Level: beginner
704bc4ae4beSMatthew G. Knepley 
705bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
706bc4ae4beSMatthew G. Knepley @*/
7072764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
7082764a2aaSMatthew G. Knepley {
7092764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7102764a2aaSMatthew G. Knepley 
7112764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7122764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
7132764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7142764a2aaSMatthew G. Knepley }
7152764a2aaSMatthew G. Knepley 
716249df284SMatthew G. Knepley /*@
717249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
718249df284SMatthew G. Knepley 
719249df284SMatthew G. Knepley   Not collective
720249df284SMatthew G. Knepley 
721249df284SMatthew G. Knepley   Input Parameters:
722249df284SMatthew G. Knepley + prob - The PetscDS object
723249df284SMatthew G. Knepley - f - The field number
724249df284SMatthew G. Knepley 
725249df284SMatthew G. Knepley   Output Parameter:
726249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
727249df284SMatthew G. Knepley 
728249df284SMatthew G. Knepley   Level: developer
729249df284SMatthew G. Knepley 
730f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
731249df284SMatthew G. Knepley @*/
732249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
733249df284SMatthew G. Knepley {
734249df284SMatthew G. Knepley   PetscFunctionBegin;
735249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
736249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
737249df284SMatthew 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);
738249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
739249df284SMatthew G. Knepley   PetscFunctionReturn(0);
740249df284SMatthew G. Knepley }
741249df284SMatthew G. Knepley 
742249df284SMatthew G. Knepley /*@
743249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
744249df284SMatthew G. Knepley 
745249df284SMatthew G. Knepley   Not collective
746249df284SMatthew G. Knepley 
747249df284SMatthew G. Knepley   Input Parameters:
748249df284SMatthew G. Knepley + prob - The PetscDS object
749249df284SMatthew G. Knepley . f - The field number
750249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
751249df284SMatthew G. Knepley 
752249df284SMatthew G. Knepley   Level: developer
753249df284SMatthew G. Knepley 
754f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
755249df284SMatthew G. Knepley @*/
756249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
757249df284SMatthew G. Knepley {
758249df284SMatthew G. Knepley   PetscFunctionBegin;
759249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
760249df284SMatthew 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);
761249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
762249df284SMatthew G. Knepley   PetscFunctionReturn(0);
763249df284SMatthew G. Knepley }
764249df284SMatthew G. Knepley 
765a6cbbb48SMatthew G. Knepley /*@
766a6cbbb48SMatthew G. Knepley   PetscDSGetAdjacency - Returns the flags for determining variable influence
767a6cbbb48SMatthew G. Knepley 
768a6cbbb48SMatthew G. Knepley   Not collective
769a6cbbb48SMatthew G. Knepley 
770a6cbbb48SMatthew G. Knepley   Input Parameters:
771a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
772a6cbbb48SMatthew G. Knepley - f - The field number
773a6cbbb48SMatthew G. Knepley 
774a6cbbb48SMatthew G. Knepley   Output Parameter:
775a6cbbb48SMatthew G. Knepley + useCone    - Flag for variable influence starting with the cone operation
776a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
777a6cbbb48SMatthew G. Knepley 
778a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
779a6cbbb48SMatthew G. Knepley 
780a6cbbb48SMatthew G. Knepley   Level: developer
781a6cbbb48SMatthew G. Knepley 
782f744cafaSSander Arens .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
783a6cbbb48SMatthew G. Knepley @*/
784a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure)
785a6cbbb48SMatthew G. Knepley {
786a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
787a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7881cf84007SMatthew G. Knepley   if (useCone) PetscValidPointer(useCone, 3);
7891cf84007SMatthew G. Knepley   if (useClosure) PetscValidPointer(useClosure, 4);
79006cc46feSMatthew G. Knepley   if (f < 0) {
79106cc46feSMatthew G. Knepley     if (useCone)    *useCone    = prob->defaultAdj[0];
79206cc46feSMatthew G. Knepley     if (useClosure) *useClosure = prob->defaultAdj[1];
79306cc46feSMatthew G. Knepley   } else {
79406cc46feSMatthew G. Knepley     if (f >= prob->Nf) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
7951cf84007SMatthew G. Knepley     if (useCone)    *useCone    = prob->adjacency[f*2+0];
7961cf84007SMatthew G. Knepley     if (useClosure) *useClosure = prob->adjacency[f*2+1];
79706cc46feSMatthew G. Knepley   }
798a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
799a6cbbb48SMatthew G. Knepley }
800a6cbbb48SMatthew G. Knepley 
801a6cbbb48SMatthew G. Knepley /*@
802a6cbbb48SMatthew G. Knepley   PetscDSSetAdjacency - Set the flags for determining variable influence
803a6cbbb48SMatthew G. Knepley 
804a6cbbb48SMatthew G. Knepley   Not collective
805a6cbbb48SMatthew G. Knepley 
806a6cbbb48SMatthew G. Knepley   Input Parameters:
807a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
808a6cbbb48SMatthew G. Knepley . f - The field number
809a6cbbb48SMatthew G. Knepley . useCone    - Flag for variable influence starting with the cone operation
810a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
811a6cbbb48SMatthew G. Knepley 
812a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
813a6cbbb48SMatthew G. Knepley 
814a6cbbb48SMatthew G. Knepley   Level: developer
815a6cbbb48SMatthew G. Knepley 
816f744cafaSSander Arens .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
817a6cbbb48SMatthew G. Knepley @*/
818a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure)
819a6cbbb48SMatthew G. Knepley {
820a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
821a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
82206cc46feSMatthew G. Knepley   if (f < 0) {
82306cc46feSMatthew G. Knepley     prob->defaultAdj[0] = useCone;
82406cc46feSMatthew G. Knepley     prob->defaultAdj[1] = useClosure;
82506cc46feSMatthew G. Knepley   } else {
82606cc46feSMatthew G. Knepley     if (f >= prob->Nf) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
827a6cbbb48SMatthew G. Knepley     prob->adjacency[f*2+0] = useCone;
828a6cbbb48SMatthew G. Knepley     prob->adjacency[f*2+1] = useClosure;
82906cc46feSMatthew G. Knepley   }
830a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
831a6cbbb48SMatthew G. Knepley }
832a6cbbb48SMatthew G. Knepley 
8332764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f,
83430b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
835194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
836194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
83797b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
8382764a2aaSMatthew G. Knepley {
8392764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8402764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8412764a2aaSMatthew G. Knepley   PetscValidPointer(obj, 2);
8422764a2aaSMatthew 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);
8432764a2aaSMatthew G. Knepley   *obj = prob->obj[f];
8442764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8452764a2aaSMatthew G. Knepley }
8462764a2aaSMatthew G. Knepley 
8472764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f,
84830b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
849194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
850194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
85197b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
8522764a2aaSMatthew G. Knepley {
8532764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8542764a2aaSMatthew G. Knepley 
8552764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8562764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
857de716cbcSToby Isaac   if (obj) PetscValidFunction(obj, 2);
8582764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
8592764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
8602764a2aaSMatthew G. Knepley   prob->obj[f] = obj;
8612764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8622764a2aaSMatthew G. Knepley }
8632764a2aaSMatthew G. Knepley 
864194d53e6SMatthew G. Knepley /*@C
865194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
866194d53e6SMatthew G. Knepley 
867194d53e6SMatthew G. Knepley   Not collective
868194d53e6SMatthew G. Knepley 
869194d53e6SMatthew G. Knepley   Input Parameters:
870194d53e6SMatthew G. Knepley + prob - The PetscDS
871194d53e6SMatthew G. Knepley - f    - The test field number
872194d53e6SMatthew G. Knepley 
873194d53e6SMatthew G. Knepley   Output Parameters:
874194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
875194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
876194d53e6SMatthew G. Knepley 
877194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
878194d53e6SMatthew G. Knepley 
879194d53e6SMatthew 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)
880194d53e6SMatthew G. Knepley 
881194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
882194d53e6SMatthew G. Knepley 
88330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
884194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
885194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
88630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
887194d53e6SMatthew G. Knepley 
888194d53e6SMatthew G. Knepley + dim - the spatial dimension
889194d53e6SMatthew G. Knepley . Nf - the number of fields
890194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
891194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
892194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
893194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
894194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
895194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
896194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
897194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
898194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
899194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
900194d53e6SMatthew G. Knepley . t - current time
901194d53e6SMatthew G. Knepley . x - coordinates of the current point
90297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
90397b6e6e8SMatthew G. Knepley . constants - constant parameters
904194d53e6SMatthew G. Knepley - f0 - output values at the current point
905194d53e6SMatthew G. Knepley 
906194d53e6SMatthew G. Knepley   Level: intermediate
907194d53e6SMatthew G. Knepley 
908194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
909194d53e6SMatthew G. Knepley @*/
9102764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f,
91130b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
912194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
913194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
91497b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
91530b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
916194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
917194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
91897b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
9192764a2aaSMatthew G. Knepley {
9202764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9212764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9222764a2aaSMatthew 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);
9232764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];}
9242764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];}
9252764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9262764a2aaSMatthew G. Knepley }
9272764a2aaSMatthew G. Knepley 
928194d53e6SMatthew G. Knepley /*@C
929194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
930194d53e6SMatthew G. Knepley 
931194d53e6SMatthew G. Knepley   Not collective
932194d53e6SMatthew G. Knepley 
933194d53e6SMatthew G. Knepley   Input Parameters:
934194d53e6SMatthew G. Knepley + prob - The PetscDS
935194d53e6SMatthew G. Knepley . f    - The test field number
936194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
937194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
938194d53e6SMatthew G. Knepley 
939194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
940194d53e6SMatthew G. Knepley 
941194d53e6SMatthew 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)
942194d53e6SMatthew G. Knepley 
943194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
944194d53e6SMatthew G. Knepley 
94530b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
946194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
947194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
94830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
949194d53e6SMatthew G. Knepley 
950194d53e6SMatthew G. Knepley + dim - the spatial dimension
951194d53e6SMatthew G. Knepley . Nf - the number of fields
952194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
953194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
954194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
955194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
956194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
957194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
958194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
959194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
960194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
961194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
962194d53e6SMatthew G. Knepley . t - current time
963194d53e6SMatthew G. Knepley . x - coordinates of the current point
96497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
96597b6e6e8SMatthew G. Knepley . constants - constant parameters
966194d53e6SMatthew G. Knepley - f0 - output values at the current point
967194d53e6SMatthew G. Knepley 
968194d53e6SMatthew G. Knepley   Level: intermediate
969194d53e6SMatthew G. Knepley 
970194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
971194d53e6SMatthew G. Knepley @*/
9722764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f,
97330b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
974194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
975194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
97697b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
97730b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
978194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
979194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
98097b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
9812764a2aaSMatthew G. Knepley {
9822764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9832764a2aaSMatthew G. Knepley 
9842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9852764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
986f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
987f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
9882764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
9892764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
9902764a2aaSMatthew G. Knepley   prob->f[f*2+0] = f0;
9912764a2aaSMatthew G. Knepley   prob->f[f*2+1] = f1;
9922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9932764a2aaSMatthew G. Knepley }
9942764a2aaSMatthew G. Knepley 
9953e75805dSMatthew G. Knepley /*@C
9963e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
9973e75805dSMatthew G. Knepley 
9983e75805dSMatthew G. Knepley   Not collective
9993e75805dSMatthew G. Knepley 
10003e75805dSMatthew G. Knepley   Input Parameter:
10013e75805dSMatthew G. Knepley . prob - The PetscDS
10023e75805dSMatthew G. Knepley 
10033e75805dSMatthew G. Knepley   Output Parameter:
10043e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
10053e75805dSMatthew G. Knepley 
10063e75805dSMatthew G. Knepley   Level: intermediate
10073e75805dSMatthew G. Knepley 
10083e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
10093e75805dSMatthew G. Knepley @*/
10103e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac)
10113e75805dSMatthew G. Knepley {
10123e75805dSMatthew G. Knepley   PetscInt f, g, h;
10133e75805dSMatthew G. Knepley 
10143e75805dSMatthew G. Knepley   PetscFunctionBegin;
10153e75805dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10163e75805dSMatthew G. Knepley   *hasJac = PETSC_FALSE;
10173e75805dSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
10183e75805dSMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
10193e75805dSMatthew G. Knepley       for (h = 0; h < 4; ++h) {
10203e75805dSMatthew G. Knepley         if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE;
10213e75805dSMatthew G. Knepley       }
10223e75805dSMatthew G. Knepley     }
10233e75805dSMatthew G. Knepley   }
10243e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
10253e75805dSMatthew G. Knepley }
10263e75805dSMatthew G. Knepley 
1027194d53e6SMatthew G. Knepley /*@C
1028194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1029194d53e6SMatthew G. Knepley 
1030194d53e6SMatthew G. Knepley   Not collective
1031194d53e6SMatthew G. Knepley 
1032194d53e6SMatthew G. Knepley   Input Parameters:
1033194d53e6SMatthew G. Knepley + prob - The PetscDS
1034194d53e6SMatthew G. Knepley . f    - The test field number
1035194d53e6SMatthew G. Knepley - g    - The field number
1036194d53e6SMatthew G. Knepley 
1037194d53e6SMatthew G. Knepley   Output Parameters:
1038194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1039194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1040194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1041194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1042194d53e6SMatthew G. Knepley 
1043194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1044194d53e6SMatthew G. Knepley 
1045194d53e6SMatthew 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
1046194d53e6SMatthew G. Knepley 
1047194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1048194d53e6SMatthew G. Knepley 
104930b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1050194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1051194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
105230b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1053194d53e6SMatthew G. Knepley 
1054194d53e6SMatthew G. Knepley + dim - the spatial dimension
1055194d53e6SMatthew G. Knepley . Nf - the number of fields
1056194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1057194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1058194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1059194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1060194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1061194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1062194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1063194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1064194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1065194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1066194d53e6SMatthew G. Knepley . t - current time
10672aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1068194d53e6SMatthew G. Knepley . x - coordinates of the current point
106997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
107097b6e6e8SMatthew G. Knepley . constants - constant parameters
1071194d53e6SMatthew G. Knepley - g0 - output values at the current point
1072194d53e6SMatthew G. Knepley 
1073194d53e6SMatthew G. Knepley   Level: intermediate
1074194d53e6SMatthew G. Knepley 
1075194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1076194d53e6SMatthew G. Knepley @*/
10772764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g,
107830b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1079194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1080194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
108197b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
108230b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1083194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1084194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
108597b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
108630b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1087194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1088194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
108997b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
109030b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1091194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1092194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
109397b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
10942764a2aaSMatthew G. Knepley {
10952764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10962764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10972764a2aaSMatthew 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);
10982764a2aaSMatthew 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);
10992764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];}
11002764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];}
11012764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];}
11022764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];}
11032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11042764a2aaSMatthew G. Knepley }
11052764a2aaSMatthew G. Knepley 
1106194d53e6SMatthew G. Knepley /*@C
1107194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1108194d53e6SMatthew G. Knepley 
1109194d53e6SMatthew G. Knepley   Not collective
1110194d53e6SMatthew G. Knepley 
1111194d53e6SMatthew G. Knepley   Input Parameters:
1112194d53e6SMatthew G. Knepley + prob - The PetscDS
1113194d53e6SMatthew G. Knepley . f    - The test field number
1114194d53e6SMatthew G. Knepley . g    - The field number
1115194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1116194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1117194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1118194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1119194d53e6SMatthew G. Knepley 
1120194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1121194d53e6SMatthew G. Knepley 
1122194d53e6SMatthew 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
1123194d53e6SMatthew G. Knepley 
1124194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1125194d53e6SMatthew G. Knepley 
112630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1127194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1128194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
112930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1130194d53e6SMatthew G. Knepley 
1131194d53e6SMatthew G. Knepley + dim - the spatial dimension
1132194d53e6SMatthew G. Knepley . Nf - the number of fields
1133194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1134194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1135194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1136194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1137194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1138194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1139194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1140194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1141194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1142194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1143194d53e6SMatthew G. Knepley . t - current time
11442aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1145194d53e6SMatthew G. Knepley . x - coordinates of the current point
114697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
114797b6e6e8SMatthew G. Knepley . constants - constant parameters
1148194d53e6SMatthew G. Knepley - g0 - output values at the current point
1149194d53e6SMatthew G. Knepley 
1150194d53e6SMatthew G. Knepley   Level: intermediate
1151194d53e6SMatthew G. Knepley 
1152194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1153194d53e6SMatthew G. Knepley @*/
11542764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g,
115530b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1156194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1157194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
115897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
115930b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1160194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1161194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
116297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
116330b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1164194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1165194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
116697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
116730b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1168194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1169194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
117097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
11712764a2aaSMatthew G. Knepley {
11722764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
11732764a2aaSMatthew G. Knepley 
11742764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11752764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11762764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
11772764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
11782764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
11792764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
11802764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
11812764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
11822764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
11832764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+0] = g0;
11842764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+1] = g1;
11852764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+2] = g2;
11862764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+3] = g3;
11872764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11882764a2aaSMatthew G. Knepley }
11892764a2aaSMatthew G. Knepley 
1190475e0ac9SMatthew G. Knepley /*@C
1191475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1192475e0ac9SMatthew G. Knepley 
1193475e0ac9SMatthew G. Knepley   Not collective
1194475e0ac9SMatthew G. Knepley 
1195475e0ac9SMatthew G. Knepley   Input Parameter:
1196475e0ac9SMatthew G. Knepley . prob - The PetscDS
1197475e0ac9SMatthew G. Knepley 
1198475e0ac9SMatthew G. Knepley   Output Parameter:
1199475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1200475e0ac9SMatthew G. Knepley 
1201475e0ac9SMatthew G. Knepley   Level: intermediate
1202475e0ac9SMatthew G. Knepley 
1203475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1204475e0ac9SMatthew G. Knepley @*/
1205475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre)
1206475e0ac9SMatthew G. Knepley {
1207475e0ac9SMatthew G. Knepley   PetscInt f, g, h;
1208475e0ac9SMatthew G. Knepley 
1209475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1210475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1211475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
1212475e0ac9SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1213475e0ac9SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1214475e0ac9SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1215475e0ac9SMatthew G. Knepley         if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE;
1216475e0ac9SMatthew G. Knepley       }
1217475e0ac9SMatthew G. Knepley     }
1218475e0ac9SMatthew G. Knepley   }
1219475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1220475e0ac9SMatthew G. Knepley }
1221475e0ac9SMatthew G. Knepley 
1222475e0ac9SMatthew G. Knepley /*@C
1223475e0ac9SMatthew 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.
1224475e0ac9SMatthew G. Knepley 
1225475e0ac9SMatthew G. Knepley   Not collective
1226475e0ac9SMatthew G. Knepley 
1227475e0ac9SMatthew G. Knepley   Input Parameters:
1228475e0ac9SMatthew G. Knepley + prob - The PetscDS
1229475e0ac9SMatthew G. Knepley . f    - The test field number
1230475e0ac9SMatthew G. Knepley - g    - The field number
1231475e0ac9SMatthew G. Knepley 
1232475e0ac9SMatthew G. Knepley   Output Parameters:
1233475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1234475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1235475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1236475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1237475e0ac9SMatthew G. Knepley 
1238475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1239475e0ac9SMatthew G. Knepley 
1240475e0ac9SMatthew 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
1241475e0ac9SMatthew G. Knepley 
1242475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1243475e0ac9SMatthew G. Knepley 
1244475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1245475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1246475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1247475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1248475e0ac9SMatthew G. Knepley 
1249475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1250475e0ac9SMatthew G. Knepley . Nf - the number of fields
1251475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1252475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1253475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1254475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1255475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1256475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1257475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1258475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1259475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1260475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1261475e0ac9SMatthew G. Knepley . t - current time
1262475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1263475e0ac9SMatthew G. Knepley . x - coordinates of the current point
126497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
126597b6e6e8SMatthew G. Knepley . constants - constant parameters
1266475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1267475e0ac9SMatthew G. Knepley 
1268475e0ac9SMatthew G. Knepley   Level: intermediate
1269475e0ac9SMatthew G. Knepley 
1270475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1271475e0ac9SMatthew G. Knepley @*/
1272475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1273475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1274475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1275475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
127697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1277475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1278475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1279475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
128097b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1281475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1282475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1283475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
128497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1285475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1286475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1287475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
128897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1289475e0ac9SMatthew G. Knepley {
1290475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1291475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1292475e0ac9SMatthew 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);
1293475e0ac9SMatthew 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);
1294475e0ac9SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];}
1295475e0ac9SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];}
1296475e0ac9SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];}
1297475e0ac9SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];}
1298475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1299475e0ac9SMatthew G. Knepley }
1300475e0ac9SMatthew G. Knepley 
1301475e0ac9SMatthew G. Knepley /*@C
1302475e0ac9SMatthew 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.
1303475e0ac9SMatthew G. Knepley 
1304475e0ac9SMatthew G. Knepley   Not collective
1305475e0ac9SMatthew G. Knepley 
1306475e0ac9SMatthew G. Knepley   Input Parameters:
1307475e0ac9SMatthew G. Knepley + prob - The PetscDS
1308475e0ac9SMatthew G. Knepley . f    - The test field number
1309475e0ac9SMatthew G. Knepley . g    - The field number
1310475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1311475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1312475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1313475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1314475e0ac9SMatthew G. Knepley 
1315475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1316475e0ac9SMatthew G. Knepley 
1317475e0ac9SMatthew 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
1318475e0ac9SMatthew G. Knepley 
1319475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1320475e0ac9SMatthew G. Knepley 
1321475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1322475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1323475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1324475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1325475e0ac9SMatthew G. Knepley 
1326475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1327475e0ac9SMatthew G. Knepley . Nf - the number of fields
1328475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1329475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1330475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1331475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1332475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1333475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1334475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1335475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1336475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1337475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1338475e0ac9SMatthew G. Knepley . t - current time
1339475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1340475e0ac9SMatthew G. Knepley . x - coordinates of the current point
134197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
134297b6e6e8SMatthew G. Knepley . constants - constant parameters
1343475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1344475e0ac9SMatthew G. Knepley 
1345475e0ac9SMatthew G. Knepley   Level: intermediate
1346475e0ac9SMatthew G. Knepley 
1347475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1348475e0ac9SMatthew G. Knepley @*/
1349475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1350475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1351475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1352475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
135397b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1354475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1355475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1356475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
135797b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1358475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1359475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1360475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
136197b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1362475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1363475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1364475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
136597b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1366475e0ac9SMatthew G. Knepley {
1367475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1368475e0ac9SMatthew G. Knepley 
1369475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1370475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1371475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1372475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1373475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1374475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1375475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1376475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1377475e0ac9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1378475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+0] = g0;
1379475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+1] = g1;
1380475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+2] = g2;
1381475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+3] = g3;
1382475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1383475e0ac9SMatthew G. Knepley }
1384475e0ac9SMatthew G. Knepley 
1385b7e05686SMatthew G. Knepley /*@C
1386b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1387b7e05686SMatthew G. Knepley 
1388b7e05686SMatthew G. Knepley   Not collective
1389b7e05686SMatthew G. Knepley 
1390b7e05686SMatthew G. Knepley   Input Parameter:
1391b7e05686SMatthew G. Knepley . prob - The PetscDS
1392b7e05686SMatthew G. Knepley 
1393b7e05686SMatthew G. Knepley   Output Parameter:
1394b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1395b7e05686SMatthew G. Knepley 
1396b7e05686SMatthew G. Knepley   Level: intermediate
1397b7e05686SMatthew G. Knepley 
1398b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1399b7e05686SMatthew G. Knepley @*/
1400b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac)
1401b7e05686SMatthew G. Knepley {
1402b7e05686SMatthew G. Knepley   PetscInt f, g, h;
1403b7e05686SMatthew G. Knepley 
1404b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1405b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1406b7e05686SMatthew G. Knepley   *hasDynJac = PETSC_FALSE;
1407b7e05686SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1408b7e05686SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1409b7e05686SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1410b7e05686SMatthew G. Knepley         if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE;
1411b7e05686SMatthew G. Knepley       }
1412b7e05686SMatthew G. Knepley     }
1413b7e05686SMatthew G. Knepley   }
1414b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1415b7e05686SMatthew G. Knepley }
1416b7e05686SMatthew G. Knepley 
1417b7e05686SMatthew G. Knepley /*@C
1418b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1419b7e05686SMatthew G. Knepley 
1420b7e05686SMatthew G. Knepley   Not collective
1421b7e05686SMatthew G. Knepley 
1422b7e05686SMatthew G. Knepley   Input Parameters:
1423b7e05686SMatthew G. Knepley + prob - The PetscDS
1424b7e05686SMatthew G. Knepley . f    - The test field number
1425b7e05686SMatthew G. Knepley - g    - The field number
1426b7e05686SMatthew G. Knepley 
1427b7e05686SMatthew G. Knepley   Output Parameters:
1428b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1429b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1430b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1431b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1432b7e05686SMatthew G. Knepley 
1433b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1434b7e05686SMatthew G. Knepley 
1435b7e05686SMatthew 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
1436b7e05686SMatthew G. Knepley 
1437b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1438b7e05686SMatthew G. Knepley 
1439b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1440b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1441b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1442b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1443b7e05686SMatthew G. Knepley 
1444b7e05686SMatthew G. Knepley + dim - the spatial dimension
1445b7e05686SMatthew G. Knepley . Nf - the number of fields
1446b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1447b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1448b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1449b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1450b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1451b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1452b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1453b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1454b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1455b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1456b7e05686SMatthew G. Knepley . t - current time
1457b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1458b7e05686SMatthew G. Knepley . x - coordinates of the current point
145997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
146097b6e6e8SMatthew G. Knepley . constants - constant parameters
1461b7e05686SMatthew G. Knepley - g0 - output values at the current point
1462b7e05686SMatthew G. Knepley 
1463b7e05686SMatthew G. Knepley   Level: intermediate
1464b7e05686SMatthew G. Knepley 
1465b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1466b7e05686SMatthew G. Knepley @*/
1467b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1468b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1469b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1470b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
147197b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1472b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1473b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1474b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
147597b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1476b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1477b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1478b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
147997b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1480b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1481b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1482b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
148397b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1484b7e05686SMatthew G. Knepley {
1485b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1486b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1487b7e05686SMatthew 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);
1488b7e05686SMatthew 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);
1489b7e05686SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];}
1490b7e05686SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];}
1491b7e05686SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];}
1492b7e05686SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];}
1493b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1494b7e05686SMatthew G. Knepley }
1495b7e05686SMatthew G. Knepley 
1496b7e05686SMatthew G. Knepley /*@C
1497b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1498b7e05686SMatthew G. Knepley 
1499b7e05686SMatthew G. Knepley   Not collective
1500b7e05686SMatthew G. Knepley 
1501b7e05686SMatthew G. Knepley   Input Parameters:
1502b7e05686SMatthew G. Knepley + prob - The PetscDS
1503b7e05686SMatthew G. Knepley . f    - The test field number
1504b7e05686SMatthew G. Knepley . g    - The field number
1505b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1506b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1507b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1508b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1509b7e05686SMatthew G. Knepley 
1510b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1511b7e05686SMatthew G. Knepley 
1512b7e05686SMatthew 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
1513b7e05686SMatthew G. Knepley 
1514b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1515b7e05686SMatthew G. Knepley 
1516b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1517b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1518b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1519b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1520b7e05686SMatthew G. Knepley 
1521b7e05686SMatthew G. Knepley + dim - the spatial dimension
1522b7e05686SMatthew G. Knepley . Nf - the number of fields
1523b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1524b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1525b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1526b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1527b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1528b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1529b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1530b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1531b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1532b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1533b7e05686SMatthew G. Knepley . t - current time
1534b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1535b7e05686SMatthew G. Knepley . x - coordinates of the current point
153697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
153797b6e6e8SMatthew G. Knepley . constants - constant parameters
1538b7e05686SMatthew G. Knepley - g0 - output values at the current point
1539b7e05686SMatthew G. Knepley 
1540b7e05686SMatthew G. Knepley   Level: intermediate
1541b7e05686SMatthew G. Knepley 
1542b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1543b7e05686SMatthew G. Knepley @*/
1544b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1545b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1546b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1547b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154897b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1549b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1550b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1551b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
155297b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1553b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1554b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1555b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
155697b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1557b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1558b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1559b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
156097b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1561b7e05686SMatthew G. Knepley {
1562b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1563b7e05686SMatthew G. Knepley 
1564b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1565b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1566b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1567b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1568b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1569b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1570b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1571b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1572b7e05686SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1573b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+0] = g0;
1574b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+1] = g1;
1575b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+2] = g2;
1576b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+3] = g3;
1577b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1578b7e05686SMatthew G. Knepley }
1579b7e05686SMatthew G. Knepley 
15800c2f2876SMatthew G. Knepley /*@C
15810c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
15820c2f2876SMatthew G. Knepley 
15830c2f2876SMatthew G. Knepley   Not collective
15840c2f2876SMatthew G. Knepley 
15850c2f2876SMatthew G. Knepley   Input Arguments:
15860c2f2876SMatthew G. Knepley + prob - The PetscDS object
15870c2f2876SMatthew G. Knepley - f    - The field number
15880c2f2876SMatthew G. Knepley 
15890c2f2876SMatthew G. Knepley   Output Argument:
15900c2f2876SMatthew G. Knepley . r    - Riemann solver
15910c2f2876SMatthew G. Knepley 
15920c2f2876SMatthew G. Knepley   Calling sequence for r:
15930c2f2876SMatthew G. Knepley 
15945db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
15950c2f2876SMatthew G. Knepley 
15965db36cf9SMatthew G. Knepley + dim  - The spatial dimension
15975db36cf9SMatthew G. Knepley . Nf   - The number of fields
15985db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
15990c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
16000c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
16010c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
16020c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
160397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
160497b6e6e8SMatthew G. Knepley . constants - constant parameters
16050c2f2876SMatthew G. Knepley - ctx  - optional user context
16060c2f2876SMatthew G. Knepley 
16070c2f2876SMatthew G. Knepley   Level: intermediate
16080c2f2876SMatthew G. Knepley 
16090c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
16100c2f2876SMatthew G. Knepley @*/
16110c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f,
161297b6e6e8SMatthew G. Knepley                                        void (**r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscInt numConstants, const PetscScalar constants[], PetscScalar flux[], void *ctx))
16130c2f2876SMatthew G. Knepley {
16140c2f2876SMatthew G. Knepley   PetscFunctionBegin;
16150c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
16160c2f2876SMatthew 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);
16170c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
16180c2f2876SMatthew G. Knepley   *r = prob->r[f];
16190c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
16200c2f2876SMatthew G. Knepley }
16210c2f2876SMatthew G. Knepley 
16220c2f2876SMatthew G. Knepley /*@C
16230c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
16240c2f2876SMatthew G. Knepley 
16250c2f2876SMatthew G. Knepley   Not collective
16260c2f2876SMatthew G. Knepley 
16270c2f2876SMatthew G. Knepley   Input Arguments:
16280c2f2876SMatthew G. Knepley + prob - The PetscDS object
16290c2f2876SMatthew G. Knepley . f    - The field number
16300c2f2876SMatthew G. Knepley - r    - Riemann solver
16310c2f2876SMatthew G. Knepley 
16320c2f2876SMatthew G. Knepley   Calling sequence for r:
16330c2f2876SMatthew G. Knepley 
16345db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
16350c2f2876SMatthew G. Knepley 
16365db36cf9SMatthew G. Knepley + dim  - The spatial dimension
16375db36cf9SMatthew G. Knepley . Nf   - The number of fields
16385db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
16390c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
16400c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
16410c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
16420c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
164397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
164497b6e6e8SMatthew G. Knepley . constants - constant parameters
16450c2f2876SMatthew G. Knepley - ctx  - optional user context
16460c2f2876SMatthew G. Knepley 
16470c2f2876SMatthew G. Knepley   Level: intermediate
16480c2f2876SMatthew G. Knepley 
16490c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
16500c2f2876SMatthew G. Knepley @*/
16510c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f,
165297b6e6e8SMatthew G. Knepley                                        void (*r)(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscInt numConstants, const PetscScalar constants[], PetscScalar flux[], void *ctx))
16530c2f2876SMatthew G. Knepley {
16540c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
16550c2f2876SMatthew G. Knepley 
16560c2f2876SMatthew G. Knepley   PetscFunctionBegin;
16570c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1658de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
16590c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
16600c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
16610c2f2876SMatthew G. Knepley   prob->r[f] = r;
16620c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
16630c2f2876SMatthew G. Knepley }
16640c2f2876SMatthew G. Knepley 
166532d2bbc9SMatthew G. Knepley /*@C
166632d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
166732d2bbc9SMatthew G. Knepley 
166832d2bbc9SMatthew G. Knepley   Not collective
166932d2bbc9SMatthew G. Knepley 
167032d2bbc9SMatthew G. Knepley   Input Parameters:
167132d2bbc9SMatthew G. Knepley + prob - The PetscDS
167232d2bbc9SMatthew G. Knepley - f    - The field number
167332d2bbc9SMatthew G. Knepley 
167432d2bbc9SMatthew G. Knepley   Output Parameters:
167532d2bbc9SMatthew G. Knepley + update - update function
167632d2bbc9SMatthew G. Knepley 
167732d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
167832d2bbc9SMatthew G. Knepley 
167932d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
168032d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
168132d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
168232d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
168332d2bbc9SMatthew G. Knepley 
168432d2bbc9SMatthew G. Knepley + dim - the spatial dimension
168532d2bbc9SMatthew G. Knepley . Nf - the number of fields
168632d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
168732d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
168832d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
168932d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
169032d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
169132d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
169232d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
169332d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
169432d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
169532d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
169632d2bbc9SMatthew G. Knepley . t - current time
169732d2bbc9SMatthew G. Knepley . x - coordinates of the current point
169832d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
169932d2bbc9SMatthew G. Knepley 
170032d2bbc9SMatthew G. Knepley   Level: intermediate
170132d2bbc9SMatthew G. Knepley 
170232d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
170332d2bbc9SMatthew G. Knepley @*/
170432d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f,
170532d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
170632d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
170732d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
17083fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
170932d2bbc9SMatthew G. Knepley {
171032d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
171132d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
171232d2bbc9SMatthew 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);
171332d2bbc9SMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = prob->update[f];}
171432d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
171532d2bbc9SMatthew G. Knepley }
171632d2bbc9SMatthew G. Knepley 
171732d2bbc9SMatthew G. Knepley /*@C
17183fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
171932d2bbc9SMatthew G. Knepley 
172032d2bbc9SMatthew G. Knepley   Not collective
172132d2bbc9SMatthew G. Knepley 
172232d2bbc9SMatthew G. Knepley   Input Parameters:
172332d2bbc9SMatthew G. Knepley + prob   - The PetscDS
172432d2bbc9SMatthew G. Knepley . f      - The field number
172532d2bbc9SMatthew G. Knepley - update - update function
172632d2bbc9SMatthew G. Knepley 
172732d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
172832d2bbc9SMatthew G. Knepley 
172932d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
173032d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
173132d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
173232d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
173332d2bbc9SMatthew G. Knepley 
173432d2bbc9SMatthew G. Knepley + dim - the spatial dimension
173532d2bbc9SMatthew G. Knepley . Nf - the number of fields
173632d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
173732d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
173832d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
173932d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
174032d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
174132d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
174232d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
174332d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
174432d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
174532d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
174632d2bbc9SMatthew G. Knepley . t - current time
174732d2bbc9SMatthew G. Knepley . x - coordinates of the current point
174832d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
174932d2bbc9SMatthew G. Knepley 
175032d2bbc9SMatthew G. Knepley   Level: intermediate
175132d2bbc9SMatthew G. Knepley 
175232d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
175332d2bbc9SMatthew G. Knepley @*/
175432d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f,
175532d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
175632d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
175732d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
17583fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
175932d2bbc9SMatthew G. Knepley {
176032d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
176132d2bbc9SMatthew G. Knepley 
176232d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
176332d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
176432d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
176532d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
176632d2bbc9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
176732d2bbc9SMatthew G. Knepley   prob->update[f] = update;
176832d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
176932d2bbc9SMatthew G. Knepley }
177032d2bbc9SMatthew G. Knepley 
17710c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx)
17720c2f2876SMatthew G. Knepley {
17730c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17740c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
17750c2f2876SMatthew 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);
17760c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
17770c2f2876SMatthew G. Knepley   *ctx = prob->ctx[f];
17780c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17790c2f2876SMatthew G. Knepley }
17800c2f2876SMatthew G. Knepley 
17810c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx)
17820c2f2876SMatthew G. Knepley {
17830c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
17840c2f2876SMatthew G. Knepley 
17850c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17860c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
17870c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
17880c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
17890c2f2876SMatthew G. Knepley   prob->ctx[f] = ctx;
17900c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17910c2f2876SMatthew G. Knepley }
17920c2f2876SMatthew G. Knepley 
1793194d53e6SMatthew G. Knepley /*@C
1794194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
1795194d53e6SMatthew G. Knepley 
1796194d53e6SMatthew G. Knepley   Not collective
1797194d53e6SMatthew G. Knepley 
1798194d53e6SMatthew G. Knepley   Input Parameters:
1799194d53e6SMatthew G. Knepley + prob - The PetscDS
1800194d53e6SMatthew G. Knepley - f    - The test field number
1801194d53e6SMatthew G. Knepley 
1802194d53e6SMatthew G. Knepley   Output Parameters:
1803194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
1804194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1805194d53e6SMatthew G. Knepley 
1806194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1807194d53e6SMatthew G. Knepley 
1808194d53e6SMatthew 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
1809194d53e6SMatthew G. Knepley 
1810194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1811194d53e6SMatthew G. Knepley 
181230b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1813194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1814194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
181530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1816194d53e6SMatthew G. Knepley 
1817194d53e6SMatthew G. Knepley + dim - the spatial dimension
1818194d53e6SMatthew G. Knepley . Nf - the number of fields
1819194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1820194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1821194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1822194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1823194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1824194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1825194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1826194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1827194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1828194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1829194d53e6SMatthew G. Knepley . t - current time
1830194d53e6SMatthew G. Knepley . x - coordinates of the current point
1831194d53e6SMatthew G. Knepley . n - unit normal at the current point
183297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
183397b6e6e8SMatthew G. Knepley . constants - constant parameters
1834194d53e6SMatthew G. Knepley - f0 - output values at the current point
1835194d53e6SMatthew G. Knepley 
1836194d53e6SMatthew G. Knepley   Level: intermediate
1837194d53e6SMatthew G. Knepley 
1838194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
1839194d53e6SMatthew G. Knepley @*/
18402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f,
184130b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1842194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1843194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
184497b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
184530b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1846194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1847194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
184897b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
18492764a2aaSMatthew G. Knepley {
18502764a2aaSMatthew G. Knepley   PetscFunctionBegin;
18512764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18522764a2aaSMatthew 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);
18532764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];}
18542764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];}
18552764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
18562764a2aaSMatthew G. Knepley }
18572764a2aaSMatthew G. Knepley 
1858194d53e6SMatthew G. Knepley /*@C
1859194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
1860194d53e6SMatthew G. Knepley 
1861194d53e6SMatthew G. Knepley   Not collective
1862194d53e6SMatthew G. Knepley 
1863194d53e6SMatthew G. Knepley   Input Parameters:
1864194d53e6SMatthew G. Knepley + prob - The PetscDS
1865194d53e6SMatthew G. Knepley . f    - The test field number
1866194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
1867194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1868194d53e6SMatthew G. Knepley 
1869194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1870194d53e6SMatthew G. Knepley 
1871194d53e6SMatthew 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
1872194d53e6SMatthew G. Knepley 
1873194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1874194d53e6SMatthew G. Knepley 
187530b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1876194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1877194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
187830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1879194d53e6SMatthew G. Knepley 
1880194d53e6SMatthew G. Knepley + dim - the spatial dimension
1881194d53e6SMatthew G. Knepley . Nf - the number of fields
1882194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1883194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1884194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1885194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1886194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1887194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1888194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1889194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1890194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1891194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1892194d53e6SMatthew G. Knepley . t - current time
1893194d53e6SMatthew G. Knepley . x - coordinates of the current point
1894194d53e6SMatthew G. Knepley . n - unit normal at the current point
189597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
189697b6e6e8SMatthew G. Knepley . constants - constant parameters
1897194d53e6SMatthew G. Knepley - f0 - output values at the current point
1898194d53e6SMatthew G. Knepley 
1899194d53e6SMatthew G. Knepley   Level: intermediate
1900194d53e6SMatthew G. Knepley 
1901194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
1902194d53e6SMatthew G. Knepley @*/
19032764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f,
190430b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1905194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1906194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
190797b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
190830b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1909194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1910194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
191197b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
19122764a2aaSMatthew G. Knepley {
19132764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
19142764a2aaSMatthew G. Knepley 
19152764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19162764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19172764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19182764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
19192764a2aaSMatthew G. Knepley   if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;}
19202764a2aaSMatthew G. Knepley   if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;}
19212764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
19222764a2aaSMatthew G. Knepley }
19232764a2aaSMatthew G. Knepley 
1924194d53e6SMatthew G. Knepley /*@C
1925194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
1926194d53e6SMatthew G. Knepley 
1927194d53e6SMatthew G. Knepley   Not collective
1928194d53e6SMatthew G. Knepley 
1929194d53e6SMatthew G. Knepley   Input Parameters:
1930194d53e6SMatthew G. Knepley + prob - The PetscDS
1931194d53e6SMatthew G. Knepley . f    - The test field number
1932194d53e6SMatthew G. Knepley - g    - The field number
1933194d53e6SMatthew G. Knepley 
1934194d53e6SMatthew G. Knepley   Output Parameters:
1935194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1936194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1937194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1938194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1939194d53e6SMatthew G. Knepley 
1940194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1941194d53e6SMatthew G. Knepley 
1942194d53e6SMatthew 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
1943194d53e6SMatthew G. Knepley 
1944194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1945194d53e6SMatthew G. Knepley 
194630b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1947194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1948194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
1950194d53e6SMatthew G. Knepley 
1951194d53e6SMatthew G. Knepley + dim - the spatial dimension
1952194d53e6SMatthew G. Knepley . Nf - the number of fields
1953194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1954194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1955194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1956194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1957194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1958194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1959194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1960194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1961194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1962194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1963194d53e6SMatthew G. Knepley . t - current time
19642aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1965194d53e6SMatthew G. Knepley . x - coordinates of the current point
1966194d53e6SMatthew G. Knepley . n - normal at the current point
196797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
196897b6e6e8SMatthew G. Knepley . constants - constant parameters
1969194d53e6SMatthew G. Knepley - g0 - output values at the current point
1970194d53e6SMatthew G. Knepley 
1971194d53e6SMatthew G. Knepley   Level: intermediate
1972194d53e6SMatthew G. Knepley 
1973194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
1974194d53e6SMatthew G. Knepley @*/
19752764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
197630b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1977194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1978194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
197997b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
198030b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1981194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1982194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
198397b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
198430b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1985194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1986194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
198797b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
198830b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1989194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1990194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
199197b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
19922764a2aaSMatthew G. Knepley {
19932764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19942764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19952764a2aaSMatthew 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);
19962764a2aaSMatthew 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);
19972764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];}
19982764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];}
19992764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];}
20002764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];}
20012764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20022764a2aaSMatthew G. Knepley }
20032764a2aaSMatthew G. Knepley 
2004194d53e6SMatthew G. Knepley /*@C
2005194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2006194d53e6SMatthew G. Knepley 
2007194d53e6SMatthew G. Knepley   Not collective
2008194d53e6SMatthew G. Knepley 
2009194d53e6SMatthew G. Knepley   Input Parameters:
2010194d53e6SMatthew G. Knepley + prob - The PetscDS
2011194d53e6SMatthew G. Knepley . f    - The test field number
2012194d53e6SMatthew G. Knepley . g    - The field number
2013194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2014194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2015194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2016194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2017194d53e6SMatthew G. Knepley 
2018194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2019194d53e6SMatthew G. Knepley 
2020194d53e6SMatthew 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
2021194d53e6SMatthew G. Knepley 
2022194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2023194d53e6SMatthew G. Knepley 
202430b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2025194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2026194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
202730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2028194d53e6SMatthew G. Knepley 
2029194d53e6SMatthew G. Knepley + dim - the spatial dimension
2030194d53e6SMatthew G. Knepley . Nf - the number of fields
2031194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2032194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2033194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2034194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2035194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2036194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2037194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2038194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2039194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2040194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2041194d53e6SMatthew G. Knepley . t - current time
20422aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2043194d53e6SMatthew G. Knepley . x - coordinates of the current point
2044194d53e6SMatthew G. Knepley . n - normal at the current point
204597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
204697b6e6e8SMatthew G. Knepley . constants - constant parameters
2047194d53e6SMatthew G. Knepley - g0 - output values at the current point
2048194d53e6SMatthew G. Knepley 
2049194d53e6SMatthew G. Knepley   Level: intermediate
2050194d53e6SMatthew G. Knepley 
2051194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2052194d53e6SMatthew G. Knepley @*/
20532764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
205430b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2055194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2056194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
205797b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
205830b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2059194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2060194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
206197b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
206230b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2063194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2064194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
206597b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
206630b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2067194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2068194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
206997b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
20702764a2aaSMatthew G. Knepley {
20712764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
20722764a2aaSMatthew G. Knepley 
20732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20742764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20752764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
20762764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
20772764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
20782764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
20792764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
20802764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
20812764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
20822764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+0] = g0;
20832764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+1] = g1;
20842764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+2] = g2;
20852764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+3] = g3;
20862764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20872764a2aaSMatthew G. Knepley }
20882764a2aaSMatthew G. Knepley 
20890d3e9b51SMatthew G. Knepley /*@C
2090c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2091c371a6d1SMatthew G. Knepley 
2092c371a6d1SMatthew G. Knepley   Not collective
2093c371a6d1SMatthew G. Knepley 
2094c371a6d1SMatthew G. Knepley   Input Parameters:
2095c371a6d1SMatthew G. Knepley + prob - The PetscDS
2096c371a6d1SMatthew G. Knepley - f    - The test field number
2097c371a6d1SMatthew G. Knepley 
2098c371a6d1SMatthew G. Knepley   Output Parameter:
2099c371a6d1SMatthew G. Knepley . exactSol - exact solution for the test field
2100c371a6d1SMatthew G. Knepley 
2101c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2102c371a6d1SMatthew G. Knepley 
2103c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2104c371a6d1SMatthew G. Knepley 
2105c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2106c371a6d1SMatthew G. Knepley . t - current time
2107c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2108c371a6d1SMatthew G. Knepley . Nc - the number of field components
2109c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2110c371a6d1SMatthew G. Knepley - ctx - a user context
2111c371a6d1SMatthew G. Knepley 
2112c371a6d1SMatthew G. Knepley   Level: intermediate
2113c371a6d1SMatthew G. Knepley 
2114c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution()
2115c371a6d1SMatthew G. Knepley @*/
2116c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2117c371a6d1SMatthew G. Knepley {
2118c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2119c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2120c371a6d1SMatthew 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);
2121c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
2122c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2123c371a6d1SMatthew G. Knepley }
2124c371a6d1SMatthew G. Knepley 
2125c371a6d1SMatthew G. Knepley /*@C
2126c371a6d1SMatthew G. Knepley   PetscDSSetExactSolution - Get the pointwise exact solution function for a given test field
2127c371a6d1SMatthew G. Knepley 
2128c371a6d1SMatthew G. Knepley   Not collective
2129c371a6d1SMatthew G. Knepley 
2130c371a6d1SMatthew G. Knepley   Input Parameters:
2131c371a6d1SMatthew G. Knepley + prob - The PetscDS
2132c371a6d1SMatthew G. Knepley . f    - The test field number
2133c371a6d1SMatthew G. Knepley - sol  - solution function for the test fields
2134c371a6d1SMatthew G. Knepley 
2135c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2136c371a6d1SMatthew G. Knepley 
2137c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2138c371a6d1SMatthew G. Knepley 
2139c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2140c371a6d1SMatthew G. Knepley . t - current time
2141c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2142c371a6d1SMatthew G. Knepley . Nc - the number of field components
2143c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2144c371a6d1SMatthew G. Knepley - ctx - a user context
2145c371a6d1SMatthew G. Knepley 
2146c371a6d1SMatthew G. Knepley   Level: intermediate
2147c371a6d1SMatthew G. Knepley 
2148c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2149c371a6d1SMatthew G. Knepley @*/
2150c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2151c371a6d1SMatthew G. Knepley {
2152c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2153c371a6d1SMatthew G. Knepley 
2154c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2155c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2156c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2157c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2158c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
2159c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2160c371a6d1SMatthew G. Knepley }
2161c371a6d1SMatthew G. Knepley 
21625638fd0eSMatthew G. Knepley /*@C
216397b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
216497b6e6e8SMatthew G. Knepley 
216597b6e6e8SMatthew G. Knepley   Not collective
216697b6e6e8SMatthew G. Knepley 
216797b6e6e8SMatthew G. Knepley   Input Parameter:
216897b6e6e8SMatthew G. Knepley . prob - The PetscDS object
216997b6e6e8SMatthew G. Knepley 
217097b6e6e8SMatthew G. Knepley   Output Parameters:
217197b6e6e8SMatthew G. Knepley + numConstants - The number of constants
217297b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
217397b6e6e8SMatthew G. Knepley 
217497b6e6e8SMatthew G. Knepley   Level: intermediate
217597b6e6e8SMatthew G. Knepley 
217697b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
217797b6e6e8SMatthew G. Knepley @*/
217897b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
217997b6e6e8SMatthew G. Knepley {
218097b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
218197b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
218297b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
218397b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
218497b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
218597b6e6e8SMatthew G. Knepley }
218697b6e6e8SMatthew G. Knepley 
21870d3e9b51SMatthew G. Knepley /*@C
218897b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
218997b6e6e8SMatthew G. Knepley 
219097b6e6e8SMatthew G. Knepley   Not collective
219197b6e6e8SMatthew G. Knepley 
219297b6e6e8SMatthew G. Knepley   Input Parameters:
219397b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
219497b6e6e8SMatthew G. Knepley . numConstants - The number of constants
219597b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
219697b6e6e8SMatthew G. Knepley 
219797b6e6e8SMatthew G. Knepley   Level: intermediate
219897b6e6e8SMatthew G. Knepley 
219997b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
220097b6e6e8SMatthew G. Knepley @*/
220197b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
220297b6e6e8SMatthew G. Knepley {
220397b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
220497b6e6e8SMatthew G. Knepley 
220597b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
220697b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
220797b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
220897b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
220997b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
221097b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
221197b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
221220be0f5bSMatthew G. Knepley     } else {
221320be0f5bSMatthew G. Knepley       prob->constants = NULL;
221420be0f5bSMatthew G. Knepley     }
221520be0f5bSMatthew G. Knepley   }
221620be0f5bSMatthew G. Knepley   if (prob->numConstants) {
221720be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
221897b6e6e8SMatthew G. Knepley     ierr = PetscMemcpy(prob->constants, constants, prob->numConstants * sizeof(PetscScalar));CHKERRQ(ierr);
221997b6e6e8SMatthew G. Knepley   }
222097b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
222197b6e6e8SMatthew G. Knepley }
222297b6e6e8SMatthew G. Knepley 
22234cd1e086SMatthew G. Knepley /*@
22244cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
22254cd1e086SMatthew G. Knepley 
22264cd1e086SMatthew G. Knepley   Not collective
22274cd1e086SMatthew G. Knepley 
22284cd1e086SMatthew G. Knepley   Input Parameters:
22294cd1e086SMatthew G. Knepley + prob - The PetscDS object
22304cd1e086SMatthew G. Knepley - disc - The discretization object
22314cd1e086SMatthew G. Knepley 
22324cd1e086SMatthew G. Knepley   Output Parameter:
22334cd1e086SMatthew G. Knepley . f - The field number
22344cd1e086SMatthew G. Knepley 
22354cd1e086SMatthew G. Knepley   Level: beginner
22364cd1e086SMatthew G. Knepley 
2237f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
22384cd1e086SMatthew G. Knepley @*/
22394cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
22404cd1e086SMatthew G. Knepley {
22414cd1e086SMatthew G. Knepley   PetscInt g;
22424cd1e086SMatthew G. Knepley 
22434cd1e086SMatthew G. Knepley   PetscFunctionBegin;
22444cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22454cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
22464cd1e086SMatthew G. Knepley   *f = -1;
22474cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
22484cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
22494cd1e086SMatthew G. Knepley   *f = g;
22504cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
22514cd1e086SMatthew G. Knepley }
22524cd1e086SMatthew G. Knepley 
22534cd1e086SMatthew G. Knepley /*@
22544cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
22554cd1e086SMatthew G. Knepley 
22564cd1e086SMatthew G. Knepley   Not collective
22574cd1e086SMatthew G. Knepley 
22584cd1e086SMatthew G. Knepley   Input Parameters:
22594cd1e086SMatthew G. Knepley + prob - The PetscDS object
22604cd1e086SMatthew G. Knepley - f - The field number
22614cd1e086SMatthew G. Knepley 
22624cd1e086SMatthew G. Knepley   Output Parameter:
22634cd1e086SMatthew G. Knepley . size - The size
22644cd1e086SMatthew G. Knepley 
22654cd1e086SMatthew G. Knepley   Level: beginner
22664cd1e086SMatthew G. Knepley 
2267f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
22684cd1e086SMatthew G. Knepley @*/
22694cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
22704cd1e086SMatthew G. Knepley {
22712166fd64SMatthew G. Knepley   PetscErrorCode ierr;
22722166fd64SMatthew G. Knepley 
22734cd1e086SMatthew G. Knepley   PetscFunctionBegin;
22744cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22754cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
22764cd1e086SMatthew 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);
22772166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2278d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
22794cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
22804cd1e086SMatthew G. Knepley }
22814cd1e086SMatthew G. Knepley 
2282bc4ae4beSMatthew G. Knepley /*@
2283bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2284bc4ae4beSMatthew G. Knepley 
2285bc4ae4beSMatthew G. Knepley   Not collective
2286bc4ae4beSMatthew G. Knepley 
2287bc4ae4beSMatthew G. Knepley   Input Parameters:
2288bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2289bc4ae4beSMatthew G. Knepley - f - The field number
2290bc4ae4beSMatthew G. Knepley 
2291bc4ae4beSMatthew G. Knepley   Output Parameter:
2292bc4ae4beSMatthew G. Knepley . off - The offset
2293bc4ae4beSMatthew G. Knepley 
2294bc4ae4beSMatthew G. Knepley   Level: beginner
2295bc4ae4beSMatthew G. Knepley 
2296f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2297bc4ae4beSMatthew G. Knepley @*/
22982764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
22992764a2aaSMatthew G. Knepley {
23004cd1e086SMatthew G. Knepley   PetscInt       size, g;
23012764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23022764a2aaSMatthew G. Knepley 
23032764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23042764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23052764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
23062764a2aaSMatthew 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);
23072764a2aaSMatthew G. Knepley   *off = 0;
23082764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
23094cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
23104cd1e086SMatthew G. Knepley     *off += size;
23112764a2aaSMatthew G. Knepley   }
23122764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23132764a2aaSMatthew G. Knepley }
23142764a2aaSMatthew G. Knepley 
2315bc4ae4beSMatthew G. Knepley /*@
231647e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2317bc4ae4beSMatthew G. Knepley 
2318bc4ae4beSMatthew G. Knepley   Not collective
2319bc4ae4beSMatthew G. Knepley 
232047e57110SSander Arens   Input Parameter:
232147e57110SSander Arens . prob - The PetscDS object
2322bc4ae4beSMatthew G. Knepley 
2323bc4ae4beSMatthew G. Knepley   Output Parameter:
232447e57110SSander Arens . dimensions - The number of dimensions
2325bc4ae4beSMatthew G. Knepley 
2326bc4ae4beSMatthew G. Knepley   Level: beginner
2327bc4ae4beSMatthew G. Knepley 
232847e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2329bc4ae4beSMatthew G. Knepley @*/
233047e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
23312764a2aaSMatthew G. Knepley {
23322764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23332764a2aaSMatthew G. Knepley 
23342764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23352764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
233647e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
233747e57110SSander Arens   PetscValidPointer(dimensions, 2);
233847e57110SSander Arens   *dimensions = prob->Nb;
233947e57110SSander Arens   PetscFunctionReturn(0);
23406ce16762SMatthew G. Knepley }
234147e57110SSander Arens 
234247e57110SSander Arens /*@
234347e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
234447e57110SSander Arens 
234547e57110SSander Arens   Not collective
234647e57110SSander Arens 
234747e57110SSander Arens   Input Parameter:
234847e57110SSander Arens . prob - The PetscDS object
234947e57110SSander Arens 
235047e57110SSander Arens   Output Parameter:
235147e57110SSander Arens . components - The number of components
235247e57110SSander Arens 
235347e57110SSander Arens   Level: beginner
235447e57110SSander Arens 
235547e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
235647e57110SSander Arens @*/
235747e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
235847e57110SSander Arens {
235947e57110SSander Arens   PetscErrorCode ierr;
236047e57110SSander Arens 
236147e57110SSander Arens   PetscFunctionBegin;
236247e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
236347e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
236447e57110SSander Arens   PetscValidPointer(components, 2);
236547e57110SSander Arens   *components = prob->Nc;
23666ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
23676ce16762SMatthew G. Knepley }
23686ce16762SMatthew G. Knepley 
23696ce16762SMatthew G. Knepley /*@
23706ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
23716ce16762SMatthew G. Knepley 
23726ce16762SMatthew G. Knepley   Not collective
23736ce16762SMatthew G. Knepley 
23746ce16762SMatthew G. Knepley   Input Parameters:
23756ce16762SMatthew G. Knepley + prob - The PetscDS object
23766ce16762SMatthew G. Knepley - f - The field number
23776ce16762SMatthew G. Knepley 
23786ce16762SMatthew G. Knepley   Output Parameter:
23796ce16762SMatthew G. Knepley . off - The offset
23806ce16762SMatthew G. Knepley 
23816ce16762SMatthew G. Knepley   Level: beginner
23826ce16762SMatthew G. Knepley 
2383f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
23846ce16762SMatthew G. Knepley @*/
23856ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
23866ce16762SMatthew G. Knepley {
23876ce16762SMatthew G. Knepley   PetscFunctionBegin;
23886ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23896ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
23906ce16762SMatthew 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);
239147e57110SSander Arens   *off = prob->off[f];
23922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23932764a2aaSMatthew G. Knepley }
23942764a2aaSMatthew G. Knepley 
2395194d53e6SMatthew G. Knepley /*@
2396194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2397194d53e6SMatthew G. Knepley 
2398194d53e6SMatthew G. Knepley   Not collective
2399194d53e6SMatthew G. Knepley 
2400194d53e6SMatthew G. Knepley   Input Parameter:
2401194d53e6SMatthew G. Knepley . prob - The PetscDS object
2402194d53e6SMatthew G. Knepley 
2403194d53e6SMatthew G. Knepley   Output Parameter:
2404194d53e6SMatthew G. Knepley . offsets - The offsets
2405194d53e6SMatthew G. Knepley 
2406194d53e6SMatthew G. Knepley   Level: beginner
2407194d53e6SMatthew G. Knepley 
2408f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2409194d53e6SMatthew G. Knepley @*/
2410194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2411194d53e6SMatthew G. Knepley {
2412194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2413194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2414194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2415194d53e6SMatthew G. Knepley   *offsets = prob->off;
2416194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2417194d53e6SMatthew G. Knepley }
2418194d53e6SMatthew G. Knepley 
2419194d53e6SMatthew G. Knepley /*@
2420194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2421194d53e6SMatthew G. Knepley 
2422194d53e6SMatthew G. Knepley   Not collective
2423194d53e6SMatthew G. Knepley 
2424194d53e6SMatthew G. Knepley   Input Parameter:
2425194d53e6SMatthew G. Knepley . prob - The PetscDS object
2426194d53e6SMatthew G. Knepley 
2427194d53e6SMatthew G. Knepley   Output Parameter:
2428194d53e6SMatthew G. Knepley . offsets - The offsets
2429194d53e6SMatthew G. Knepley 
2430194d53e6SMatthew G. Knepley   Level: beginner
2431194d53e6SMatthew G. Knepley 
2432f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2433194d53e6SMatthew G. Knepley @*/
2434194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2435194d53e6SMatthew G. Knepley {
2436194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2437194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2438194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2439194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
2440194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2441194d53e6SMatthew G. Knepley }
2442194d53e6SMatthew G. Knepley 
244368c9edb9SMatthew G. Knepley /*@C
244468c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
244568c9edb9SMatthew G. Knepley 
244668c9edb9SMatthew G. Knepley   Not collective
244768c9edb9SMatthew G. Knepley 
244868c9edb9SMatthew G. Knepley   Input Parameter:
244968c9edb9SMatthew G. Knepley . prob - The PetscDS object
245068c9edb9SMatthew G. Knepley 
245168c9edb9SMatthew G. Knepley   Output Parameters:
245268c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
245368c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
245468c9edb9SMatthew G. Knepley 
245568c9edb9SMatthew G. Knepley   Level: intermediate
245668c9edb9SMatthew G. Knepley 
2457f744cafaSSander Arens .seealso: PetscDSCreate()
245868c9edb9SMatthew G. Knepley @*/
24592764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
24602764a2aaSMatthew G. Knepley {
24612764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24622764a2aaSMatthew G. Knepley 
24632764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24642764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24652764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
24662764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basis;}
24672764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;}
24682764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
24692764a2aaSMatthew G. Knepley }
24702764a2aaSMatthew G. Knepley 
247168c9edb9SMatthew G. Knepley /*@C
24724d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
247368c9edb9SMatthew G. Knepley 
247468c9edb9SMatthew G. Knepley   Not collective
247568c9edb9SMatthew G. Knepley 
247668c9edb9SMatthew G. Knepley   Input Parameter:
247768c9edb9SMatthew G. Knepley . prob - The PetscDS object
247868c9edb9SMatthew G. Knepley 
247968c9edb9SMatthew G. Knepley   Output Parameters:
24804d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points
24814d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points
248268c9edb9SMatthew G. Knepley 
248368c9edb9SMatthew G. Knepley   Level: intermediate
248468c9edb9SMatthew G. Knepley 
248568c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
248668c9edb9SMatthew G. Knepley @*/
24874d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
24882764a2aaSMatthew G. Knepley {
24892764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24902764a2aaSMatthew G. Knepley 
24912764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24922764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24932764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
24944d0b9603SSander Arens   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basisFace;}
24954d0b9603SSander Arens   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;}
24962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
24972764a2aaSMatthew G. Knepley }
24982764a2aaSMatthew G. Knepley 
24992764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
25002764a2aaSMatthew G. Knepley {
25012764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25022764a2aaSMatthew G. Knepley 
25032764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25042764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25052764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25062764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
25072764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
25082764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
25092764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25102764a2aaSMatthew G. Knepley }
25112764a2aaSMatthew G. Knepley 
25122764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
25132764a2aaSMatthew G. Knepley {
25142764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25152764a2aaSMatthew G. Knepley 
25162764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25172764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25182764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25192764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
25202764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
25212764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
25222764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
25232764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
25242764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
25252764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25262764a2aaSMatthew G. Knepley }
25272764a2aaSMatthew G. Knepley 
25282764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer)
25292764a2aaSMatthew G. Knepley {
25302764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25312764a2aaSMatthew G. Knepley 
25322764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25332764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25342764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25352764a2aaSMatthew G. Knepley   if (x)           {PetscValidPointer(x, 2);           *x           = prob->x;}
25362764a2aaSMatthew G. Knepley   if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;}
25372764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25382764a2aaSMatthew G. Knepley }
25392764a2aaSMatthew G. Knepley 
254058ebd649SToby Isaac /*@C
254158ebd649SToby Isaac   PetscDSAddBoundary - Add a boundary condition to the model
254258ebd649SToby Isaac 
254358ebd649SToby Isaac   Input Parameters:
254458ebd649SToby Isaac + ds          - The PetscDS object
25452d47a189SJulian Andrej . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
254658ebd649SToby Isaac . name        - The BC name
254758ebd649SToby Isaac . labelname   - The label defining constrained points
254858ebd649SToby Isaac . field       - The field to constrain
254958ebd649SToby Isaac . numcomps    - The number of constrained field components
255058ebd649SToby Isaac . comps       - An array of constrained component numbers
255158ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
255258ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
255358ebd649SToby Isaac . ids         - An array of ids for constrained points
255458ebd649SToby Isaac - ctx         - An optional user context for bcFunc
255558ebd649SToby Isaac 
255658ebd649SToby Isaac   Options Database Keys:
255758ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
255858ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
255958ebd649SToby Isaac 
256058ebd649SToby Isaac   Level: developer
256158ebd649SToby Isaac 
256258ebd649SToby Isaac .seealso: PetscDSGetBoundary()
256358ebd649SToby Isaac @*/
2564a30ec4eaSSatish Balay PetscErrorCode PetscDSAddBoundary(PetscDS ds, DMBoundaryConditionType type, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(void), PetscInt numids, const PetscInt *ids, void *ctx)
256558ebd649SToby Isaac {
256658ebd649SToby Isaac   DSBoundary     b;
256758ebd649SToby Isaac   PetscErrorCode ierr;
256858ebd649SToby Isaac 
256958ebd649SToby Isaac   PetscFunctionBegin;
257058ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
257158ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
257258ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
257358ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
257458ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
257558ebd649SToby Isaac   if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
257658ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
257758ebd649SToby Isaac   if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
2578f971fd6bSMatthew G. Knepley   b->type            = type;
257958ebd649SToby Isaac   b->field           = field;
258058ebd649SToby Isaac   b->numcomps        = numcomps;
258158ebd649SToby Isaac   b->func            = bcFunc;
258258ebd649SToby Isaac   b->numids          = numids;
258358ebd649SToby Isaac   b->ctx             = ctx;
258458ebd649SToby Isaac   b->next            = ds->boundary;
258558ebd649SToby Isaac   ds->boundary       = b;
258658ebd649SToby Isaac   PetscFunctionReturn(0);
258758ebd649SToby Isaac }
258858ebd649SToby Isaac 
258958ebd649SToby Isaac /*@
259058ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
259158ebd649SToby Isaac 
259258ebd649SToby Isaac   Input Parameters:
259358ebd649SToby Isaac . ds - The PetscDS object
259458ebd649SToby Isaac 
259558ebd649SToby Isaac   Output Parameters:
259658ebd649SToby Isaac . numBd - The number of BC
259758ebd649SToby Isaac 
259858ebd649SToby Isaac   Level: intermediate
259958ebd649SToby Isaac 
260058ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
260158ebd649SToby Isaac @*/
260258ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
260358ebd649SToby Isaac {
260458ebd649SToby Isaac   DSBoundary b = ds->boundary;
260558ebd649SToby Isaac 
260658ebd649SToby Isaac   PetscFunctionBegin;
260758ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
260858ebd649SToby Isaac   PetscValidPointer(numBd, 2);
260958ebd649SToby Isaac   *numBd = 0;
261058ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
261158ebd649SToby Isaac   PetscFunctionReturn(0);
261258ebd649SToby Isaac }
261358ebd649SToby Isaac 
261458ebd649SToby Isaac /*@C
261558ebd649SToby Isaac   PetscDSGetBoundary - Add a boundary condition to the model
261658ebd649SToby Isaac 
261758ebd649SToby Isaac   Input Parameters:
261858ebd649SToby Isaac + ds          - The PetscDS object
261958ebd649SToby Isaac - bd          - The BC number
262058ebd649SToby Isaac 
262158ebd649SToby Isaac   Output Parameters:
26222d47a189SJulian Andrej + type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
262358ebd649SToby Isaac . name        - The BC name
262458ebd649SToby Isaac . labelname   - The label defining constrained points
262558ebd649SToby Isaac . field       - The field to constrain
262658ebd649SToby Isaac . numcomps    - The number of constrained field components
262758ebd649SToby Isaac . comps       - An array of constrained component numbers
262858ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
262958ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
263058ebd649SToby Isaac . ids         - An array of ids for constrained points
263158ebd649SToby Isaac - ctx         - An optional user context for bcFunc
263258ebd649SToby Isaac 
263358ebd649SToby Isaac   Options Database Keys:
263458ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
263558ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
263658ebd649SToby Isaac 
263758ebd649SToby Isaac   Level: developer
263858ebd649SToby Isaac 
263958ebd649SToby Isaac .seealso: PetscDSAddBoundary()
264058ebd649SToby Isaac @*/
2641a30ec4eaSSatish Balay PetscErrorCode PetscDSGetBoundary(PetscDS ds, PetscInt bd, DMBoundaryConditionType *type, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(void), PetscInt *numids, const PetscInt **ids, void **ctx)
264258ebd649SToby Isaac {
264358ebd649SToby Isaac   DSBoundary b    = ds->boundary;
264458ebd649SToby Isaac   PetscInt   n    = 0;
264558ebd649SToby Isaac 
264658ebd649SToby Isaac   PetscFunctionBegin;
264758ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
264858ebd649SToby Isaac   while (b) {
264958ebd649SToby Isaac     if (n == bd) break;
265058ebd649SToby Isaac     b = b->next;
265158ebd649SToby Isaac     ++n;
265258ebd649SToby Isaac   }
265358ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
2654f971fd6bSMatthew G. Knepley   if (type) {
2655f971fd6bSMatthew G. Knepley     PetscValidPointer(type, 3);
2656f971fd6bSMatthew G. Knepley     *type = b->type;
265758ebd649SToby Isaac   }
265858ebd649SToby Isaac   if (name) {
265958ebd649SToby Isaac     PetscValidPointer(name, 4);
266058ebd649SToby Isaac     *name = b->name;
266158ebd649SToby Isaac   }
266258ebd649SToby Isaac   if (labelname) {
266358ebd649SToby Isaac     PetscValidPointer(labelname, 5);
266458ebd649SToby Isaac     *labelname = b->labelname;
266558ebd649SToby Isaac   }
266658ebd649SToby Isaac   if (field) {
266758ebd649SToby Isaac     PetscValidPointer(field, 6);
266858ebd649SToby Isaac     *field = b->field;
266958ebd649SToby Isaac   }
267058ebd649SToby Isaac   if (numcomps) {
267158ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
267258ebd649SToby Isaac     *numcomps = b->numcomps;
267358ebd649SToby Isaac   }
267458ebd649SToby Isaac   if (comps) {
267558ebd649SToby Isaac     PetscValidPointer(comps, 8);
267658ebd649SToby Isaac     *comps = b->comps;
267758ebd649SToby Isaac   }
267858ebd649SToby Isaac   if (func) {
267958ebd649SToby Isaac     PetscValidPointer(func, 9);
268058ebd649SToby Isaac     *func = b->func;
268158ebd649SToby Isaac   }
268258ebd649SToby Isaac   if (numids) {
268358ebd649SToby Isaac     PetscValidPointer(numids, 10);
268458ebd649SToby Isaac     *numids = b->numids;
268558ebd649SToby Isaac   }
268658ebd649SToby Isaac   if (ids) {
268758ebd649SToby Isaac     PetscValidPointer(ids, 11);
268858ebd649SToby Isaac     *ids = b->ids;
268958ebd649SToby Isaac   }
269058ebd649SToby Isaac   if (ctx) {
269158ebd649SToby Isaac     PetscValidPointer(ctx, 12);
269258ebd649SToby Isaac     *ctx = b->ctx;
269358ebd649SToby Isaac   }
269458ebd649SToby Isaac   PetscFunctionReturn(0);
269558ebd649SToby Isaac }
269658ebd649SToby Isaac 
2697dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB)
2698dff059c6SToby Isaac {
2699dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
2700dff059c6SToby Isaac   PetscErrorCode ierr;
2701dff059c6SToby Isaac 
2702dff059c6SToby Isaac   PetscFunctionBegin;
2703dff059c6SToby Isaac   PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1);
2704dff059c6SToby Isaac   PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2);
2705dff059c6SToby Isaac   if (probA == probB) PetscFunctionReturn(0);
2706dff059c6SToby Isaac   next = probB->boundary;
2707dff059c6SToby Isaac   while (next) {
2708dff059c6SToby Isaac     DSBoundary b = next;
2709dff059c6SToby Isaac 
2710dff059c6SToby Isaac     next = b->next;
2711dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2712dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2713dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
2714dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2715dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
2716dff059c6SToby Isaac   }
2717dff059c6SToby Isaac   lastnext = &(probB->boundary);
2718dff059c6SToby Isaac   for (b = probA->boundary; b; b = b->next) {
2719dff059c6SToby Isaac     DSBoundary bNew;
2720dff059c6SToby Isaac 
2721459726d8SSatish Balay     ierr = PetscNew(&bNew);CHKERRQ(ierr);
2722dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
2723dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
2724dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr);
2725dff059c6SToby Isaac     bNew->numids = b->numids;
2726dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
2727dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr);
2728dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
2729dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
2730dff059c6SToby Isaac     bNew->ctx   = b->ctx;
2731f971fd6bSMatthew G. Knepley     bNew->type  = b->type;
2732dff059c6SToby Isaac     bNew->field = b->field;
2733dff059c6SToby Isaac     bNew->func  = b->func;
2734dff059c6SToby Isaac 
2735dff059c6SToby Isaac     *lastnext = bNew;
2736dff059c6SToby Isaac     lastnext = &(bNew->next);
2737dff059c6SToby Isaac   }
2738dff059c6SToby Isaac   PetscFunctionReturn(0);
2739dff059c6SToby Isaac }
2740dff059c6SToby Isaac 
2741da51fcedSMatthew G. Knepley /*@
2742da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
2743da51fcedSMatthew G. Knepley 
2744da51fcedSMatthew G. Knepley   Not collective
2745da51fcedSMatthew G. Knepley 
2746da51fcedSMatthew G. Knepley   Input Parameter:
2747da51fcedSMatthew G. Knepley . prob - The PetscDS object
2748da51fcedSMatthew G. Knepley 
2749da51fcedSMatthew G. Knepley   Output Parameter:
2750da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
2751da51fcedSMatthew G. Knepley 
2752da51fcedSMatthew G. Knepley   Level: intermediate
2753da51fcedSMatthew G. Knepley 
2754da51fcedSMatthew G. Knepley .seealso: PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
2755da51fcedSMatthew G. Knepley @*/
2756da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
2757da51fcedSMatthew G. Knepley {
2758da51fcedSMatthew G. Knepley   PetscInt       Nf, Ng, f, g;
2759da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
2760da51fcedSMatthew G. Knepley 
2761da51fcedSMatthew G. Knepley   PetscFunctionBegin;
2762da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2763da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
2764da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
2765da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
276613903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
2767da51fcedSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
2768da51fcedSMatthew G. Knepley     PetscPointFunc   obj;
2769da51fcedSMatthew G. Knepley     PetscPointFunc   f0, f1;
2770da51fcedSMatthew G. Knepley     PetscPointJac    g0, g1, g2, g3;
2771da51fcedSMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
2772da51fcedSMatthew G. Knepley     PetscBdPointJac  g0Bd, g1Bd, g2Bd, g3Bd;
2773da51fcedSMatthew G. Knepley     PetscRiemannFunc r;
2774da51fcedSMatthew G. Knepley 
2775da51fcedSMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
2776da51fcedSMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
2777da51fcedSMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
2778da51fcedSMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
2779da51fcedSMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, f, obj);CHKERRQ(ierr);
2780da51fcedSMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, f, f0, f1);CHKERRQ(ierr);
2781da51fcedSMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, f, f0Bd, f1Bd);CHKERRQ(ierr);
2782da51fcedSMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, f, r);CHKERRQ(ierr);
2783da51fcedSMatthew G. Knepley     for (g = 0; g < Nf; ++g) {
2784da51fcedSMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
2785da51fcedSMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
2786da51fcedSMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, f, g, g0, g1, g2, g3);CHKERRQ(ierr);
2787da51fcedSMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, f, g, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
2788da51fcedSMatthew G. Knepley     }
2789da51fcedSMatthew G. Knepley   }
2790da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
2791da51fcedSMatthew G. Knepley }
2792da51fcedSMatthew G. Knepley 
2793bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob)
27942764a2aaSMatthew G. Knepley {
2795931fb3b8SToby Isaac   PetscErrorCode      ierr;
2796931fb3b8SToby Isaac 
27972764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2798931fb3b8SToby Isaac   ierr = PetscFree(prob->data);CHKERRQ(ierr);
27992764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28002764a2aaSMatthew G. Knepley }
28012764a2aaSMatthew G. Knepley 
2802bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob)
28032764a2aaSMatthew G. Knepley {
28042764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28052764a2aaSMatthew G. Knepley   prob->ops->setfromoptions = NULL;
28062764a2aaSMatthew G. Knepley   prob->ops->setup          = NULL;
28072764a2aaSMatthew G. Knepley   prob->ops->view           = NULL;
28082764a2aaSMatthew G. Knepley   prob->ops->destroy        = PetscDSDestroy_Basic;
28092764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28102764a2aaSMatthew G. Knepley }
28112764a2aaSMatthew G. Knepley 
28122764a2aaSMatthew G. Knepley /*MC
28132764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
28142764a2aaSMatthew G. Knepley 
28152764a2aaSMatthew G. Knepley   Level: intermediate
28162764a2aaSMatthew G. Knepley 
28172764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
28182764a2aaSMatthew G. Knepley M*/
28192764a2aaSMatthew G. Knepley 
28202764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob)
28212764a2aaSMatthew G. Knepley {
28222764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
28232764a2aaSMatthew G. Knepley   PetscErrorCode      ierr;
28242764a2aaSMatthew G. Knepley 
28252764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2826931fb3b8SToby Isaac   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28272764a2aaSMatthew G. Knepley   ierr       = PetscNewLog(prob, &b);CHKERRQ(ierr);
28282764a2aaSMatthew G. Knepley   prob->data = b;
28292764a2aaSMatthew G. Knepley 
28302764a2aaSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr);
28312764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28322764a2aaSMatthew G. Knepley }
2833