xref: /petsc/src/dm/dt/interface/dtds.c (revision df3a45bd6466958df0529804d9dd41fabb15c1f7)
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;
290d1506c7cSMatthew G. Knepley   PetscInt       dim, dimEmbed, 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);
298d1506c7cSMatthew G. Knepley   ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr);
299f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
30047e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
301f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
302f744cafaSSander Arens   ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisFace,Nf,&prob->basisDerFace);CHKERRQ(ierr);
3032764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3049de99aefSMatthew G. Knepley     PetscObject     obj;
3059de99aefSMatthew G. Knepley     PetscClassId    id;
3062764a2aaSMatthew G. Knepley     PetscQuadrature q;
3079de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
3082764a2aaSMatthew G. Knepley 
3099de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3109de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3119de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
3129de99aefSMatthew G. Knepley       PetscFE fe = (PetscFE) obj;
3139de99aefSMatthew G. Knepley 
3142764a2aaSMatthew G. Knepley       ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
3152764a2aaSMatthew G. Knepley       ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
3162764a2aaSMatthew G. Knepley       ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
3172764a2aaSMatthew G. Knepley       ierr = PetscFEGetDefaultTabulation(fe, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3184d0b9603SSander Arens       ierr = PetscFEGetFaceTabulation(fe, &prob->basisFace[f], &prob->basisDerFace[f], NULL);CHKERRQ(ierr);
3199de99aefSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
3209de99aefSMatthew G. Knepley       PetscFV fv = (PetscFV) obj;
3219de99aefSMatthew G. Knepley 
3229de99aefSMatthew G. Knepley       ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
3239de99aefSMatthew G. Knepley       ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
3249c3cf19fSMatthew G. Knepley       Nb   = Nc;
3256c1a3d01SMatthew G. Knepley       ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3264d0b9603SSander Arens       /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
327abac5ca0SMatthew G. Knepley     } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
32847e57110SSander Arens     prob->Nc[f]       = Nc;
32947e57110SSander Arens     prob->Nb[f]       = Nb;
330194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
331194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
332a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
3332764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
3342764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
3359c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
3362764a2aaSMatthew G. Knepley     prob->totComp += Nc;
3372764a2aaSMatthew G. Knepley   }
3382764a2aaSMatthew G. Knepley   work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim));
3392764a2aaSMatthew G. Knepley   /* Allocate works space */
340d1506c7cSMatthew G. Knepley   ierr = PetscMalloc5(prob->totComp,&prob->u,prob->totComp,&prob->u_t,prob->totComp*dim,&prob->u_x,dimEmbed,&prob->x,work,&prob->refSpaceDer);CHKERRQ(ierr);
3412764a2aaSMatthew 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);
3422764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
3432764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
3442764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3452764a2aaSMatthew G. Knepley }
3462764a2aaSMatthew G. Knepley 
3472764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
3482764a2aaSMatthew G. Knepley {
3492764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3502764a2aaSMatthew G. Knepley 
3512764a2aaSMatthew G. Knepley   PetscFunctionBegin;
35247e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
353f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
354f744cafaSSander Arens   ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisFace,prob->basisDerFace);CHKERRQ(ierr);
3552764a2aaSMatthew G. Knepley   ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr);
3562764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
3572764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3582764a2aaSMatthew G. Knepley }
3592764a2aaSMatthew G. Knepley 
3602764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
3612764a2aaSMatthew G. Knepley {
362f744cafaSSander Arens   PetscObject      *tmpd;
363a6cbbb48SMatthew G. Knepley   PetscBool        *tmpi, *tmpa;
36432d2bbc9SMatthew G. Knepley   PetscPointFunc   *tmpobj, *tmpf, *tmpup;
365b7e05686SMatthew G. Knepley   PetscPointJac    *tmpg, *tmpgp, *tmpgt;
3662aa1fc23SMatthew G. Knepley   PetscBdPointFunc *tmpfbd;
3672aa1fc23SMatthew G. Knepley   PetscBdPointJac  *tmpgbd;
368194d53e6SMatthew G. Knepley   PetscRiemannFunc *tmpr;
369c371a6d1SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol;
3700c2f2876SMatthew G. Knepley   void            **tmpctx;
371a6cbbb48SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f, i;
3722764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
3732764a2aaSMatthew G. Knepley 
3742764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3752764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
3762764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
3772764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
378f744cafaSSander Arens   ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr);
379f744cafaSSander 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];}
380f744cafaSSander 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;}
381f744cafaSSander Arens   ierr = PetscFree3(prob->disc, prob->implicit, prob->adjacency);CHKERRQ(ierr);
3822764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
3832764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
384249df284SMatthew G. Knepley   prob->implicit  = tmpi;
385a6cbbb48SMatthew G. Knepley   prob->adjacency = tmpa;
386b7e05686SMatthew 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);
38732d2bbc9SMatthew G. Knepley   ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr);
3882764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f];
3892764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f];
3902764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f];
391475e0ac9SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f];
3920c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f];
39332d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
3940c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
3952764a2aaSMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL;
3962764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL;
3972764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL;
398475e0ac9SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL;
399b7e05686SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL;
4000c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL;
40132d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
4020c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
403b7e05686SMatthew G. Knepley   ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr);
40432d2bbc9SMatthew G. Knepley   ierr = PetscFree(prob->update);CHKERRQ(ierr);
4052764a2aaSMatthew G. Knepley   prob->obj = tmpobj;
4062764a2aaSMatthew G. Knepley   prob->f   = tmpf;
4072764a2aaSMatthew G. Knepley   prob->g   = tmpg;
408475e0ac9SMatthew G. Knepley   prob->gp  = tmpgp;
409b7e05686SMatthew G. Knepley   prob->gt  = tmpgt;
4100c2f2876SMatthew G. Knepley   prob->r   = tmpr;
41132d2bbc9SMatthew G. Knepley   prob->update = tmpup;
4120c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
413c371a6d1SMatthew G. Knepley   ierr = PetscCalloc3(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew, &tmpexactSol);CHKERRQ(ierr);
4142764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f];
4152764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f];
416c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
4172764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL;
4182764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL;
419c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
420c371a6d1SMatthew G. Knepley   ierr = PetscFree3(prob->fBd, prob->gBd, prob->exactSol);CHKERRQ(ierr);
4212764a2aaSMatthew G. Knepley   prob->fBd = tmpfbd;
4222764a2aaSMatthew G. Knepley   prob->gBd = tmpgbd;
423c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
4242764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4252764a2aaSMatthew G. Knepley }
4262764a2aaSMatthew G. Knepley 
4272764a2aaSMatthew G. Knepley /*@
4282764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
4292764a2aaSMatthew G. Knepley 
4302764a2aaSMatthew G. Knepley   Collective on PetscDS
4312764a2aaSMatthew G. Knepley 
4322764a2aaSMatthew G. Knepley   Input Parameter:
4332764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
4342764a2aaSMatthew G. Knepley 
4352764a2aaSMatthew G. Knepley   Level: developer
4362764a2aaSMatthew G. Knepley 
4372764a2aaSMatthew G. Knepley .seealso PetscDSView()
4382764a2aaSMatthew G. Knepley @*/
4392764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob)
4402764a2aaSMatthew G. Knepley {
4412764a2aaSMatthew G. Knepley   PetscInt       f;
44258ebd649SToby Isaac   DSBoundary     next;
4432764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4442764a2aaSMatthew G. Knepley 
4452764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4462764a2aaSMatthew G. Knepley   if (!*prob) PetscFunctionReturn(0);
4472764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1);
4482764a2aaSMatthew G. Knepley 
4492764a2aaSMatthew G. Knepley   if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);}
4502764a2aaSMatthew G. Knepley   ((PetscObject) (*prob))->refct = 0;
451*df3a45bdSMatthew G. Knepley   if ((*prob)->subprobs) {
452*df3a45bdSMatthew G. Knepley     PetscInt dim, d;
453*df3a45bdSMatthew G. Knepley 
454*df3a45bdSMatthew G. Knepley     ierr = PetscDSGetSpatialDimension(*prob, &dim);CHKERRQ(ierr);
455*df3a45bdSMatthew G. Knepley     for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*prob)->subprobs[d]);CHKERRQ(ierr);}
456*df3a45bdSMatthew G. Knepley   }
457*df3a45bdSMatthew G. Knepley   ierr = PetscFree((*prob)->subprobs);CHKERRQ(ierr);
4582764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr);
4592764a2aaSMatthew G. Knepley   for (f = 0; f < (*prob)->Nf; ++f) {
4602764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr);
4612764a2aaSMatthew G. Knepley   }
462f744cafaSSander Arens   ierr = PetscFree3((*prob)->disc, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr);
463b7e05686SMatthew G. Knepley   ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr);
46432d2bbc9SMatthew G. Knepley   ierr = PetscFree((*prob)->update);CHKERRQ(ierr);
465c371a6d1SMatthew G. Knepley   ierr = PetscFree3((*prob)->fBd,(*prob)->gBd,(*prob)->exactSol);CHKERRQ(ierr);
4662764a2aaSMatthew G. Knepley   if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);}
46758ebd649SToby Isaac   next = (*prob)->boundary;
46858ebd649SToby Isaac   while (next) {
46958ebd649SToby Isaac     DSBoundary b = next;
47058ebd649SToby Isaac 
47158ebd649SToby Isaac     next = b->next;
47258ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
47358ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
47458ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
47558ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
47658ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
47758ebd649SToby Isaac   }
47897b6e6e8SMatthew G. Knepley   ierr = PetscFree((*prob)->constants);CHKERRQ(ierr);
4792764a2aaSMatthew G. Knepley   ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr);
4802764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4812764a2aaSMatthew G. Knepley }
4822764a2aaSMatthew G. Knepley 
4832764a2aaSMatthew G. Knepley /*@
4842764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
4852764a2aaSMatthew G. Knepley 
4862764a2aaSMatthew G. Knepley   Collective on MPI_Comm
4872764a2aaSMatthew G. Knepley 
4882764a2aaSMatthew G. Knepley   Input Parameter:
4892764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
4902764a2aaSMatthew G. Knepley 
4912764a2aaSMatthew G. Knepley   Output Parameter:
4922764a2aaSMatthew G. Knepley . prob - The PetscDS object
4932764a2aaSMatthew G. Knepley 
4942764a2aaSMatthew G. Knepley   Level: beginner
4952764a2aaSMatthew G. Knepley 
4962764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
4972764a2aaSMatthew G. Knepley @*/
4982764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob)
4992764a2aaSMatthew G. Knepley {
5002764a2aaSMatthew G. Knepley   PetscDS   p;
5012764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5022764a2aaSMatthew G. Knepley 
5032764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5042764a2aaSMatthew G. Knepley   PetscValidPointer(prob, 2);
5052764a2aaSMatthew G. Knepley   *prob  = NULL;
5062764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5072764a2aaSMatthew G. Knepley 
50873107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5092764a2aaSMatthew G. Knepley 
5102764a2aaSMatthew G. Knepley   p->Nf    = 0;
5112764a2aaSMatthew G. Knepley   p->setup = PETSC_FALSE;
51297b6e6e8SMatthew G. Knepley   p->numConstants = 0;
51397b6e6e8SMatthew G. Knepley   p->constants    = NULL;
514a859676bSMatthew G. Knepley   p->dimEmbed     = -1;
5152764a2aaSMatthew G. Knepley 
5162764a2aaSMatthew G. Knepley   *prob = p;
5172764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5182764a2aaSMatthew G. Knepley }
5192764a2aaSMatthew G. Knepley 
520bc4ae4beSMatthew G. Knepley /*@
521bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
522bc4ae4beSMatthew G. Knepley 
523bc4ae4beSMatthew G. Knepley   Not collective
524bc4ae4beSMatthew G. Knepley 
525bc4ae4beSMatthew G. Knepley   Input Parameter:
526bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
527bc4ae4beSMatthew G. Knepley 
528bc4ae4beSMatthew G. Knepley   Output Parameter:
529bc4ae4beSMatthew G. Knepley . Nf - The number of fields
530bc4ae4beSMatthew G. Knepley 
531bc4ae4beSMatthew G. Knepley   Level: beginner
532bc4ae4beSMatthew G. Knepley 
533bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
534bc4ae4beSMatthew G. Knepley @*/
5352764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
5362764a2aaSMatthew G. Knepley {
5372764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5382764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5392764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
5402764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
5412764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5422764a2aaSMatthew G. Knepley }
5432764a2aaSMatthew G. Knepley 
544bc4ae4beSMatthew G. Knepley /*@
545a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
546bc4ae4beSMatthew G. Knepley 
547bc4ae4beSMatthew G. Knepley   Not collective
548bc4ae4beSMatthew G. Knepley 
549bc4ae4beSMatthew G. Knepley   Input Parameter:
550bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
551bc4ae4beSMatthew G. Knepley 
552bc4ae4beSMatthew G. Knepley   Output Parameter:
553bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
554bc4ae4beSMatthew G. Knepley 
555bc4ae4beSMatthew G. Knepley   Level: beginner
556bc4ae4beSMatthew G. Knepley 
557a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate()
558bc4ae4beSMatthew G. Knepley @*/
5592764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
5602764a2aaSMatthew G. Knepley {
5612764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5622764a2aaSMatthew G. Knepley 
5632764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5642764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5652764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
5662764a2aaSMatthew G. Knepley   *dim = 0;
5679de99aefSMatthew G. Knepley   if (prob->Nf) {
5689de99aefSMatthew G. Knepley     PetscObject  obj;
5699de99aefSMatthew G. Knepley     PetscClassId id;
5709de99aefSMatthew G. Knepley 
5719de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
5729de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
5739de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
5749de99aefSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
5759de99aefSMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
5769de99aefSMatthew G. Knepley   }
5772764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5782764a2aaSMatthew G. Knepley }
5792764a2aaSMatthew G. Knepley 
580bc4ae4beSMatthew G. Knepley /*@
581a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
582a859676bSMatthew G. Knepley 
583a859676bSMatthew G. Knepley   Not collective
584a859676bSMatthew G. Knepley 
585a859676bSMatthew G. Knepley   Input Parameter:
586a859676bSMatthew G. Knepley . prob - The PetscDS object
587a859676bSMatthew G. Knepley 
588a859676bSMatthew G. Knepley   Output Parameter:
589a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
590a859676bSMatthew G. Knepley 
591a859676bSMatthew G. Knepley   Level: beginner
592a859676bSMatthew G. Knepley 
593a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
594a859676bSMatthew G. Knepley @*/
595a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
596a859676bSMatthew G. Knepley {
597a859676bSMatthew G. Knepley   PetscFunctionBegin;
598a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
599a859676bSMatthew G. Knepley   PetscValidPointer(dimEmbed, 2);
600a859676bSMatthew G. Knepley   if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
601a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
602a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
603a859676bSMatthew G. Knepley }
604a859676bSMatthew G. Knepley 
605a859676bSMatthew G. Knepley /*@
606a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
607a859676bSMatthew G. Knepley 
608a859676bSMatthew G. Knepley   Not collective
609a859676bSMatthew G. Knepley 
610a859676bSMatthew G. Knepley   Input Parameters:
611a859676bSMatthew G. Knepley + prob - The PetscDS object
612a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
613a859676bSMatthew G. Knepley 
614a859676bSMatthew G. Knepley   Level: beginner
615a859676bSMatthew G. Knepley 
616a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
617a859676bSMatthew G. Knepley @*/
618a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
619a859676bSMatthew G. Knepley {
620a859676bSMatthew G. Knepley   PetscFunctionBegin;
621a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
622a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
623a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
624a859676bSMatthew G. Knepley }
625a859676bSMatthew G. Knepley 
626a859676bSMatthew G. Knepley /*@
627bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
628bc4ae4beSMatthew G. Knepley 
629bc4ae4beSMatthew G. Knepley   Not collective
630bc4ae4beSMatthew G. Knepley 
631bc4ae4beSMatthew G. Knepley   Input Parameter:
632bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
633bc4ae4beSMatthew G. Knepley 
634bc4ae4beSMatthew G. Knepley   Output Parameter:
635bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
636bc4ae4beSMatthew G. Knepley 
637bc4ae4beSMatthew G. Knepley   Level: beginner
638bc4ae4beSMatthew G. Knepley 
639bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
640bc4ae4beSMatthew G. Knepley @*/
6412764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
6422764a2aaSMatthew G. Knepley {
6432764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6442764a2aaSMatthew G. Knepley 
6452764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6462764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6472764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6482764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6492764a2aaSMatthew G. Knepley   *dim = prob->totDim;
6502764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6512764a2aaSMatthew G. Knepley }
6522764a2aaSMatthew G. Knepley 
653bc4ae4beSMatthew G. Knepley /*@
654bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
655bc4ae4beSMatthew G. Knepley 
656bc4ae4beSMatthew G. Knepley   Not collective
657bc4ae4beSMatthew G. Knepley 
658bc4ae4beSMatthew G. Knepley   Input Parameter:
659bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
660bc4ae4beSMatthew G. Knepley 
661bc4ae4beSMatthew G. Knepley   Output Parameter:
662bc4ae4beSMatthew G. Knepley . dim - The total number of components
663bc4ae4beSMatthew G. Knepley 
664bc4ae4beSMatthew G. Knepley   Level: beginner
665bc4ae4beSMatthew G. Knepley 
666bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
667bc4ae4beSMatthew G. Knepley @*/
6682764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
6692764a2aaSMatthew G. Knepley {
6702764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6712764a2aaSMatthew G. Knepley 
6722764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6732764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6742764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6752764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
6762764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
6772764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6782764a2aaSMatthew G. Knepley }
6792764a2aaSMatthew G. Knepley 
680bc4ae4beSMatthew G. Knepley /*@
681bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
682bc4ae4beSMatthew G. Knepley 
683bc4ae4beSMatthew G. Knepley   Not collective
684bc4ae4beSMatthew G. Knepley 
685bc4ae4beSMatthew G. Knepley   Input Parameters:
686bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
687bc4ae4beSMatthew G. Knepley - f - The field number
688bc4ae4beSMatthew G. Knepley 
689bc4ae4beSMatthew G. Knepley   Output Parameter:
690bc4ae4beSMatthew G. Knepley . disc - The discretization object
691bc4ae4beSMatthew G. Knepley 
692bc4ae4beSMatthew G. Knepley   Level: beginner
693bc4ae4beSMatthew G. Knepley 
694f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
695bc4ae4beSMatthew G. Knepley @*/
6962764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
6972764a2aaSMatthew G. Knepley {
6982764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6992764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7002764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
7012764a2aaSMatthew 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);
7022764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
7032764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7042764a2aaSMatthew G. Knepley }
7052764a2aaSMatthew G. Knepley 
706bc4ae4beSMatthew G. Knepley /*@
707bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
708bc4ae4beSMatthew G. Knepley 
709bc4ae4beSMatthew G. Knepley   Not collective
710bc4ae4beSMatthew G. Knepley 
711bc4ae4beSMatthew G. Knepley   Input Parameters:
712bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
713bc4ae4beSMatthew G. Knepley . f - The field number
714bc4ae4beSMatthew G. Knepley - disc - The discretization object
715bc4ae4beSMatthew G. Knepley 
716bc4ae4beSMatthew G. Knepley   Level: beginner
717bc4ae4beSMatthew G. Knepley 
718bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
719bc4ae4beSMatthew G. Knepley @*/
7202764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
7212764a2aaSMatthew G. Knepley {
7222764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7232764a2aaSMatthew G. Knepley 
7242764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7252764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7262764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
7272764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
7282764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
7292764a2aaSMatthew G. Knepley   if (prob->disc[f]) {ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);}
7302764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
7312764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
732249df284SMatthew G. Knepley   {
733249df284SMatthew G. Knepley     PetscClassId id;
734249df284SMatthew G. Knepley 
735249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
736a6cbbb48SMatthew G. Knepley     if (id == PETSCFV_CLASSID) {
737a6cbbb48SMatthew G. Knepley       prob->implicit[f]      = PETSC_FALSE;
738a6cbbb48SMatthew G. Knepley       prob->adjacency[f*2+0] = PETSC_TRUE;
739a6cbbb48SMatthew G. Knepley       prob->adjacency[f*2+1] = PETSC_FALSE;
740a6cbbb48SMatthew G. Knepley     }
741249df284SMatthew G. Knepley   }
7422764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7432764a2aaSMatthew G. Knepley }
7442764a2aaSMatthew G. Knepley 
745bc4ae4beSMatthew G. Knepley /*@
746bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
747bc4ae4beSMatthew G. Knepley 
748bc4ae4beSMatthew G. Knepley   Not collective
749bc4ae4beSMatthew G. Knepley 
750bc4ae4beSMatthew G. Knepley   Input Parameters:
751bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
752bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
753bc4ae4beSMatthew G. Knepley 
754bc4ae4beSMatthew G. Knepley   Level: beginner
755bc4ae4beSMatthew G. Knepley 
756bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
757bc4ae4beSMatthew G. Knepley @*/
7582764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
7592764a2aaSMatthew G. Knepley {
7602764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7612764a2aaSMatthew G. Knepley 
7622764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7632764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
7642764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7652764a2aaSMatthew G. Knepley }
7662764a2aaSMatthew G. Knepley 
767249df284SMatthew G. Knepley /*@
768249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
769249df284SMatthew G. Knepley 
770249df284SMatthew G. Knepley   Not collective
771249df284SMatthew G. Knepley 
772249df284SMatthew G. Knepley   Input Parameters:
773249df284SMatthew G. Knepley + prob - The PetscDS object
774249df284SMatthew G. Knepley - f - The field number
775249df284SMatthew G. Knepley 
776249df284SMatthew G. Knepley   Output Parameter:
777249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
778249df284SMatthew G. Knepley 
779249df284SMatthew G. Knepley   Level: developer
780249df284SMatthew G. Knepley 
781f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
782249df284SMatthew G. Knepley @*/
783249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
784249df284SMatthew G. Knepley {
785249df284SMatthew G. Knepley   PetscFunctionBegin;
786249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
787249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
788249df284SMatthew 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);
789249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
790249df284SMatthew G. Knepley   PetscFunctionReturn(0);
791249df284SMatthew G. Knepley }
792249df284SMatthew G. Knepley 
793249df284SMatthew G. Knepley /*@
794249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
795249df284SMatthew G. Knepley 
796249df284SMatthew G. Knepley   Not collective
797249df284SMatthew G. Knepley 
798249df284SMatthew G. Knepley   Input Parameters:
799249df284SMatthew G. Knepley + prob - The PetscDS object
800249df284SMatthew G. Knepley . f - The field number
801249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
802249df284SMatthew G. Knepley 
803249df284SMatthew G. Knepley   Level: developer
804249df284SMatthew G. Knepley 
805f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
806249df284SMatthew G. Knepley @*/
807249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
808249df284SMatthew G. Knepley {
809249df284SMatthew G. Knepley   PetscFunctionBegin;
810249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
811249df284SMatthew 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);
812249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
813249df284SMatthew G. Knepley   PetscFunctionReturn(0);
814249df284SMatthew G. Knepley }
815249df284SMatthew G. Knepley 
816a6cbbb48SMatthew G. Knepley /*@
817a6cbbb48SMatthew G. Knepley   PetscDSGetAdjacency - Returns the flags for determining variable influence
818a6cbbb48SMatthew G. Knepley 
819a6cbbb48SMatthew G. Knepley   Not collective
820a6cbbb48SMatthew G. Knepley 
821a6cbbb48SMatthew G. Knepley   Input Parameters:
822a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
823a6cbbb48SMatthew G. Knepley - f - The field number
824a6cbbb48SMatthew G. Knepley 
825a6cbbb48SMatthew G. Knepley   Output Parameter:
826a6cbbb48SMatthew G. Knepley + useCone    - Flag for variable influence starting with the cone operation
827a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
828a6cbbb48SMatthew G. Knepley 
829a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
830a6cbbb48SMatthew G. Knepley 
831a6cbbb48SMatthew G. Knepley   Level: developer
832a6cbbb48SMatthew G. Knepley 
833f744cafaSSander Arens .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
834a6cbbb48SMatthew G. Knepley @*/
835a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure)
836a6cbbb48SMatthew G. Knepley {
837a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
838a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
839a6cbbb48SMatthew G. Knepley   PetscValidPointer(useCone, 3);
840a6cbbb48SMatthew G. Knepley   PetscValidPointer(useClosure, 4);
841a6cbbb48SMatthew 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);
842a6cbbb48SMatthew G. Knepley   *useCone    = prob->adjacency[f*2+0];
843a6cbbb48SMatthew G. Knepley   *useClosure = prob->adjacency[f*2+1];
844a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
845a6cbbb48SMatthew G. Knepley }
846a6cbbb48SMatthew G. Knepley 
847a6cbbb48SMatthew G. Knepley /*@
848a6cbbb48SMatthew G. Knepley   PetscDSSetAdjacency - Set the flags for determining variable influence
849a6cbbb48SMatthew G. Knepley 
850a6cbbb48SMatthew G. Knepley   Not collective
851a6cbbb48SMatthew G. Knepley 
852a6cbbb48SMatthew G. Knepley   Input Parameters:
853a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
854a6cbbb48SMatthew G. Knepley . f - The field number
855a6cbbb48SMatthew G. Knepley . useCone    - Flag for variable influence starting with the cone operation
856a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
857a6cbbb48SMatthew G. Knepley 
858a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
859a6cbbb48SMatthew G. Knepley 
860a6cbbb48SMatthew G. Knepley   Level: developer
861a6cbbb48SMatthew G. Knepley 
862f744cafaSSander Arens .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
863a6cbbb48SMatthew G. Knepley @*/
864a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure)
865a6cbbb48SMatthew G. Knepley {
866a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
867a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
868a6cbbb48SMatthew 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);
869a6cbbb48SMatthew G. Knepley   prob->adjacency[f*2+0] = useCone;
870a6cbbb48SMatthew G. Knepley   prob->adjacency[f*2+1] = useClosure;
871a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
872a6cbbb48SMatthew G. Knepley }
873a6cbbb48SMatthew G. Knepley 
8742764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f,
87530b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
876194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
877194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
87897b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
8792764a2aaSMatthew G. Knepley {
8802764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8812764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8822764a2aaSMatthew G. Knepley   PetscValidPointer(obj, 2);
8832764a2aaSMatthew 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);
8842764a2aaSMatthew G. Knepley   *obj = prob->obj[f];
8852764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
8862764a2aaSMatthew G. Knepley }
8872764a2aaSMatthew G. Knepley 
8882764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f,
88930b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
890194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
891194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
89297b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
8932764a2aaSMatthew G. Knepley {
8942764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
8952764a2aaSMatthew G. Knepley 
8962764a2aaSMatthew G. Knepley   PetscFunctionBegin;
8972764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
898de716cbcSToby Isaac   if (obj) PetscValidFunction(obj, 2);
8992764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
9002764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
9012764a2aaSMatthew G. Knepley   prob->obj[f] = obj;
9022764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9032764a2aaSMatthew G. Knepley }
9042764a2aaSMatthew G. Knepley 
905194d53e6SMatthew G. Knepley /*@C
906194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
907194d53e6SMatthew G. Knepley 
908194d53e6SMatthew G. Knepley   Not collective
909194d53e6SMatthew G. Knepley 
910194d53e6SMatthew G. Knepley   Input Parameters:
911194d53e6SMatthew G. Knepley + prob - The PetscDS
912194d53e6SMatthew G. Knepley - f    - The test field number
913194d53e6SMatthew G. Knepley 
914194d53e6SMatthew G. Knepley   Output Parameters:
915194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
916194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
917194d53e6SMatthew G. Knepley 
918194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
919194d53e6SMatthew G. Knepley 
920194d53e6SMatthew 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)
921194d53e6SMatthew G. Knepley 
922194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
923194d53e6SMatthew G. Knepley 
92430b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
925194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
926194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
92730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
928194d53e6SMatthew G. Knepley 
929194d53e6SMatthew G. Knepley + dim - the spatial dimension
930194d53e6SMatthew G. Knepley . Nf - the number of fields
931194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
932194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
933194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
934194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
935194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
936194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
937194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
938194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
939194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
940194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
941194d53e6SMatthew G. Knepley . t - current time
942194d53e6SMatthew G. Knepley . x - coordinates of the current point
94397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
94497b6e6e8SMatthew G. Knepley . constants - constant parameters
945194d53e6SMatthew G. Knepley - f0 - output values at the current point
946194d53e6SMatthew G. Knepley 
947194d53e6SMatthew G. Knepley   Level: intermediate
948194d53e6SMatthew G. Knepley 
949194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
950194d53e6SMatthew G. Knepley @*/
9512764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f,
95230b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
953194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
954194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
95597b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
95630b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
957194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
958194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
95997b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
9602764a2aaSMatthew G. Knepley {
9612764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9622764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9632764a2aaSMatthew 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);
9642764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];}
9652764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];}
9662764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9672764a2aaSMatthew G. Knepley }
9682764a2aaSMatthew G. Knepley 
969194d53e6SMatthew G. Knepley /*@C
970194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
971194d53e6SMatthew G. Knepley 
972194d53e6SMatthew G. Knepley   Not collective
973194d53e6SMatthew G. Knepley 
974194d53e6SMatthew G. Knepley   Input Parameters:
975194d53e6SMatthew G. Knepley + prob - The PetscDS
976194d53e6SMatthew G. Knepley . f    - The test field number
977194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
978194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
979194d53e6SMatthew G. Knepley 
980194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
981194d53e6SMatthew G. Knepley 
982194d53e6SMatthew 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)
983194d53e6SMatthew G. Knepley 
984194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
985194d53e6SMatthew G. Knepley 
98630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
987194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
988194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
98930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
990194d53e6SMatthew G. Knepley 
991194d53e6SMatthew G. Knepley + dim - the spatial dimension
992194d53e6SMatthew G. Knepley . Nf - the number of fields
993194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
994194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
995194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
996194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
997194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
998194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
999194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1000194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1001194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1002194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1003194d53e6SMatthew G. Knepley . t - current time
1004194d53e6SMatthew G. Knepley . x - coordinates of the current point
100597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
100697b6e6e8SMatthew G. Knepley . constants - constant parameters
1007194d53e6SMatthew G. Knepley - f0 - output values at the current point
1008194d53e6SMatthew G. Knepley 
1009194d53e6SMatthew G. Knepley   Level: intermediate
1010194d53e6SMatthew G. Knepley 
1011194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1012194d53e6SMatthew G. Knepley @*/
10132764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f,
101430b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1015194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1016194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
101797b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
101830b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1019194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1020194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
102197b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
10222764a2aaSMatthew G. Knepley {
10232764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
10242764a2aaSMatthew G. Knepley 
10252764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10262764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1027f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1028f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
10292764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
10302764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
10312764a2aaSMatthew G. Knepley   prob->f[f*2+0] = f0;
10322764a2aaSMatthew G. Knepley   prob->f[f*2+1] = f1;
10332764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10342764a2aaSMatthew G. Knepley }
10352764a2aaSMatthew G. Knepley 
10363e75805dSMatthew G. Knepley /*@C
10373e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
10383e75805dSMatthew G. Knepley 
10393e75805dSMatthew G. Knepley   Not collective
10403e75805dSMatthew G. Knepley 
10413e75805dSMatthew G. Knepley   Input Parameter:
10423e75805dSMatthew G. Knepley . prob - The PetscDS
10433e75805dSMatthew G. Knepley 
10443e75805dSMatthew G. Knepley   Output Parameter:
10453e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
10463e75805dSMatthew G. Knepley 
10473e75805dSMatthew G. Knepley   Level: intermediate
10483e75805dSMatthew G. Knepley 
10493e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
10503e75805dSMatthew G. Knepley @*/
10513e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac)
10523e75805dSMatthew G. Knepley {
10533e75805dSMatthew G. Knepley   PetscInt f, g, h;
10543e75805dSMatthew G. Knepley 
10553e75805dSMatthew G. Knepley   PetscFunctionBegin;
10563e75805dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10573e75805dSMatthew G. Knepley   *hasJac = PETSC_FALSE;
10583e75805dSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
10593e75805dSMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
10603e75805dSMatthew G. Knepley       for (h = 0; h < 4; ++h) {
10613e75805dSMatthew G. Knepley         if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE;
10623e75805dSMatthew G. Knepley       }
10633e75805dSMatthew G. Knepley     }
10643e75805dSMatthew G. Knepley   }
10653e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
10663e75805dSMatthew G. Knepley }
10673e75805dSMatthew G. Knepley 
1068194d53e6SMatthew G. Knepley /*@C
1069194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1070194d53e6SMatthew G. Knepley 
1071194d53e6SMatthew G. Knepley   Not collective
1072194d53e6SMatthew G. Knepley 
1073194d53e6SMatthew G. Knepley   Input Parameters:
1074194d53e6SMatthew G. Knepley + prob - The PetscDS
1075194d53e6SMatthew G. Knepley . f    - The test field number
1076194d53e6SMatthew G. Knepley - g    - The field number
1077194d53e6SMatthew G. Knepley 
1078194d53e6SMatthew G. Knepley   Output Parameters:
1079194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1080194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1081194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1082194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1083194d53e6SMatthew G. Knepley 
1084194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1085194d53e6SMatthew G. Knepley 
1086194d53e6SMatthew 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
1087194d53e6SMatthew G. Knepley 
1088194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1089194d53e6SMatthew G. Knepley 
109030b9ff8bSMatthew G. Knepley $ g0(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[],
109330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1094194d53e6SMatthew G. Knepley 
1095194d53e6SMatthew G. Knepley + dim - the spatial dimension
1096194d53e6SMatthew G. Knepley . Nf - the number of fields
1097194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1098194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1099194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1100194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1101194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1102194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1103194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1104194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1105194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1106194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1107194d53e6SMatthew G. Knepley . t - current time
11082aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1109194d53e6SMatthew G. Knepley . x - coordinates of the current point
111097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
111197b6e6e8SMatthew G. Knepley . constants - constant parameters
1112194d53e6SMatthew G. Knepley - g0 - output values at the current point
1113194d53e6SMatthew G. Knepley 
1114194d53e6SMatthew G. Knepley   Level: intermediate
1115194d53e6SMatthew G. Knepley 
1116194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1117194d53e6SMatthew G. Knepley @*/
11182764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g,
111930b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1120194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1121194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
112297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
112330b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1124194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1125194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
112697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
112730b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1128194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1129194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
113097b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
113130b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1132194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1133194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
113497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
11352764a2aaSMatthew G. Knepley {
11362764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11372764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11382764a2aaSMatthew 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);
11392764a2aaSMatthew 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);
11402764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];}
11412764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];}
11422764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];}
11432764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];}
11442764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11452764a2aaSMatthew G. Knepley }
11462764a2aaSMatthew G. Knepley 
1147194d53e6SMatthew G. Knepley /*@C
1148194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1149194d53e6SMatthew G. Knepley 
1150194d53e6SMatthew G. Knepley   Not collective
1151194d53e6SMatthew G. Knepley 
1152194d53e6SMatthew G. Knepley   Input Parameters:
1153194d53e6SMatthew G. Knepley + prob - The PetscDS
1154194d53e6SMatthew G. Knepley . f    - The test field number
1155194d53e6SMatthew G. Knepley . g    - The field number
1156194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1157194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1158194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1159194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1160194d53e6SMatthew G. Knepley 
1161194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1162194d53e6SMatthew G. Knepley 
1163194d53e6SMatthew 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
1164194d53e6SMatthew G. Knepley 
1165194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1166194d53e6SMatthew G. Knepley 
116730b9ff8bSMatthew G. Knepley $ g0(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[],
117030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1171194d53e6SMatthew G. Knepley 
1172194d53e6SMatthew G. Knepley + dim - the spatial dimension
1173194d53e6SMatthew G. Knepley . Nf - the number of fields
1174194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1175194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1176194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1177194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1178194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1179194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1180194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1181194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1182194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1183194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1184194d53e6SMatthew G. Knepley . t - current time
11852aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1186194d53e6SMatthew G. Knepley . x - coordinates of the current point
118797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
118897b6e6e8SMatthew G. Knepley . constants - constant parameters
1189194d53e6SMatthew G. Knepley - g0 - output values at the current point
1190194d53e6SMatthew G. Knepley 
1191194d53e6SMatthew G. Knepley   Level: intermediate
1192194d53e6SMatthew G. Knepley 
1193194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1194194d53e6SMatthew G. Knepley @*/
11952764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g,
119630b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1197194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1198194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
119997b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
120030b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1201194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1202194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
120397b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
120430b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1205194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1206194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
120797b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
120830b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1209194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1210194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
121197b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
12122764a2aaSMatthew G. Knepley {
12132764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
12142764a2aaSMatthew G. Knepley 
12152764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12162764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
12172764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
12182764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
12192764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
12202764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
12212764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
12222764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
12232764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
12242764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+0] = g0;
12252764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+1] = g1;
12262764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+2] = g2;
12272764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+3] = g3;
12282764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12292764a2aaSMatthew G. Knepley }
12302764a2aaSMatthew G. Knepley 
1231475e0ac9SMatthew G. Knepley /*@C
1232475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1233475e0ac9SMatthew G. Knepley 
1234475e0ac9SMatthew G. Knepley   Not collective
1235475e0ac9SMatthew G. Knepley 
1236475e0ac9SMatthew G. Knepley   Input Parameter:
1237475e0ac9SMatthew G. Knepley . prob - The PetscDS
1238475e0ac9SMatthew G. Knepley 
1239475e0ac9SMatthew G. Knepley   Output Parameter:
1240475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1241475e0ac9SMatthew G. Knepley 
1242475e0ac9SMatthew G. Knepley   Level: intermediate
1243475e0ac9SMatthew G. Knepley 
1244475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1245475e0ac9SMatthew G. Knepley @*/
1246475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre)
1247475e0ac9SMatthew G. Knepley {
1248475e0ac9SMatthew G. Knepley   PetscInt f, g, h;
1249475e0ac9SMatthew G. Knepley 
1250475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1251475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1252475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
1253475e0ac9SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1254475e0ac9SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1255475e0ac9SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1256475e0ac9SMatthew G. Knepley         if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE;
1257475e0ac9SMatthew G. Knepley       }
1258475e0ac9SMatthew G. Knepley     }
1259475e0ac9SMatthew G. Knepley   }
1260475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1261475e0ac9SMatthew G. Knepley }
1262475e0ac9SMatthew G. Knepley 
1263475e0ac9SMatthew G. Knepley /*@C
1264475e0ac9SMatthew 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.
1265475e0ac9SMatthew G. Knepley 
1266475e0ac9SMatthew G. Knepley   Not collective
1267475e0ac9SMatthew G. Knepley 
1268475e0ac9SMatthew G. Knepley   Input Parameters:
1269475e0ac9SMatthew G. Knepley + prob - The PetscDS
1270475e0ac9SMatthew G. Knepley . f    - The test field number
1271475e0ac9SMatthew G. Knepley - g    - The field number
1272475e0ac9SMatthew G. Knepley 
1273475e0ac9SMatthew G. Knepley   Output Parameters:
1274475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1275475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1276475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1277475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1278475e0ac9SMatthew G. Knepley 
1279475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1280475e0ac9SMatthew G. Knepley 
1281475e0ac9SMatthew 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
1282475e0ac9SMatthew G. Knepley 
1283475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1284475e0ac9SMatthew G. Knepley 
1285475e0ac9SMatthew G. Knepley $ g0(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[],
1288475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1289475e0ac9SMatthew G. Knepley 
1290475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1291475e0ac9SMatthew G. Knepley . Nf - the number of fields
1292475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1293475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1294475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1295475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1296475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1297475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1298475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1299475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1300475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1301475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1302475e0ac9SMatthew G. Knepley . t - current time
1303475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1304475e0ac9SMatthew G. Knepley . x - coordinates of the current point
130597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
130697b6e6e8SMatthew G. Knepley . constants - constant parameters
1307475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1308475e0ac9SMatthew G. Knepley 
1309475e0ac9SMatthew G. Knepley   Level: intermediate
1310475e0ac9SMatthew G. Knepley 
1311475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1312475e0ac9SMatthew G. Knepley @*/
1313475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1314475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1315475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1316475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
131797b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1318475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1319475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1320475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
132197b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1322475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1323475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1324475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
132597b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1326475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1327475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1328475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
132997b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1330475e0ac9SMatthew G. Knepley {
1331475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1332475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1333475e0ac9SMatthew 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);
1334475e0ac9SMatthew 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);
1335475e0ac9SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];}
1336475e0ac9SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];}
1337475e0ac9SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];}
1338475e0ac9SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];}
1339475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1340475e0ac9SMatthew G. Knepley }
1341475e0ac9SMatthew G. Knepley 
1342475e0ac9SMatthew G. Knepley /*@C
1343475e0ac9SMatthew 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.
1344475e0ac9SMatthew G. Knepley 
1345475e0ac9SMatthew G. Knepley   Not collective
1346475e0ac9SMatthew G. Knepley 
1347475e0ac9SMatthew G. Knepley   Input Parameters:
1348475e0ac9SMatthew G. Knepley + prob - The PetscDS
1349475e0ac9SMatthew G. Knepley . f    - The test field number
1350475e0ac9SMatthew G. Knepley . g    - The field number
1351475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1352475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1353475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1354475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1355475e0ac9SMatthew G. Knepley 
1356475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1357475e0ac9SMatthew G. Knepley 
1358475e0ac9SMatthew 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
1359475e0ac9SMatthew G. Knepley 
1360475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1361475e0ac9SMatthew G. Knepley 
1362475e0ac9SMatthew G. Knepley $ g0(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[],
1365475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1366475e0ac9SMatthew G. Knepley 
1367475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1368475e0ac9SMatthew G. Knepley . Nf - the number of fields
1369475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1370475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1371475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1372475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1373475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1374475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1375475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1376475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1377475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1378475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1379475e0ac9SMatthew G. Knepley . t - current time
1380475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1381475e0ac9SMatthew G. Knepley . x - coordinates of the current point
138297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
138397b6e6e8SMatthew G. Knepley . constants - constant parameters
1384475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1385475e0ac9SMatthew G. Knepley 
1386475e0ac9SMatthew G. Knepley   Level: intermediate
1387475e0ac9SMatthew G. Knepley 
1388475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1389475e0ac9SMatthew G. Knepley @*/
1390475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1391475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1392475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1393475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
139497b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1395475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1396475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1397475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
139897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1399475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1400475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1401475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
140297b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1403475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1404475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1405475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
140697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1407475e0ac9SMatthew G. Knepley {
1408475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1409475e0ac9SMatthew G. Knepley 
1410475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1411475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1412475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1413475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1414475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1415475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1416475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1417475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1418475e0ac9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1419475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+0] = g0;
1420475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+1] = g1;
1421475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+2] = g2;
1422475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+3] = g3;
1423475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1424475e0ac9SMatthew G. Knepley }
1425475e0ac9SMatthew G. Knepley 
1426b7e05686SMatthew G. Knepley /*@C
1427b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1428b7e05686SMatthew G. Knepley 
1429b7e05686SMatthew G. Knepley   Not collective
1430b7e05686SMatthew G. Knepley 
1431b7e05686SMatthew G. Knepley   Input Parameter:
1432b7e05686SMatthew G. Knepley . prob - The PetscDS
1433b7e05686SMatthew G. Knepley 
1434b7e05686SMatthew G. Knepley   Output Parameter:
1435b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1436b7e05686SMatthew G. Knepley 
1437b7e05686SMatthew G. Knepley   Level: intermediate
1438b7e05686SMatthew G. Knepley 
1439b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1440b7e05686SMatthew G. Knepley @*/
1441b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac)
1442b7e05686SMatthew G. Knepley {
1443b7e05686SMatthew G. Knepley   PetscInt f, g, h;
1444b7e05686SMatthew G. Knepley 
1445b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1446b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1447b7e05686SMatthew G. Knepley   *hasDynJac = PETSC_FALSE;
1448b7e05686SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1449b7e05686SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1450b7e05686SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1451b7e05686SMatthew G. Knepley         if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE;
1452b7e05686SMatthew G. Knepley       }
1453b7e05686SMatthew G. Knepley     }
1454b7e05686SMatthew G. Knepley   }
1455b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1456b7e05686SMatthew G. Knepley }
1457b7e05686SMatthew G. Knepley 
1458b7e05686SMatthew G. Knepley /*@C
1459b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1460b7e05686SMatthew G. Knepley 
1461b7e05686SMatthew G. Knepley   Not collective
1462b7e05686SMatthew G. Knepley 
1463b7e05686SMatthew G. Knepley   Input Parameters:
1464b7e05686SMatthew G. Knepley + prob - The PetscDS
1465b7e05686SMatthew G. Knepley . f    - The test field number
1466b7e05686SMatthew G. Knepley - g    - The field number
1467b7e05686SMatthew G. Knepley 
1468b7e05686SMatthew G. Knepley   Output Parameters:
1469b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1470b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1471b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1472b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1473b7e05686SMatthew G. Knepley 
1474b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1475b7e05686SMatthew G. Knepley 
1476b7e05686SMatthew 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
1477b7e05686SMatthew G. Knepley 
1478b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1479b7e05686SMatthew G. Knepley 
1480b7e05686SMatthew G. Knepley $ g0(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[],
1483b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1484b7e05686SMatthew G. Knepley 
1485b7e05686SMatthew G. Knepley + dim - the spatial dimension
1486b7e05686SMatthew G. Knepley . Nf - the number of fields
1487b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1488b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1489b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1490b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1491b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1492b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1493b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1494b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1495b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1496b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1497b7e05686SMatthew G. Knepley . t - current time
1498b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1499b7e05686SMatthew G. Knepley . x - coordinates of the current point
150097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
150197b6e6e8SMatthew G. Knepley . constants - constant parameters
1502b7e05686SMatthew G. Knepley - g0 - output values at the current point
1503b7e05686SMatthew G. Knepley 
1504b7e05686SMatthew G. Knepley   Level: intermediate
1505b7e05686SMatthew G. Knepley 
1506b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1507b7e05686SMatthew G. Knepley @*/
1508b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1509b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1510b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1511b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
151297b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1513b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1514b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1515b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
151697b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1517b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1518b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1519b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
152097b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1521b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1522b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1523b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
152497b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1525b7e05686SMatthew G. Knepley {
1526b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1527b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1528b7e05686SMatthew 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);
1529b7e05686SMatthew 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);
1530b7e05686SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];}
1531b7e05686SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];}
1532b7e05686SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];}
1533b7e05686SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];}
1534b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1535b7e05686SMatthew G. Knepley }
1536b7e05686SMatthew G. Knepley 
1537b7e05686SMatthew G. Knepley /*@C
1538b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1539b7e05686SMatthew G. Knepley 
1540b7e05686SMatthew G. Knepley   Not collective
1541b7e05686SMatthew G. Knepley 
1542b7e05686SMatthew G. Knepley   Input Parameters:
1543b7e05686SMatthew G. Knepley + prob - The PetscDS
1544b7e05686SMatthew G. Knepley . f    - The test field number
1545b7e05686SMatthew G. Knepley . g    - The field number
1546b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1547b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1548b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1549b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1550b7e05686SMatthew G. Knepley 
1551b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1552b7e05686SMatthew G. Knepley 
1553b7e05686SMatthew 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
1554b7e05686SMatthew G. Knepley 
1555b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1556b7e05686SMatthew G. Knepley 
1557b7e05686SMatthew G. Knepley $ g0(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[],
1560b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1561b7e05686SMatthew G. Knepley 
1562b7e05686SMatthew G. Knepley + dim - the spatial dimension
1563b7e05686SMatthew G. Knepley . Nf - the number of fields
1564b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1565b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1566b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1567b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1568b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1569b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1570b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1571b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1572b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1573b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1574b7e05686SMatthew G. Knepley . t - current time
1575b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1576b7e05686SMatthew G. Knepley . x - coordinates of the current point
157797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
157897b6e6e8SMatthew G. Knepley . constants - constant parameters
1579b7e05686SMatthew G. Knepley - g0 - output values at the current point
1580b7e05686SMatthew G. Knepley 
1581b7e05686SMatthew G. Knepley   Level: intermediate
1582b7e05686SMatthew G. Knepley 
1583b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1584b7e05686SMatthew G. Knepley @*/
1585b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1586b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1587b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1588b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
158997b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1590b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1591b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1592b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
159397b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1594b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1595b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1596b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
159797b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1598b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1599b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1600b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
160197b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1602b7e05686SMatthew G. Knepley {
1603b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1604b7e05686SMatthew G. Knepley 
1605b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1606b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1607b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1608b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1609b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1610b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1611b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1612b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1613b7e05686SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1614b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+0] = g0;
1615b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+1] = g1;
1616b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+2] = g2;
1617b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+3] = g3;
1618b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1619b7e05686SMatthew G. Knepley }
1620b7e05686SMatthew G. Knepley 
16210c2f2876SMatthew G. Knepley /*@C
16220c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
16230c2f2876SMatthew G. Knepley 
16240c2f2876SMatthew G. Knepley   Not collective
16250c2f2876SMatthew G. Knepley 
16260c2f2876SMatthew G. Knepley   Input Arguments:
16270c2f2876SMatthew G. Knepley + prob - The PetscDS object
16280c2f2876SMatthew G. Knepley - f    - The field number
16290c2f2876SMatthew G. Knepley 
16300c2f2876SMatthew G. Knepley   Output Argument:
16310c2f2876SMatthew G. Knepley . r    - Riemann solver
16320c2f2876SMatthew G. Knepley 
16330c2f2876SMatthew G. Knepley   Calling sequence for r:
16340c2f2876SMatthew G. Knepley 
16355db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
16360c2f2876SMatthew G. Knepley 
16375db36cf9SMatthew G. Knepley + dim  - The spatial dimension
16385db36cf9SMatthew G. Knepley . Nf   - The number of fields
16395db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
16400c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
16410c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
16420c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
16430c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
164497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
164597b6e6e8SMatthew G. Knepley . constants - constant parameters
16460c2f2876SMatthew G. Knepley - ctx  - optional user context
16470c2f2876SMatthew G. Knepley 
16480c2f2876SMatthew G. Knepley   Level: intermediate
16490c2f2876SMatthew G. Knepley 
16500c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
16510c2f2876SMatthew G. Knepley @*/
16520c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f,
165397b6e6e8SMatthew 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))
16540c2f2876SMatthew G. Knepley {
16550c2f2876SMatthew G. Knepley   PetscFunctionBegin;
16560c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
16570c2f2876SMatthew 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);
16580c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
16590c2f2876SMatthew G. Knepley   *r = prob->r[f];
16600c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
16610c2f2876SMatthew G. Knepley }
16620c2f2876SMatthew G. Knepley 
16630c2f2876SMatthew G. Knepley /*@C
16640c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
16650c2f2876SMatthew G. Knepley 
16660c2f2876SMatthew G. Knepley   Not collective
16670c2f2876SMatthew G. Knepley 
16680c2f2876SMatthew G. Knepley   Input Arguments:
16690c2f2876SMatthew G. Knepley + prob - The PetscDS object
16700c2f2876SMatthew G. Knepley . f    - The field number
16710c2f2876SMatthew G. Knepley - r    - Riemann solver
16720c2f2876SMatthew G. Knepley 
16730c2f2876SMatthew G. Knepley   Calling sequence for r:
16740c2f2876SMatthew G. Knepley 
16755db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
16760c2f2876SMatthew G. Knepley 
16775db36cf9SMatthew G. Knepley + dim  - The spatial dimension
16785db36cf9SMatthew G. Knepley . Nf   - The number of fields
16795db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
16800c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
16810c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
16820c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
16830c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
168497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
168597b6e6e8SMatthew G. Knepley . constants - constant parameters
16860c2f2876SMatthew G. Knepley - ctx  - optional user context
16870c2f2876SMatthew G. Knepley 
16880c2f2876SMatthew G. Knepley   Level: intermediate
16890c2f2876SMatthew G. Knepley 
16900c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
16910c2f2876SMatthew G. Knepley @*/
16920c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f,
169397b6e6e8SMatthew 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))
16940c2f2876SMatthew G. Knepley {
16950c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
16960c2f2876SMatthew G. Knepley 
16970c2f2876SMatthew G. Knepley   PetscFunctionBegin;
16980c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1699de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
17000c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
17010c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
17020c2f2876SMatthew G. Knepley   prob->r[f] = r;
17030c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17040c2f2876SMatthew G. Knepley }
17050c2f2876SMatthew G. Knepley 
170632d2bbc9SMatthew G. Knepley /*@C
170732d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
170832d2bbc9SMatthew G. Knepley 
170932d2bbc9SMatthew G. Knepley   Not collective
171032d2bbc9SMatthew G. Knepley 
171132d2bbc9SMatthew G. Knepley   Input Parameters:
171232d2bbc9SMatthew G. Knepley + prob - The PetscDS
171332d2bbc9SMatthew G. Knepley - f    - The field number
171432d2bbc9SMatthew G. Knepley 
171532d2bbc9SMatthew G. Knepley   Output Parameters:
171632d2bbc9SMatthew G. Knepley + update - update function
171732d2bbc9SMatthew G. Knepley 
171832d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
171932d2bbc9SMatthew G. Knepley 
172032d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
172132d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
172232d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
172332d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
172432d2bbc9SMatthew G. Knepley 
172532d2bbc9SMatthew G. Knepley + dim - the spatial dimension
172632d2bbc9SMatthew G. Knepley . Nf - the number of fields
172732d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
172832d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
172932d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
173032d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
173132d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
173232d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
173332d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
173432d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
173532d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
173632d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
173732d2bbc9SMatthew G. Knepley . t - current time
173832d2bbc9SMatthew G. Knepley . x - coordinates of the current point
173932d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
174032d2bbc9SMatthew G. Knepley 
174132d2bbc9SMatthew G. Knepley   Level: intermediate
174232d2bbc9SMatthew G. Knepley 
174332d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
174432d2bbc9SMatthew G. Knepley @*/
174532d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f,
174632d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
174732d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
174832d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
17493fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
175032d2bbc9SMatthew G. Knepley {
175132d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
175232d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
175332d2bbc9SMatthew 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);
175432d2bbc9SMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = prob->update[f];}
175532d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
175632d2bbc9SMatthew G. Knepley }
175732d2bbc9SMatthew G. Knepley 
175832d2bbc9SMatthew G. Knepley /*@C
17593fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
176032d2bbc9SMatthew G. Knepley 
176132d2bbc9SMatthew G. Knepley   Not collective
176232d2bbc9SMatthew G. Knepley 
176332d2bbc9SMatthew G. Knepley   Input Parameters:
176432d2bbc9SMatthew G. Knepley + prob   - The PetscDS
176532d2bbc9SMatthew G. Knepley . f      - The field number
176632d2bbc9SMatthew G. Knepley - update - update function
176732d2bbc9SMatthew G. Knepley 
176832d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
176932d2bbc9SMatthew G. Knepley 
177032d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
177132d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
177232d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
177332d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
177432d2bbc9SMatthew G. Knepley 
177532d2bbc9SMatthew G. Knepley + dim - the spatial dimension
177632d2bbc9SMatthew G. Knepley . Nf - the number of fields
177732d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
177832d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
177932d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
178032d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
178132d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
178232d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
178332d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
178432d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
178532d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
178632d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
178732d2bbc9SMatthew G. Knepley . t - current time
178832d2bbc9SMatthew G. Knepley . x - coordinates of the current point
178932d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
179032d2bbc9SMatthew G. Knepley 
179132d2bbc9SMatthew G. Knepley   Level: intermediate
179232d2bbc9SMatthew G. Knepley 
179332d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
179432d2bbc9SMatthew G. Knepley @*/
179532d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f,
179632d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
179732d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
179832d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
17993fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
180032d2bbc9SMatthew G. Knepley {
180132d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
180232d2bbc9SMatthew G. Knepley 
180332d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
180432d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
180532d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
180632d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
180732d2bbc9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
180832d2bbc9SMatthew G. Knepley   prob->update[f] = update;
180932d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
181032d2bbc9SMatthew G. Knepley }
181132d2bbc9SMatthew G. Knepley 
18120c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx)
18130c2f2876SMatthew G. Knepley {
18140c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18150c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18160c2f2876SMatthew 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);
18170c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
18180c2f2876SMatthew G. Knepley   *ctx = prob->ctx[f];
18190c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18200c2f2876SMatthew G. Knepley }
18210c2f2876SMatthew G. Knepley 
18220c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx)
18230c2f2876SMatthew G. Knepley {
18240c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
18250c2f2876SMatthew G. Knepley 
18260c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18270c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18280c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
18290c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
18300c2f2876SMatthew G. Knepley   prob->ctx[f] = ctx;
18310c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18320c2f2876SMatthew G. Knepley }
18330c2f2876SMatthew G. Knepley 
1834194d53e6SMatthew G. Knepley /*@C
1835194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
1836194d53e6SMatthew G. Knepley 
1837194d53e6SMatthew G. Knepley   Not collective
1838194d53e6SMatthew G. Knepley 
1839194d53e6SMatthew G. Knepley   Input Parameters:
1840194d53e6SMatthew G. Knepley + prob - The PetscDS
1841194d53e6SMatthew G. Knepley - f    - The test field number
1842194d53e6SMatthew G. Knepley 
1843194d53e6SMatthew G. Knepley   Output Parameters:
1844194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
1845194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1846194d53e6SMatthew G. Knepley 
1847194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1848194d53e6SMatthew G. Knepley 
1849194d53e6SMatthew G. Knepley   \int_\Gamma \phi {\vec f}_0(u, u_t, \nabla u, x, t) \cdot \hat n + \nabla\phi \cdot {\overleftrightarrow f}_1(u, u_t, \nabla u, x, t) \cdot \hat n
1850194d53e6SMatthew G. Knepley 
1851194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1852194d53e6SMatthew G. Knepley 
185330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1854194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1855194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
185630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1857194d53e6SMatthew G. Knepley 
1858194d53e6SMatthew G. Knepley + dim - the spatial dimension
1859194d53e6SMatthew G. Knepley . Nf - the number of fields
1860194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1861194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1862194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1863194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1864194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1865194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1866194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1867194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1868194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1869194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1870194d53e6SMatthew G. Knepley . t - current time
1871194d53e6SMatthew G. Knepley . x - coordinates of the current point
1872194d53e6SMatthew G. Knepley . n - unit normal at the current point
187397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
187497b6e6e8SMatthew G. Knepley . constants - constant parameters
1875194d53e6SMatthew G. Knepley - f0 - output values at the current point
1876194d53e6SMatthew G. Knepley 
1877194d53e6SMatthew G. Knepley   Level: intermediate
1878194d53e6SMatthew G. Knepley 
1879194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
1880194d53e6SMatthew G. Knepley @*/
18812764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f,
188230b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1883194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1884194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
188597b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
188630b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1887194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1888194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
188997b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
18902764a2aaSMatthew G. Knepley {
18912764a2aaSMatthew G. Knepley   PetscFunctionBegin;
18922764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18932764a2aaSMatthew 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);
18942764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];}
18952764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];}
18962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
18972764a2aaSMatthew G. Knepley }
18982764a2aaSMatthew G. Knepley 
1899194d53e6SMatthew G. Knepley /*@C
1900194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
1901194d53e6SMatthew G. Knepley 
1902194d53e6SMatthew G. Knepley   Not collective
1903194d53e6SMatthew G. Knepley 
1904194d53e6SMatthew G. Knepley   Input Parameters:
1905194d53e6SMatthew G. Knepley + prob - The PetscDS
1906194d53e6SMatthew G. Knepley . f    - The test field number
1907194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
1908194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1909194d53e6SMatthew G. Knepley 
1910194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1911194d53e6SMatthew G. Knepley 
1912194d53e6SMatthew G. Knepley   \int_\Gamma \phi {\vec f}_0(u, u_t, \nabla u, x, t) \cdot \hat n + \nabla\phi \cdot {\overleftrightarrow f}_1(u, u_t, \nabla u, x, t) \cdot \hat n
1913194d53e6SMatthew G. Knepley 
1914194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1915194d53e6SMatthew G. Knepley 
191630b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1917194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1918194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
191930b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1920194d53e6SMatthew G. Knepley 
1921194d53e6SMatthew G. Knepley + dim - the spatial dimension
1922194d53e6SMatthew G. Knepley . Nf - the number of fields
1923194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1924194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1925194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1926194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1927194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1928194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1929194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1930194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1931194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1932194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1933194d53e6SMatthew G. Knepley . t - current time
1934194d53e6SMatthew G. Knepley . x - coordinates of the current point
1935194d53e6SMatthew G. Knepley . n - unit normal at the current point
193697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
193797b6e6e8SMatthew G. Knepley . constants - constant parameters
1938194d53e6SMatthew G. Knepley - f0 - output values at the current point
1939194d53e6SMatthew G. Knepley 
1940194d53e6SMatthew G. Knepley   Level: intermediate
1941194d53e6SMatthew G. Knepley 
1942194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
1943194d53e6SMatthew G. Knepley @*/
19442764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f,
194530b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1946194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1947194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194897b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
194930b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1950194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1951194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
195297b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
19532764a2aaSMatthew G. Knepley {
19542764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
19552764a2aaSMatthew G. Knepley 
19562764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19572764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19582764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19592764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
19602764a2aaSMatthew G. Knepley   if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;}
19612764a2aaSMatthew G. Knepley   if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;}
19622764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
19632764a2aaSMatthew G. Knepley }
19642764a2aaSMatthew G. Knepley 
1965194d53e6SMatthew G. Knepley /*@C
1966194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
1967194d53e6SMatthew G. Knepley 
1968194d53e6SMatthew G. Knepley   Not collective
1969194d53e6SMatthew G. Knepley 
1970194d53e6SMatthew G. Knepley   Input Parameters:
1971194d53e6SMatthew G. Knepley + prob - The PetscDS
1972194d53e6SMatthew G. Knepley . f    - The test field number
1973194d53e6SMatthew G. Knepley - g    - The field number
1974194d53e6SMatthew G. Knepley 
1975194d53e6SMatthew G. Knepley   Output Parameters:
1976194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1977194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1978194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1979194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1980194d53e6SMatthew G. Knepley 
1981194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1982194d53e6SMatthew G. Knepley 
1983194d53e6SMatthew G. Knepley   \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi
1984194d53e6SMatthew G. Knepley 
1985194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1986194d53e6SMatthew G. Knepley 
198730b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1988194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1989194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
199030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
1991194d53e6SMatthew G. Knepley 
1992194d53e6SMatthew G. Knepley + dim - the spatial dimension
1993194d53e6SMatthew G. Knepley . Nf - the number of fields
1994194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1995194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1996194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1997194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1998194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1999194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2000194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2001194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2002194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2003194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2004194d53e6SMatthew G. Knepley . t - current time
20052aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2006194d53e6SMatthew G. Knepley . x - coordinates of the current point
2007194d53e6SMatthew G. Knepley . n - normal at the current point
200897b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
200997b6e6e8SMatthew G. Knepley . constants - constant parameters
2010194d53e6SMatthew G. Knepley - g0 - output values at the current point
2011194d53e6SMatthew G. Knepley 
2012194d53e6SMatthew G. Knepley   Level: intermediate
2013194d53e6SMatthew G. Knepley 
2014194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2015194d53e6SMatthew G. Knepley @*/
20162764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
201730b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2018194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2019194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
202097b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
202130b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2022194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2023194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
202497b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
202530b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2026194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2027194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
202897b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
202930b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2030194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2031194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
203297b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
20332764a2aaSMatthew G. Knepley {
20342764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20352764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20362764a2aaSMatthew 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);
20372764a2aaSMatthew 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);
20382764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];}
20392764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];}
20402764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];}
20412764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];}
20422764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20432764a2aaSMatthew G. Knepley }
20442764a2aaSMatthew G. Knepley 
2045194d53e6SMatthew G. Knepley /*@C
2046194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2047194d53e6SMatthew G. Knepley 
2048194d53e6SMatthew G. Knepley   Not collective
2049194d53e6SMatthew G. Knepley 
2050194d53e6SMatthew G. Knepley   Input Parameters:
2051194d53e6SMatthew G. Knepley + prob - The PetscDS
2052194d53e6SMatthew G. Knepley . f    - The test field number
2053194d53e6SMatthew G. Knepley . g    - The field number
2054194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2055194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2056194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2057194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2058194d53e6SMatthew G. Knepley 
2059194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2060194d53e6SMatthew G. Knepley 
2061194d53e6SMatthew G. Knepley   \int_\Gamma \phi {\vec g}_0(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \phi {\vec g}_1(u, u_t, \nabla u, x, t) \cdot \hat n \nabla \psi + \nabla\phi \cdot {\vec g}_2(u, u_t, \nabla u, x, t) \cdot \hat n \psi + \nabla\phi \cdot {\overleftrightarrow g}_3(u, u_t, \nabla u, x, t) \cdot \hat n \cdot \nabla \psi
2062194d53e6SMatthew G. Knepley 
2063194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2064194d53e6SMatthew G. Knepley 
206530b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2066194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2067194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
206830b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2069194d53e6SMatthew G. Knepley 
2070194d53e6SMatthew G. Knepley + dim - the spatial dimension
2071194d53e6SMatthew G. Knepley . Nf - the number of fields
2072194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2073194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2074194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2075194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2076194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2077194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2078194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2079194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2080194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2081194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2082194d53e6SMatthew G. Knepley . t - current time
20832aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2084194d53e6SMatthew G. Knepley . x - coordinates of the current point
2085194d53e6SMatthew G. Knepley . n - normal at the current point
208697b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
208797b6e6e8SMatthew G. Knepley . constants - constant parameters
2088194d53e6SMatthew G. Knepley - g0 - output values at the current point
2089194d53e6SMatthew G. Knepley 
2090194d53e6SMatthew G. Knepley   Level: intermediate
2091194d53e6SMatthew G. Knepley 
2092194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2093194d53e6SMatthew G. Knepley @*/
20942764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
209530b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2096194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2097194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
209897b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
209930b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2100194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2101194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
210297b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
210330b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2104194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2105194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
210697b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
210730b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2108194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2109194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
211097b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
21112764a2aaSMatthew G. Knepley {
21122764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21132764a2aaSMatthew G. Knepley 
21142764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21152764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21162764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
21172764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
21182764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
21192764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
21202764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21212764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
21222764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
21232764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+0] = g0;
21242764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+1] = g1;
21252764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+2] = g2;
21262764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+3] = g3;
21272764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21282764a2aaSMatthew G. Knepley }
21292764a2aaSMatthew G. Knepley 
21300d3e9b51SMatthew G. Knepley /*@C
2131c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2132c371a6d1SMatthew G. Knepley 
2133c371a6d1SMatthew G. Knepley   Not collective
2134c371a6d1SMatthew G. Knepley 
2135c371a6d1SMatthew G. Knepley   Input Parameters:
2136c371a6d1SMatthew G. Knepley + prob - The PetscDS
2137c371a6d1SMatthew G. Knepley - f    - The test field number
2138c371a6d1SMatthew G. Knepley 
2139c371a6d1SMatthew G. Knepley   Output Parameter:
2140c371a6d1SMatthew G. Knepley . exactSol - exact solution for the test field
2141c371a6d1SMatthew G. Knepley 
2142c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2143c371a6d1SMatthew G. Knepley 
2144c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2145c371a6d1SMatthew G. Knepley 
2146c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2147c371a6d1SMatthew G. Knepley . t - current time
2148c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2149c371a6d1SMatthew G. Knepley . Nc - the number of field components
2150c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2151c371a6d1SMatthew G. Knepley - ctx - a user context
2152c371a6d1SMatthew G. Knepley 
2153c371a6d1SMatthew G. Knepley   Level: intermediate
2154c371a6d1SMatthew G. Knepley 
2155c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution()
2156c371a6d1SMatthew G. Knepley @*/
2157c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2158c371a6d1SMatthew G. Knepley {
2159c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2160c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2161c371a6d1SMatthew 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);
2162c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
2163c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2164c371a6d1SMatthew G. Knepley }
2165c371a6d1SMatthew G. Knepley 
2166c371a6d1SMatthew G. Knepley /*@C
2167c371a6d1SMatthew G. Knepley   PetscDSSetExactSolution - Get the pointwise exact solution function for a given test field
2168c371a6d1SMatthew G. Knepley 
2169c371a6d1SMatthew G. Knepley   Not collective
2170c371a6d1SMatthew G. Knepley 
2171c371a6d1SMatthew G. Knepley   Input Parameters:
2172c371a6d1SMatthew G. Knepley + prob - The PetscDS
2173c371a6d1SMatthew G. Knepley . f    - The test field number
2174c371a6d1SMatthew G. Knepley - sol  - solution function for the test fields
2175c371a6d1SMatthew G. Knepley 
2176c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2177c371a6d1SMatthew G. Knepley 
2178c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2179c371a6d1SMatthew G. Knepley 
2180c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2181c371a6d1SMatthew G. Knepley . t - current time
2182c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2183c371a6d1SMatthew G. Knepley . Nc - the number of field components
2184c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2185c371a6d1SMatthew G. Knepley - ctx - a user context
2186c371a6d1SMatthew G. Knepley 
2187c371a6d1SMatthew G. Knepley   Level: intermediate
2188c371a6d1SMatthew G. Knepley 
2189c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2190c371a6d1SMatthew G. Knepley @*/
2191c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2192c371a6d1SMatthew G. Knepley {
2193c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2194c371a6d1SMatthew G. Knepley 
2195c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2196c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2197c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2198c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2199c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
2200c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2201c371a6d1SMatthew G. Knepley }
2202c371a6d1SMatthew G. Knepley 
22035638fd0eSMatthew G. Knepley /*@C
220497b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
220597b6e6e8SMatthew G. Knepley 
220697b6e6e8SMatthew G. Knepley   Not collective
220797b6e6e8SMatthew G. Knepley 
220897b6e6e8SMatthew G. Knepley   Input Parameter:
220997b6e6e8SMatthew G. Knepley . prob - The PetscDS object
221097b6e6e8SMatthew G. Knepley 
221197b6e6e8SMatthew G. Knepley   Output Parameters:
221297b6e6e8SMatthew G. Knepley + numConstants - The number of constants
221397b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
221497b6e6e8SMatthew G. Knepley 
221597b6e6e8SMatthew G. Knepley   Level: intermediate
221697b6e6e8SMatthew G. Knepley 
221797b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
221897b6e6e8SMatthew G. Knepley @*/
221997b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
222097b6e6e8SMatthew G. Knepley {
222197b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
222297b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
222397b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
222497b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
222597b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
222697b6e6e8SMatthew G. Knepley }
222797b6e6e8SMatthew G. Knepley 
22280d3e9b51SMatthew G. Knepley /*@C
222997b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
223097b6e6e8SMatthew G. Knepley 
223197b6e6e8SMatthew G. Knepley   Not collective
223297b6e6e8SMatthew G. Knepley 
223397b6e6e8SMatthew G. Knepley   Input Parameters:
223497b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
223597b6e6e8SMatthew G. Knepley . numConstants - The number of constants
223697b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
223797b6e6e8SMatthew G. Knepley 
223897b6e6e8SMatthew G. Knepley   Level: intermediate
223997b6e6e8SMatthew G. Knepley 
224097b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
224197b6e6e8SMatthew G. Knepley @*/
224297b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
224397b6e6e8SMatthew G. Knepley {
224497b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
224597b6e6e8SMatthew G. Knepley 
224697b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
224797b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
224897b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
224997b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
225097b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
225197b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
225297b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
225320be0f5bSMatthew G. Knepley     } else {
225420be0f5bSMatthew G. Knepley       prob->constants = NULL;
225520be0f5bSMatthew G. Knepley     }
225620be0f5bSMatthew G. Knepley   }
225720be0f5bSMatthew G. Knepley   if (prob->numConstants) {
225820be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
225997b6e6e8SMatthew G. Knepley     ierr = PetscMemcpy(prob->constants, constants, prob->numConstants * sizeof(PetscScalar));CHKERRQ(ierr);
226097b6e6e8SMatthew G. Knepley   }
226197b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
226297b6e6e8SMatthew G. Knepley }
226397b6e6e8SMatthew G. Knepley 
22644cd1e086SMatthew G. Knepley /*@
22654cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
22664cd1e086SMatthew G. Knepley 
22674cd1e086SMatthew G. Knepley   Not collective
22684cd1e086SMatthew G. Knepley 
22694cd1e086SMatthew G. Knepley   Input Parameters:
22704cd1e086SMatthew G. Knepley + prob - The PetscDS object
22714cd1e086SMatthew G. Knepley - disc - The discretization object
22724cd1e086SMatthew G. Knepley 
22734cd1e086SMatthew G. Knepley   Output Parameter:
22744cd1e086SMatthew G. Knepley . f - The field number
22754cd1e086SMatthew G. Knepley 
22764cd1e086SMatthew G. Knepley   Level: beginner
22774cd1e086SMatthew G. Knepley 
2278f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
22794cd1e086SMatthew G. Knepley @*/
22804cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
22814cd1e086SMatthew G. Knepley {
22824cd1e086SMatthew G. Knepley   PetscInt g;
22834cd1e086SMatthew G. Knepley 
22844cd1e086SMatthew G. Knepley   PetscFunctionBegin;
22854cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
22864cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
22874cd1e086SMatthew G. Knepley   *f = -1;
22884cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
22894cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
22904cd1e086SMatthew G. Knepley   *f = g;
22914cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
22924cd1e086SMatthew G. Knepley }
22934cd1e086SMatthew G. Knepley 
22944cd1e086SMatthew G. Knepley /*@
22954cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
22964cd1e086SMatthew G. Knepley 
22974cd1e086SMatthew G. Knepley   Not collective
22984cd1e086SMatthew G. Knepley 
22994cd1e086SMatthew G. Knepley   Input Parameters:
23004cd1e086SMatthew G. Knepley + prob - The PetscDS object
23014cd1e086SMatthew G. Knepley - f - The field number
23024cd1e086SMatthew G. Knepley 
23034cd1e086SMatthew G. Knepley   Output Parameter:
23044cd1e086SMatthew G. Knepley . size - The size
23054cd1e086SMatthew G. Knepley 
23064cd1e086SMatthew G. Knepley   Level: beginner
23074cd1e086SMatthew G. Knepley 
2308f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
23094cd1e086SMatthew G. Knepley @*/
23104cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
23114cd1e086SMatthew G. Knepley {
23122166fd64SMatthew G. Knepley   PetscErrorCode ierr;
23132166fd64SMatthew G. Knepley 
23144cd1e086SMatthew G. Knepley   PetscFunctionBegin;
23154cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23164cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
23174cd1e086SMatthew 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);
23182166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2319d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
23204cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
23214cd1e086SMatthew G. Knepley }
23224cd1e086SMatthew G. Knepley 
2323bc4ae4beSMatthew G. Knepley /*@
2324bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2325bc4ae4beSMatthew G. Knepley 
2326bc4ae4beSMatthew G. Knepley   Not collective
2327bc4ae4beSMatthew G. Knepley 
2328bc4ae4beSMatthew G. Knepley   Input Parameters:
2329bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2330bc4ae4beSMatthew G. Knepley - f - The field number
2331bc4ae4beSMatthew G. Knepley 
2332bc4ae4beSMatthew G. Knepley   Output Parameter:
2333bc4ae4beSMatthew G. Knepley . off - The offset
2334bc4ae4beSMatthew G. Knepley 
2335bc4ae4beSMatthew G. Knepley   Level: beginner
2336bc4ae4beSMatthew G. Knepley 
2337f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2338bc4ae4beSMatthew G. Knepley @*/
23392764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
23402764a2aaSMatthew G. Knepley {
23414cd1e086SMatthew G. Knepley   PetscInt       size, g;
23422764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23432764a2aaSMatthew G. Knepley 
23442764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23452764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23462764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
23472764a2aaSMatthew 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);
23482764a2aaSMatthew G. Knepley   *off = 0;
23492764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
23504cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
23514cd1e086SMatthew G. Knepley     *off += size;
23522764a2aaSMatthew G. Knepley   }
23532764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23542764a2aaSMatthew G. Knepley }
23552764a2aaSMatthew G. Knepley 
2356bc4ae4beSMatthew G. Knepley /*@
235747e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2358bc4ae4beSMatthew G. Knepley 
2359bc4ae4beSMatthew G. Knepley   Not collective
2360bc4ae4beSMatthew G. Knepley 
236147e57110SSander Arens   Input Parameter:
236247e57110SSander Arens . prob - The PetscDS object
2363bc4ae4beSMatthew G. Knepley 
2364bc4ae4beSMatthew G. Knepley   Output Parameter:
236547e57110SSander Arens . dimensions - The number of dimensions
2366bc4ae4beSMatthew G. Knepley 
2367bc4ae4beSMatthew G. Knepley   Level: beginner
2368bc4ae4beSMatthew G. Knepley 
236947e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2370bc4ae4beSMatthew G. Knepley @*/
237147e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
23722764a2aaSMatthew G. Knepley {
23732764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23742764a2aaSMatthew G. Knepley 
23752764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23762764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
237747e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
237847e57110SSander Arens   PetscValidPointer(dimensions, 2);
237947e57110SSander Arens   *dimensions = prob->Nb;
238047e57110SSander Arens   PetscFunctionReturn(0);
23816ce16762SMatthew G. Knepley }
238247e57110SSander Arens 
238347e57110SSander Arens /*@
238447e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
238547e57110SSander Arens 
238647e57110SSander Arens   Not collective
238747e57110SSander Arens 
238847e57110SSander Arens   Input Parameter:
238947e57110SSander Arens . prob - The PetscDS object
239047e57110SSander Arens 
239147e57110SSander Arens   Output Parameter:
239247e57110SSander Arens . components - The number of components
239347e57110SSander Arens 
239447e57110SSander Arens   Level: beginner
239547e57110SSander Arens 
239647e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
239747e57110SSander Arens @*/
239847e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
239947e57110SSander Arens {
240047e57110SSander Arens   PetscErrorCode ierr;
240147e57110SSander Arens 
240247e57110SSander Arens   PetscFunctionBegin;
240347e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
240447e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
240547e57110SSander Arens   PetscValidPointer(components, 2);
240647e57110SSander Arens   *components = prob->Nc;
24076ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
24086ce16762SMatthew G. Knepley }
24096ce16762SMatthew G. Knepley 
24106ce16762SMatthew G. Knepley /*@
24116ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
24126ce16762SMatthew G. Knepley 
24136ce16762SMatthew G. Knepley   Not collective
24146ce16762SMatthew G. Knepley 
24156ce16762SMatthew G. Knepley   Input Parameters:
24166ce16762SMatthew G. Knepley + prob - The PetscDS object
24176ce16762SMatthew G. Knepley - f - The field number
24186ce16762SMatthew G. Knepley 
24196ce16762SMatthew G. Knepley   Output Parameter:
24206ce16762SMatthew G. Knepley . off - The offset
24216ce16762SMatthew G. Knepley 
24226ce16762SMatthew G. Knepley   Level: beginner
24236ce16762SMatthew G. Knepley 
2424f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
24256ce16762SMatthew G. Knepley @*/
24266ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
24276ce16762SMatthew G. Knepley {
24286ce16762SMatthew G. Knepley   PetscFunctionBegin;
24296ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24306ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
24316ce16762SMatthew 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);
243247e57110SSander Arens   *off = prob->off[f];
24332764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
24342764a2aaSMatthew G. Knepley }
24352764a2aaSMatthew G. Knepley 
2436194d53e6SMatthew G. Knepley /*@
2437194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2438194d53e6SMatthew G. Knepley 
2439194d53e6SMatthew G. Knepley   Not collective
2440194d53e6SMatthew G. Knepley 
2441194d53e6SMatthew G. Knepley   Input Parameter:
2442194d53e6SMatthew G. Knepley . prob - The PetscDS object
2443194d53e6SMatthew G. Knepley 
2444194d53e6SMatthew G. Knepley   Output Parameter:
2445194d53e6SMatthew G. Knepley . offsets - The offsets
2446194d53e6SMatthew G. Knepley 
2447194d53e6SMatthew G. Knepley   Level: beginner
2448194d53e6SMatthew G. Knepley 
2449f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2450194d53e6SMatthew G. Knepley @*/
2451194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2452194d53e6SMatthew G. Knepley {
2453194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2454194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2455194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2456194d53e6SMatthew G. Knepley   *offsets = prob->off;
2457194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2458194d53e6SMatthew G. Knepley }
2459194d53e6SMatthew G. Knepley 
2460194d53e6SMatthew G. Knepley /*@
2461194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2462194d53e6SMatthew G. Knepley 
2463194d53e6SMatthew G. Knepley   Not collective
2464194d53e6SMatthew G. Knepley 
2465194d53e6SMatthew G. Knepley   Input Parameter:
2466194d53e6SMatthew G. Knepley . prob - The PetscDS object
2467194d53e6SMatthew G. Knepley 
2468194d53e6SMatthew G. Knepley   Output Parameter:
2469194d53e6SMatthew G. Knepley . offsets - The offsets
2470194d53e6SMatthew G. Knepley 
2471194d53e6SMatthew G. Knepley   Level: beginner
2472194d53e6SMatthew G. Knepley 
2473f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2474194d53e6SMatthew G. Knepley @*/
2475194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2476194d53e6SMatthew G. Knepley {
2477194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2478194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2479194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2480194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
2481194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2482194d53e6SMatthew G. Knepley }
2483194d53e6SMatthew G. Knepley 
248468c9edb9SMatthew G. Knepley /*@C
248568c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
248668c9edb9SMatthew G. Knepley 
248768c9edb9SMatthew G. Knepley   Not collective
248868c9edb9SMatthew G. Knepley 
248968c9edb9SMatthew G. Knepley   Input Parameter:
249068c9edb9SMatthew G. Knepley . prob - The PetscDS object
249168c9edb9SMatthew G. Knepley 
249268c9edb9SMatthew G. Knepley   Output Parameters:
249368c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
249468c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
249568c9edb9SMatthew G. Knepley 
249668c9edb9SMatthew G. Knepley   Level: intermediate
249768c9edb9SMatthew G. Knepley 
2498f744cafaSSander Arens .seealso: PetscDSCreate()
249968c9edb9SMatthew G. Knepley @*/
25002764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
25012764a2aaSMatthew G. Knepley {
25022764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25032764a2aaSMatthew G. Knepley 
25042764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25052764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25062764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25072764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basis;}
25082764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;}
25092764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25102764a2aaSMatthew G. Knepley }
25112764a2aaSMatthew G. Knepley 
251268c9edb9SMatthew G. Knepley /*@C
25134d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
251468c9edb9SMatthew G. Knepley 
251568c9edb9SMatthew G. Knepley   Not collective
251668c9edb9SMatthew G. Knepley 
251768c9edb9SMatthew G. Knepley   Input Parameter:
251868c9edb9SMatthew G. Knepley . prob - The PetscDS object
251968c9edb9SMatthew G. Knepley 
252068c9edb9SMatthew G. Knepley   Output Parameters:
25214d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points
25224d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points
252368c9edb9SMatthew G. Knepley 
252468c9edb9SMatthew G. Knepley   Level: intermediate
252568c9edb9SMatthew G. Knepley 
252668c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
252768c9edb9SMatthew G. Knepley @*/
25284d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
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);
25354d0b9603SSander Arens   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basisFace;}
25364d0b9603SSander Arens   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;}
25372764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25382764a2aaSMatthew G. Knepley }
25392764a2aaSMatthew G. Knepley 
25402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
25412764a2aaSMatthew G. Knepley {
25422764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25432764a2aaSMatthew G. Knepley 
25442764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25452764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25462764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25472764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
25482764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
25492764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
25502764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25512764a2aaSMatthew G. Knepley }
25522764a2aaSMatthew G. Knepley 
25532764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
25542764a2aaSMatthew G. Knepley {
25552764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25562764a2aaSMatthew G. Knepley 
25572764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25582764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25592764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25602764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
25612764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
25622764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
25632764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
25642764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
25652764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
25662764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25672764a2aaSMatthew G. Knepley }
25682764a2aaSMatthew G. Knepley 
25692764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer)
25702764a2aaSMatthew G. Knepley {
25712764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25722764a2aaSMatthew G. Knepley 
25732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25742764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25752764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25762764a2aaSMatthew G. Knepley   if (x)           {PetscValidPointer(x, 2);           *x           = prob->x;}
25772764a2aaSMatthew G. Knepley   if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;}
25782764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25792764a2aaSMatthew G. Knepley }
25802764a2aaSMatthew G. Knepley 
258158ebd649SToby Isaac /*@C
258258ebd649SToby Isaac   PetscDSAddBoundary - Add a boundary condition to the model
258358ebd649SToby Isaac 
258458ebd649SToby Isaac   Input Parameters:
258558ebd649SToby Isaac + ds          - The PetscDS object
25862d47a189SJulian Andrej . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
258758ebd649SToby Isaac . name        - The BC name
258858ebd649SToby Isaac . labelname   - The label defining constrained points
258958ebd649SToby Isaac . field       - The field to constrain
259058ebd649SToby Isaac . numcomps    - The number of constrained field components
259158ebd649SToby Isaac . comps       - An array of constrained component numbers
259258ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
259358ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
259458ebd649SToby Isaac . ids         - An array of ids for constrained points
259558ebd649SToby Isaac - ctx         - An optional user context for bcFunc
259658ebd649SToby Isaac 
259758ebd649SToby Isaac   Options Database Keys:
259858ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
259958ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
260058ebd649SToby Isaac 
260158ebd649SToby Isaac   Level: developer
260258ebd649SToby Isaac 
260358ebd649SToby Isaac .seealso: PetscDSGetBoundary()
260458ebd649SToby Isaac @*/
2605a30ec4eaSSatish 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)
260658ebd649SToby Isaac {
260758ebd649SToby Isaac   DSBoundary     b;
260858ebd649SToby Isaac   PetscErrorCode ierr;
260958ebd649SToby Isaac 
261058ebd649SToby Isaac   PetscFunctionBegin;
261158ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
261258ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
261358ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
261458ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
261558ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
261658ebd649SToby Isaac   if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
261758ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
261858ebd649SToby Isaac   if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
2619f971fd6bSMatthew G. Knepley   b->type            = type;
262058ebd649SToby Isaac   b->field           = field;
262158ebd649SToby Isaac   b->numcomps        = numcomps;
262258ebd649SToby Isaac   b->func            = bcFunc;
262358ebd649SToby Isaac   b->numids          = numids;
262458ebd649SToby Isaac   b->ctx             = ctx;
262558ebd649SToby Isaac   b->next            = ds->boundary;
262658ebd649SToby Isaac   ds->boundary       = b;
262758ebd649SToby Isaac   PetscFunctionReturn(0);
262858ebd649SToby Isaac }
262958ebd649SToby Isaac 
263058ebd649SToby Isaac /*@
263158ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
263258ebd649SToby Isaac 
263358ebd649SToby Isaac   Input Parameters:
263458ebd649SToby Isaac . ds - The PetscDS object
263558ebd649SToby Isaac 
263658ebd649SToby Isaac   Output Parameters:
263758ebd649SToby Isaac . numBd - The number of BC
263858ebd649SToby Isaac 
263958ebd649SToby Isaac   Level: intermediate
264058ebd649SToby Isaac 
264158ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
264258ebd649SToby Isaac @*/
264358ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
264458ebd649SToby Isaac {
264558ebd649SToby Isaac   DSBoundary b = ds->boundary;
264658ebd649SToby Isaac 
264758ebd649SToby Isaac   PetscFunctionBegin;
264858ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
264958ebd649SToby Isaac   PetscValidPointer(numBd, 2);
265058ebd649SToby Isaac   *numBd = 0;
265158ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
265258ebd649SToby Isaac   PetscFunctionReturn(0);
265358ebd649SToby Isaac }
265458ebd649SToby Isaac 
265558ebd649SToby Isaac /*@C
265658ebd649SToby Isaac   PetscDSGetBoundary - Add a boundary condition to the model
265758ebd649SToby Isaac 
265858ebd649SToby Isaac   Input Parameters:
265958ebd649SToby Isaac + ds          - The PetscDS object
266058ebd649SToby Isaac - bd          - The BC number
266158ebd649SToby Isaac 
266258ebd649SToby Isaac   Output Parameters:
26632d47a189SJulian Andrej + type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
266458ebd649SToby Isaac . name        - The BC name
266558ebd649SToby Isaac . labelname   - The label defining constrained points
266658ebd649SToby Isaac . field       - The field to constrain
266758ebd649SToby Isaac . numcomps    - The number of constrained field components
266858ebd649SToby Isaac . comps       - An array of constrained component numbers
266958ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
267058ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
267158ebd649SToby Isaac . ids         - An array of ids for constrained points
267258ebd649SToby Isaac - ctx         - An optional user context for bcFunc
267358ebd649SToby Isaac 
267458ebd649SToby Isaac   Options Database Keys:
267558ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
267658ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
267758ebd649SToby Isaac 
267858ebd649SToby Isaac   Level: developer
267958ebd649SToby Isaac 
268058ebd649SToby Isaac .seealso: PetscDSAddBoundary()
268158ebd649SToby Isaac @*/
2682a30ec4eaSSatish 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)
268358ebd649SToby Isaac {
268458ebd649SToby Isaac   DSBoundary b    = ds->boundary;
268558ebd649SToby Isaac   PetscInt   n    = 0;
268658ebd649SToby Isaac 
268758ebd649SToby Isaac   PetscFunctionBegin;
268858ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
268958ebd649SToby Isaac   while (b) {
269058ebd649SToby Isaac     if (n == bd) break;
269158ebd649SToby Isaac     b = b->next;
269258ebd649SToby Isaac     ++n;
269358ebd649SToby Isaac   }
269458ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
2695f971fd6bSMatthew G. Knepley   if (type) {
2696f971fd6bSMatthew G. Knepley     PetscValidPointer(type, 3);
2697f971fd6bSMatthew G. Knepley     *type = b->type;
269858ebd649SToby Isaac   }
269958ebd649SToby Isaac   if (name) {
270058ebd649SToby Isaac     PetscValidPointer(name, 4);
270158ebd649SToby Isaac     *name = b->name;
270258ebd649SToby Isaac   }
270358ebd649SToby Isaac   if (labelname) {
270458ebd649SToby Isaac     PetscValidPointer(labelname, 5);
270558ebd649SToby Isaac     *labelname = b->labelname;
270658ebd649SToby Isaac   }
270758ebd649SToby Isaac   if (field) {
270858ebd649SToby Isaac     PetscValidPointer(field, 6);
270958ebd649SToby Isaac     *field = b->field;
271058ebd649SToby Isaac   }
271158ebd649SToby Isaac   if (numcomps) {
271258ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
271358ebd649SToby Isaac     *numcomps = b->numcomps;
271458ebd649SToby Isaac   }
271558ebd649SToby Isaac   if (comps) {
271658ebd649SToby Isaac     PetscValidPointer(comps, 8);
271758ebd649SToby Isaac     *comps = b->comps;
271858ebd649SToby Isaac   }
271958ebd649SToby Isaac   if (func) {
272058ebd649SToby Isaac     PetscValidPointer(func, 9);
272158ebd649SToby Isaac     *func = b->func;
272258ebd649SToby Isaac   }
272358ebd649SToby Isaac   if (numids) {
272458ebd649SToby Isaac     PetscValidPointer(numids, 10);
272558ebd649SToby Isaac     *numids = b->numids;
272658ebd649SToby Isaac   }
272758ebd649SToby Isaac   if (ids) {
272858ebd649SToby Isaac     PetscValidPointer(ids, 11);
272958ebd649SToby Isaac     *ids = b->ids;
273058ebd649SToby Isaac   }
273158ebd649SToby Isaac   if (ctx) {
273258ebd649SToby Isaac     PetscValidPointer(ctx, 12);
273358ebd649SToby Isaac     *ctx = b->ctx;
273458ebd649SToby Isaac   }
273558ebd649SToby Isaac   PetscFunctionReturn(0);
273658ebd649SToby Isaac }
273758ebd649SToby Isaac 
2738dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB)
2739dff059c6SToby Isaac {
2740dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
2741dff059c6SToby Isaac   PetscErrorCode ierr;
2742dff059c6SToby Isaac 
2743dff059c6SToby Isaac   PetscFunctionBegin;
2744dff059c6SToby Isaac   PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1);
2745dff059c6SToby Isaac   PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2);
2746dff059c6SToby Isaac   if (probA == probB) PetscFunctionReturn(0);
2747dff059c6SToby Isaac   next = probB->boundary;
2748dff059c6SToby Isaac   while (next) {
2749dff059c6SToby Isaac     DSBoundary b = next;
2750dff059c6SToby Isaac 
2751dff059c6SToby Isaac     next = b->next;
2752dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2753dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2754dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
2755dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2756dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
2757dff059c6SToby Isaac   }
2758dff059c6SToby Isaac   lastnext = &(probB->boundary);
2759dff059c6SToby Isaac   for (b = probA->boundary; b; b = b->next) {
2760dff059c6SToby Isaac     DSBoundary bNew;
2761dff059c6SToby Isaac 
2762459726d8SSatish Balay     ierr = PetscNew(&bNew);CHKERRQ(ierr);
2763dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
2764dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
2765dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr);
2766dff059c6SToby Isaac     bNew->numids = b->numids;
2767dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
2768dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr);
2769dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
2770dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
2771dff059c6SToby Isaac     bNew->ctx   = b->ctx;
2772f971fd6bSMatthew G. Knepley     bNew->type  = b->type;
2773dff059c6SToby Isaac     bNew->field = b->field;
2774dff059c6SToby Isaac     bNew->func  = b->func;
2775dff059c6SToby Isaac 
2776dff059c6SToby Isaac     *lastnext = bNew;
2777dff059c6SToby Isaac     lastnext = &(bNew->next);
2778dff059c6SToby Isaac   }
2779dff059c6SToby Isaac   PetscFunctionReturn(0);
2780dff059c6SToby Isaac }
2781dff059c6SToby Isaac 
2782da51fcedSMatthew G. Knepley /*@
2783da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
2784da51fcedSMatthew G. Knepley 
2785da51fcedSMatthew G. Knepley   Not collective
2786da51fcedSMatthew G. Knepley 
2787da51fcedSMatthew G. Knepley   Input Parameter:
2788da51fcedSMatthew G. Knepley . prob - The PetscDS object
2789da51fcedSMatthew G. Knepley 
2790da51fcedSMatthew G. Knepley   Output Parameter:
2791da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
2792da51fcedSMatthew G. Knepley 
2793da51fcedSMatthew G. Knepley   Level: intermediate
2794da51fcedSMatthew G. Knepley 
2795da51fcedSMatthew G. Knepley .seealso: PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
2796da51fcedSMatthew G. Knepley @*/
2797da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
2798da51fcedSMatthew G. Knepley {
2799da51fcedSMatthew G. Knepley   PetscInt       Nf, Ng, f, g;
2800da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
2801da51fcedSMatthew G. Knepley 
2802da51fcedSMatthew G. Knepley   PetscFunctionBegin;
2803da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2804da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
2805da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
2806da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
280713903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
2808da51fcedSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
2809da51fcedSMatthew G. Knepley     PetscPointFunc   obj;
2810da51fcedSMatthew G. Knepley     PetscPointFunc   f0, f1;
2811da51fcedSMatthew G. Knepley     PetscPointJac    g0, g1, g2, g3;
2812da51fcedSMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
2813da51fcedSMatthew G. Knepley     PetscBdPointJac  g0Bd, g1Bd, g2Bd, g3Bd;
2814da51fcedSMatthew G. Knepley     PetscRiemannFunc r;
2815da51fcedSMatthew G. Knepley 
2816da51fcedSMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
2817da51fcedSMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
2818da51fcedSMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
2819da51fcedSMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
2820da51fcedSMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, f, obj);CHKERRQ(ierr);
2821da51fcedSMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, f, f0, f1);CHKERRQ(ierr);
2822da51fcedSMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, f, f0Bd, f1Bd);CHKERRQ(ierr);
2823da51fcedSMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, f, r);CHKERRQ(ierr);
2824da51fcedSMatthew G. Knepley     for (g = 0; g < Nf; ++g) {
2825da51fcedSMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
2826da51fcedSMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
2827da51fcedSMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, f, g, g0, g1, g2, g3);CHKERRQ(ierr);
2828da51fcedSMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, f, g, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
2829da51fcedSMatthew G. Knepley     }
2830da51fcedSMatthew G. Knepley   }
2831da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
2832da51fcedSMatthew G. Knepley }
2833da51fcedSMatthew G. Knepley 
2834b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
2835b1353e8eSMatthew G. Knepley {
2836*df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
2837b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
2838b1353e8eSMatthew G. Knepley 
2839b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
2840b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2841b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
2842b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
2843b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
2844*df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
2845*df3a45bdSMatthew G. Knepley   if (height > dim) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_OUTOFRANGE, "DS can only handle height in [0, %D], not %D", dim, height);
2846*df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
2847*df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
2848b1353e8eSMatthew G. Knepley     PetscInt cdim;
2849b1353e8eSMatthew G. Knepley 
2850*df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
2851b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
2852*df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
2853b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
2854b1353e8eSMatthew G. Knepley       PetscFE      subfe;
2855b1353e8eSMatthew G. Knepley       PetscObject  obj;
2856b1353e8eSMatthew G. Knepley       PetscClassId id;
2857b1353e8eSMatthew G. Knepley 
2858b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
2859b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
2860b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
2861b1353e8eSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
2862*df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
2863b1353e8eSMatthew G. Knepley     }
2864b1353e8eSMatthew G. Knepley   }
2865*df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
2866b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
2867b1353e8eSMatthew G. Knepley }
2868b1353e8eSMatthew G. Knepley 
2869bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob)
28702764a2aaSMatthew G. Knepley {
2871931fb3b8SToby Isaac   PetscErrorCode      ierr;
2872931fb3b8SToby Isaac 
28732764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2874931fb3b8SToby Isaac   ierr = PetscFree(prob->data);CHKERRQ(ierr);
28752764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28762764a2aaSMatthew G. Knepley }
28772764a2aaSMatthew G. Knepley 
2878bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob)
28792764a2aaSMatthew G. Knepley {
28802764a2aaSMatthew G. Knepley   PetscFunctionBegin;
28812764a2aaSMatthew G. Knepley   prob->ops->setfromoptions = NULL;
28822764a2aaSMatthew G. Knepley   prob->ops->setup          = NULL;
28832764a2aaSMatthew G. Knepley   prob->ops->view           = NULL;
28842764a2aaSMatthew G. Knepley   prob->ops->destroy        = PetscDSDestroy_Basic;
28852764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
28862764a2aaSMatthew G. Knepley }
28872764a2aaSMatthew G. Knepley 
28882764a2aaSMatthew G. Knepley /*MC
28892764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
28902764a2aaSMatthew G. Knepley 
28912764a2aaSMatthew G. Knepley   Level: intermediate
28922764a2aaSMatthew G. Knepley 
28932764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
28942764a2aaSMatthew G. Knepley M*/
28952764a2aaSMatthew G. Knepley 
28962764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob)
28972764a2aaSMatthew G. Knepley {
28982764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
28992764a2aaSMatthew G. Knepley   PetscErrorCode      ierr;
29002764a2aaSMatthew G. Knepley 
29012764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2902931fb3b8SToby Isaac   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29032764a2aaSMatthew G. Knepley   ierr       = PetscNewLog(prob, &b);CHKERRQ(ierr);
29042764a2aaSMatthew G. Knepley   prob->data = b;
29052764a2aaSMatthew G. Knepley 
29062764a2aaSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr);
29072764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29082764a2aaSMatthew G. Knepley }
2909