xref: /petsc/src/dm/dt/interface/dtds.c (revision 3e60c2a609065628e269554425bb039deb887ac4)
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 
37f5f57ec0SBarry Smith    Not available from Fortran
38f5f57ec0SBarry Smith 
392764a2aaSMatthew G. Knepley .keywords: PetscDS, register
402764a2aaSMatthew G. Knepley .seealso: PetscDSRegisterAll(), PetscDSRegisterDestroy()
412764a2aaSMatthew G. Knepley 
422764a2aaSMatthew G. Knepley @*/
432764a2aaSMatthew G. Knepley PetscErrorCode PetscDSRegister(const char sname[], PetscErrorCode (*function)(PetscDS))
442764a2aaSMatthew G. Knepley {
452764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
462764a2aaSMatthew G. Knepley 
472764a2aaSMatthew G. Knepley   PetscFunctionBegin;
482764a2aaSMatthew G. Knepley   ierr = PetscFunctionListAdd(&PetscDSList, sname, function);CHKERRQ(ierr);
492764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
502764a2aaSMatthew G. Knepley }
512764a2aaSMatthew G. Knepley 
522764a2aaSMatthew G. Knepley /*@C
532764a2aaSMatthew G. Knepley   PetscDSSetType - Builds a particular PetscDS
542764a2aaSMatthew G. Knepley 
552764a2aaSMatthew G. Knepley   Collective on PetscDS
562764a2aaSMatthew G. Knepley 
572764a2aaSMatthew G. Knepley   Input Parameters:
582764a2aaSMatthew G. Knepley + prob - The PetscDS object
592764a2aaSMatthew G. Knepley - name - The kind of system
602764a2aaSMatthew G. Knepley 
612764a2aaSMatthew G. Knepley   Options Database Key:
622764a2aaSMatthew G. Knepley . -petscds_type <type> - Sets the PetscDS type; use -help for a list of available types
632764a2aaSMatthew G. Knepley 
642764a2aaSMatthew G. Knepley   Level: intermediate
652764a2aaSMatthew G. Knepley 
66f5f57ec0SBarry Smith    Not available from Fortran
67f5f57ec0SBarry Smith 
682764a2aaSMatthew G. Knepley .keywords: PetscDS, set, type
692764a2aaSMatthew G. Knepley .seealso: PetscDSGetType(), PetscDSCreate()
702764a2aaSMatthew G. Knepley @*/
712764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetType(PetscDS prob, PetscDSType name)
722764a2aaSMatthew G. Knepley {
732764a2aaSMatthew G. Knepley   PetscErrorCode (*r)(PetscDS);
742764a2aaSMatthew G. Knepley   PetscBool      match;
752764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
762764a2aaSMatthew G. Knepley 
772764a2aaSMatthew G. Knepley   PetscFunctionBegin;
782764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
792764a2aaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) prob, name, &match);CHKERRQ(ierr);
802764a2aaSMatthew G. Knepley   if (match) PetscFunctionReturn(0);
812764a2aaSMatthew G. Knepley 
820f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
832764a2aaSMatthew G. Knepley   ierr = PetscFunctionListFind(PetscDSList, name, &r);CHKERRQ(ierr);
842764a2aaSMatthew G. Knepley   if (!r) SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown PetscDS type: %s", name);
852764a2aaSMatthew G. Knepley 
862764a2aaSMatthew G. Knepley   if (prob->ops->destroy) {
872764a2aaSMatthew G. Knepley     ierr             = (*prob->ops->destroy)(prob);CHKERRQ(ierr);
882764a2aaSMatthew G. Knepley     prob->ops->destroy = NULL;
892764a2aaSMatthew G. Knepley   }
902764a2aaSMatthew G. Knepley   ierr = (*r)(prob);CHKERRQ(ierr);
912764a2aaSMatthew G. Knepley   ierr = PetscObjectChangeTypeName((PetscObject) prob, name);CHKERRQ(ierr);
922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
932764a2aaSMatthew G. Knepley }
942764a2aaSMatthew G. Knepley 
952764a2aaSMatthew G. Knepley /*@C
962764a2aaSMatthew G. Knepley   PetscDSGetType - Gets the PetscDS type name (as a string) from the object.
972764a2aaSMatthew G. Knepley 
982764a2aaSMatthew G. Knepley   Not Collective
992764a2aaSMatthew G. Knepley 
1002764a2aaSMatthew G. Knepley   Input Parameter:
1012764a2aaSMatthew G. Knepley . prob  - The PetscDS
1022764a2aaSMatthew G. Knepley 
1032764a2aaSMatthew G. Knepley   Output Parameter:
1042764a2aaSMatthew G. Knepley . name - The PetscDS type name
1052764a2aaSMatthew G. Knepley 
1062764a2aaSMatthew G. Knepley   Level: intermediate
1072764a2aaSMatthew G. Knepley 
108f5f57ec0SBarry Smith    Not available from Fortran
109f5f57ec0SBarry Smith 
1102764a2aaSMatthew G. Knepley .keywords: PetscDS, get, type, name
1112764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PetscDSCreate()
1122764a2aaSMatthew G. Knepley @*/
1132764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetType(PetscDS prob, PetscDSType *name)
1142764a2aaSMatthew G. Knepley {
1152764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
1162764a2aaSMatthew G. Knepley 
1172764a2aaSMatthew G. Knepley   PetscFunctionBegin;
1182764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
119c959eef4SJed Brown   PetscValidPointer(name, 2);
1200f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
1212764a2aaSMatthew G. Knepley   *name = ((PetscObject) prob)->type_name;
1222764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
1232764a2aaSMatthew G. Knepley }
1242764a2aaSMatthew G. Knepley 
1257d8a60eaSMatthew G. Knepley static PetscErrorCode PetscDSView_Ascii(PetscDS prob, PetscViewer viewer)
1267d8a60eaSMatthew G. Knepley {
1277d8a60eaSMatthew G. Knepley   PetscViewerFormat  format;
12897b6e6e8SMatthew G. Knepley   const PetscScalar *constants;
12997b6e6e8SMatthew G. Knepley   PetscInt           numConstants, f;
1307d8a60eaSMatthew G. Knepley   PetscErrorCode     ierr;
1317d8a60eaSMatthew G. Knepley 
1327d8a60eaSMatthew G. Knepley   PetscFunctionBegin;
1337d8a60eaSMatthew G. Knepley   ierr = PetscViewerGetFormat(viewer, &format);CHKERRQ(ierr);
1347d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPrintf(viewer, "Discrete System with %d fields\n", prob->Nf);CHKERRQ(ierr);
1357d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1367d8a60eaSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1377d8a60eaSMatthew G. Knepley     PetscObject     obj;
1387d8a60eaSMatthew G. Knepley     PetscClassId    id;
139f35450b9SMatthew G. Knepley     PetscQuadrature q;
1407d8a60eaSMatthew G. Knepley     const char     *name;
141f35450b9SMatthew G. Knepley     PetscInt        Nc, Nq, Nqc;
1427d8a60eaSMatthew G. Knepley 
1437d8a60eaSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
1447d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
1457d8a60eaSMatthew G. Knepley     ierr = PetscObjectGetName(obj, &name);CHKERRQ(ierr);
1467d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "Field %s", name ? name : "<unknown>");CHKERRQ(ierr);
1477d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
1487d8a60eaSMatthew G. Knepley       ierr = PetscFEGetNumComponents((PetscFE) obj, &Nc);CHKERRQ(ierr);
149f35450b9SMatthew G. Knepley       ierr = PetscFEGetQuadrature((PetscFE) obj, &q);CHKERRQ(ierr);
1507d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FEM");CHKERRQ(ierr);
1517d8a60eaSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
1527d8a60eaSMatthew G. Knepley       ierr = PetscFVGetNumComponents((PetscFV) obj, &Nc);CHKERRQ(ierr);
153f35450b9SMatthew G. Knepley       ierr = PetscFVGetQuadrature((PetscFV) obj, &q);CHKERRQ(ierr);
1547d8a60eaSMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " FVM");CHKERRQ(ierr);
1557d8a60eaSMatthew G. Knepley     }
15697b6e6e8SMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %D", f);
15797b6e6e8SMatthew G. Knepley     if (Nc > 1) {ierr = PetscViewerASCIIPrintf(viewer, "%D components", Nc);CHKERRQ(ierr);}
15897b6e6e8SMatthew G. Knepley     else        {ierr = PetscViewerASCIIPrintf(viewer, "%D component ", Nc);CHKERRQ(ierr);}
159249df284SMatthew G. Knepley     if (prob->implicit[f]) {ierr = PetscViewerASCIIPrintf(viewer, " (implicit)");CHKERRQ(ierr);}
160249df284SMatthew G. Knepley     else                   {ierr = PetscViewerASCIIPrintf(viewer, " (explicit)");CHKERRQ(ierr);}
161a6cbbb48SMatthew G. Knepley     if (prob->adjacency[f*2+0]) {
162a6cbbb48SMatthew G. Knepley       if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM++)");CHKERRQ(ierr);}
163a6cbbb48SMatthew G. Knepley       else                        {ierr = PetscViewerASCIIPrintf(viewer, " (adj FVM)");CHKERRQ(ierr);}
164a6cbbb48SMatthew G. Knepley     } else {
165a6cbbb48SMatthew G. Knepley       if (prob->adjacency[f*2+1]) {ierr = PetscViewerASCIIPrintf(viewer, " (adj FEM)");CHKERRQ(ierr);}
166a6cbbb48SMatthew G. Knepley       else                        {ierr = PetscViewerASCIIPrintf(viewer, " (adj FUNKY)");CHKERRQ(ierr);}
167a6cbbb48SMatthew G. Knepley     }
168*3e60c2a6SMatthew G. Knepley     if (q) {
169f35450b9SMatthew G. Knepley       ierr = PetscQuadratureGetData(q, NULL, &Nqc, &Nq, NULL, NULL);CHKERRQ(ierr);
170f35450b9SMatthew G. Knepley       ierr = PetscViewerASCIIPrintf(viewer, " (Nq %D Nqc %D)", Nq, Nqc);CHKERRQ(ierr);
171*3e60c2a6SMatthew G. Knepley     }
1727d8a60eaSMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
1735d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
1747d8a60eaSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEView((PetscFE) obj, viewer);CHKERRQ(ierr);}
1757d8a60eaSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVView((PetscFV) obj, viewer);CHKERRQ(ierr);}
1765d160056SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
1777d8a60eaSMatthew G. Knepley   }
17897b6e6e8SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &numConstants, &constants);CHKERRQ(ierr);
17997b6e6e8SMatthew G. Knepley   if (numConstants) {
18097b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPrintf(viewer, "%D constants\n", numConstants);CHKERRQ(ierr);
18197b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
18257fc01e9SMatthew G. Knepley     for (f = 0; f < numConstants; ++f) {ierr = PetscViewerASCIIPrintf(viewer, "%g\n", (double) PetscRealPart(constants[f]));CHKERRQ(ierr);}
18397b6e6e8SMatthew G. Knepley     ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
18497b6e6e8SMatthew G. Knepley   }
1857d8a60eaSMatthew G. Knepley   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
1867d8a60eaSMatthew G. Knepley   PetscFunctionReturn(0);
1877d8a60eaSMatthew G. Knepley }
1887d8a60eaSMatthew G. Knepley 
1892764a2aaSMatthew G. Knepley /*@C
1902764a2aaSMatthew G. Knepley   PetscDSView - Views a PetscDS
1912764a2aaSMatthew G. Knepley 
1922764a2aaSMatthew G. Knepley   Collective on PetscDS
1932764a2aaSMatthew G. Knepley 
1942764a2aaSMatthew G. Knepley   Input Parameter:
1952764a2aaSMatthew G. Knepley + prob - the PetscDS object to view
1962764a2aaSMatthew G. Knepley - v  - the viewer
1972764a2aaSMatthew G. Knepley 
1982764a2aaSMatthew G. Knepley   Level: developer
1992764a2aaSMatthew G. Knepley 
2002764a2aaSMatthew G. Knepley .seealso PetscDSDestroy()
2012764a2aaSMatthew G. Knepley @*/
2022764a2aaSMatthew G. Knepley PetscErrorCode PetscDSView(PetscDS prob, PetscViewer v)
2032764a2aaSMatthew G. Knepley {
2047d8a60eaSMatthew G. Knepley   PetscBool      iascii;
2052764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2062764a2aaSMatthew G. Knepley 
2072764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2082764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2092764a2aaSMatthew G. Knepley   if (!v) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject) prob), &v);CHKERRQ(ierr);}
2107d8a60eaSMatthew G. Knepley   else    {PetscValidHeaderSpecific(v, PETSC_VIEWER_CLASSID, 2);}
2117d8a60eaSMatthew G. Knepley   ierr = PetscObjectTypeCompare((PetscObject) v, PETSCVIEWERASCII, &iascii);CHKERRQ(ierr);
2127d8a60eaSMatthew G. Knepley   if (iascii) {ierr = PetscDSView_Ascii(prob, v);CHKERRQ(ierr);}
2132764a2aaSMatthew G. Knepley   if (prob->ops->view) {ierr = (*prob->ops->view)(prob, v);CHKERRQ(ierr);}
2142764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2152764a2aaSMatthew G. Knepley }
2162764a2aaSMatthew G. Knepley 
2172764a2aaSMatthew G. Knepley /*@
2182764a2aaSMatthew G. Knepley   PetscDSSetFromOptions - sets parameters in a PetscDS from the options database
2192764a2aaSMatthew G. Knepley 
2202764a2aaSMatthew G. Knepley   Collective on PetscDS
2212764a2aaSMatthew G. Knepley 
2222764a2aaSMatthew G. Knepley   Input Parameter:
2232764a2aaSMatthew G. Knepley . prob - the PetscDS object to set options for
2242764a2aaSMatthew G. Knepley 
2252764a2aaSMatthew G. Knepley   Options Database:
2262764a2aaSMatthew G. Knepley 
2272764a2aaSMatthew G. Knepley   Level: developer
2282764a2aaSMatthew G. Knepley 
2292764a2aaSMatthew G. Knepley .seealso PetscDSView()
2302764a2aaSMatthew G. Knepley @*/
2312764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetFromOptions(PetscDS prob)
2322764a2aaSMatthew G. Knepley {
233f1fd5e65SToby Isaac   DSBoundary     b;
2342764a2aaSMatthew G. Knepley   const char    *defaultType;
2352764a2aaSMatthew G. Knepley   char           name[256];
2362764a2aaSMatthew G. Knepley   PetscBool      flg;
2372764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
2382764a2aaSMatthew G. Knepley 
2392764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2402764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2412764a2aaSMatthew G. Knepley   if (!((PetscObject) prob)->type_name) {
2422764a2aaSMatthew G. Knepley     defaultType = PETSCDSBASIC;
2432764a2aaSMatthew G. Knepley   } else {
2442764a2aaSMatthew G. Knepley     defaultType = ((PetscObject) prob)->type_name;
2452764a2aaSMatthew G. Knepley   }
2460f51fdf8SToby Isaac   ierr = PetscDSRegisterAll();CHKERRQ(ierr);
2472764a2aaSMatthew G. Knepley 
2482764a2aaSMatthew G. Knepley   ierr = PetscObjectOptionsBegin((PetscObject) prob);CHKERRQ(ierr);
249f1fd5e65SToby Isaac   for (b = prob->boundary; b; b = b->next) {
250f1fd5e65SToby Isaac     char       optname[1024];
251f1fd5e65SToby Isaac     PetscInt   ids[1024], len = 1024;
252f1fd5e65SToby Isaac     PetscBool  flg;
253f1fd5e65SToby Isaac 
254f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s", b->name);CHKERRQ(ierr);
255f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
256f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary IDs", "", ids, &len, &flg);CHKERRQ(ierr);
257f1fd5e65SToby Isaac     if (flg) {
258f1fd5e65SToby Isaac       b->numids = len;
259f1fd5e65SToby Isaac       ierr = PetscFree(b->ids);CHKERRQ(ierr);
260f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->ids);CHKERRQ(ierr);
261f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->ids, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
262f1fd5e65SToby Isaac     }
263e7b0402cSSander Arens     len = 1024;
264f1fd5e65SToby Isaac     ierr = PetscSNPrintf(optname, sizeof(optname), "-bc_%s_comp", b->name);CHKERRQ(ierr);
265f1fd5e65SToby Isaac     ierr = PetscMemzero(ids, sizeof(ids));CHKERRQ(ierr);
266f1fd5e65SToby Isaac     ierr = PetscOptionsIntArray(optname, "List of boundary field components", "", ids, &len, &flg);CHKERRQ(ierr);
267f1fd5e65SToby Isaac     if (flg) {
268f1fd5e65SToby Isaac       b->numcomps = len;
269f1fd5e65SToby Isaac       ierr = PetscFree(b->comps);CHKERRQ(ierr);
270f1fd5e65SToby Isaac       ierr = PetscMalloc1(len, &b->comps);CHKERRQ(ierr);
271f1fd5e65SToby Isaac       ierr = PetscMemcpy(b->comps, ids, len*sizeof(PetscInt));CHKERRQ(ierr);
272f1fd5e65SToby Isaac     }
273f1fd5e65SToby Isaac   }
2742764a2aaSMatthew G. Knepley   ierr = PetscOptionsFList("-petscds_type", "Discrete System", "PetscDSSetType", PetscDSList, defaultType, name, 256, &flg);CHKERRQ(ierr);
2752764a2aaSMatthew G. Knepley   if (flg) {
2762764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, name);CHKERRQ(ierr);
2772764a2aaSMatthew G. Knepley   } else if (!((PetscObject) prob)->type_name) {
2782764a2aaSMatthew G. Knepley     ierr = PetscDSSetType(prob, defaultType);CHKERRQ(ierr);
2792764a2aaSMatthew G. Knepley   }
2802764a2aaSMatthew G. Knepley   if (prob->ops->setfromoptions) {ierr = (*prob->ops->setfromoptions)(prob);CHKERRQ(ierr);}
2812764a2aaSMatthew G. Knepley   /* process any options handlers added with PetscObjectAddOptionsHandler() */
2820633abcbSJed Brown   ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) prob);CHKERRQ(ierr);
2832764a2aaSMatthew G. Knepley   ierr = PetscOptionsEnd();CHKERRQ(ierr);
2845d160056SMatthew G. Knepley   if (prob->Nf) {ierr = PetscDSViewFromOptions(prob, NULL, "-petscds_view");CHKERRQ(ierr);}
2852764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
2862764a2aaSMatthew G. Knepley }
2872764a2aaSMatthew G. Knepley 
2882764a2aaSMatthew G. Knepley /*@C
2892764a2aaSMatthew G. Knepley   PetscDSSetUp - Construct data structures for the PetscDS
2902764a2aaSMatthew G. Knepley 
2912764a2aaSMatthew G. Knepley   Collective on PetscDS
2922764a2aaSMatthew G. Knepley 
2932764a2aaSMatthew G. Knepley   Input Parameter:
2942764a2aaSMatthew G. Knepley . prob - the PetscDS object to setup
2952764a2aaSMatthew G. Knepley 
2962764a2aaSMatthew G. Knepley   Level: developer
2972764a2aaSMatthew G. Knepley 
2982764a2aaSMatthew G. Knepley .seealso PetscDSView(), PetscDSDestroy()
2992764a2aaSMatthew G. Knepley @*/
3002764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetUp(PetscDS prob)
3012764a2aaSMatthew G. Knepley {
3022764a2aaSMatthew G. Knepley   const PetscInt Nf = prob->Nf;
303d1506c7cSMatthew G. Knepley   PetscInt       dim, dimEmbed, work, NcMax = 0, NqMax = 0, f;
3042764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3052764a2aaSMatthew G. Knepley 
3062764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3072764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
3082764a2aaSMatthew G. Knepley   if (prob->setup) PetscFunctionReturn(0);
3092764a2aaSMatthew G. Knepley   /* Calculate sizes */
3102764a2aaSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
311d1506c7cSMatthew G. Knepley   ierr = PetscDSGetCoordinateDimension(prob, &dimEmbed);CHKERRQ(ierr);
312f744cafaSSander Arens   prob->totDim = prob->totComp = 0;
31347e57110SSander Arens   ierr = PetscMalloc2(Nf,&prob->Nc,Nf,&prob->Nb);CHKERRQ(ierr);
314f744cafaSSander Arens   ierr = PetscCalloc2(Nf+1,&prob->off,Nf+1,&prob->offDer);CHKERRQ(ierr);
315f744cafaSSander Arens   ierr = PetscMalloc4(Nf,&prob->basis,Nf,&prob->basisDer,Nf,&prob->basisFace,Nf,&prob->basisDerFace);CHKERRQ(ierr);
3162764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) {
3179de99aefSMatthew G. Knepley     PetscObject     obj;
3189de99aefSMatthew G. Knepley     PetscClassId    id;
3192764a2aaSMatthew G. Knepley     PetscQuadrature q;
3209de99aefSMatthew G. Knepley     PetscInt        Nq = 0, Nb, Nc;
3212764a2aaSMatthew G. Knepley 
3229de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
3239de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
3249de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {
3259de99aefSMatthew G. Knepley       PetscFE fe = (PetscFE) obj;
3269de99aefSMatthew G. Knepley 
3272764a2aaSMatthew G. Knepley       ierr = PetscFEGetQuadrature(fe, &q);CHKERRQ(ierr);
3282764a2aaSMatthew G. Knepley       ierr = PetscFEGetDimension(fe, &Nb);CHKERRQ(ierr);
3292764a2aaSMatthew G. Knepley       ierr = PetscFEGetNumComponents(fe, &Nc);CHKERRQ(ierr);
3302764a2aaSMatthew G. Knepley       ierr = PetscFEGetDefaultTabulation(fe, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3314d0b9603SSander Arens       ierr = PetscFEGetFaceTabulation(fe, &prob->basisFace[f], &prob->basisDerFace[f], NULL);CHKERRQ(ierr);
3329de99aefSMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
3339de99aefSMatthew G. Knepley       PetscFV fv = (PetscFV) obj;
3349de99aefSMatthew G. Knepley 
3359de99aefSMatthew G. Knepley       ierr = PetscFVGetQuadrature(fv, &q);CHKERRQ(ierr);
3369de99aefSMatthew G. Knepley       ierr = PetscFVGetNumComponents(fv, &Nc);CHKERRQ(ierr);
3379c3cf19fSMatthew G. Knepley       Nb   = Nc;
3386c1a3d01SMatthew G. Knepley       ierr = PetscFVGetDefaultTabulation(fv, &prob->basis[f], &prob->basisDer[f], NULL);CHKERRQ(ierr);
3394d0b9603SSander Arens       /* TODO: should PetscFV also have face tabulation? Otherwise there will be a null pointer in prob->basisFace */
340abac5ca0SMatthew G. Knepley     } else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", f);
34147e57110SSander Arens     prob->Nc[f]       = Nc;
34247e57110SSander Arens     prob->Nb[f]       = Nb;
343194d53e6SMatthew G. Knepley     prob->off[f+1]    = Nc     + prob->off[f];
344194d53e6SMatthew G. Knepley     prob->offDer[f+1] = Nc*dim + prob->offDer[f];
345a6b92713SMatthew G. Knepley     if (q) {ierr = PetscQuadratureGetData(q, NULL, NULL, &Nq, NULL, NULL);CHKERRQ(ierr);}
3462764a2aaSMatthew G. Knepley     NqMax          = PetscMax(NqMax, Nq);
3472764a2aaSMatthew G. Knepley     NcMax          = PetscMax(NcMax, Nc);
3489c3cf19fSMatthew G. Knepley     prob->totDim  += Nb;
3492764a2aaSMatthew G. Knepley     prob->totComp += Nc;
3502764a2aaSMatthew G. Knepley   }
3512764a2aaSMatthew G. Knepley   work = PetscMax(prob->totComp*dim, PetscSqr(NcMax*dim));
3522764a2aaSMatthew G. Knepley   /* Allocate works space */
353d1506c7cSMatthew 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);
3542764a2aaSMatthew G. Knepley   ierr = PetscMalloc6(NqMax*NcMax,&prob->f0,NqMax*NcMax*dim,&prob->f1,NqMax*NcMax*NcMax,&prob->g0,NqMax*NcMax*NcMax*dim,&prob->g1,NqMax*NcMax*NcMax*dim,&prob->g2,NqMax*NcMax*NcMax*dim*dim,&prob->g3);CHKERRQ(ierr);
3552764a2aaSMatthew G. Knepley   if (prob->ops->setup) {ierr = (*prob->ops->setup)(prob);CHKERRQ(ierr);}
3562764a2aaSMatthew G. Knepley   prob->setup = PETSC_TRUE;
3572764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3582764a2aaSMatthew G. Knepley }
3592764a2aaSMatthew G. Knepley 
3602764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSDestroyStructs_Static(PetscDS prob)
3612764a2aaSMatthew G. Knepley {
3622764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
3632764a2aaSMatthew G. Knepley 
3642764a2aaSMatthew G. Knepley   PetscFunctionBegin;
36547e57110SSander Arens   ierr = PetscFree2(prob->Nc,prob->Nb);CHKERRQ(ierr);
366f744cafaSSander Arens   ierr = PetscFree2(prob->off,prob->offDer);CHKERRQ(ierr);
367f744cafaSSander Arens   ierr = PetscFree4(prob->basis,prob->basisDer,prob->basisFace,prob->basisDerFace);CHKERRQ(ierr);
3682764a2aaSMatthew G. Knepley   ierr = PetscFree5(prob->u,prob->u_t,prob->u_x,prob->x,prob->refSpaceDer);CHKERRQ(ierr);
3692764a2aaSMatthew G. Knepley   ierr = PetscFree6(prob->f0,prob->f1,prob->g0,prob->g1,prob->g2,prob->g3);CHKERRQ(ierr);
3702764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
3712764a2aaSMatthew G. Knepley }
3722764a2aaSMatthew G. Knepley 
3732764a2aaSMatthew G. Knepley static PetscErrorCode PetscDSEnlarge_Static(PetscDS prob, PetscInt NfNew)
3742764a2aaSMatthew G. Knepley {
375f744cafaSSander Arens   PetscObject      *tmpd;
376a6cbbb48SMatthew G. Knepley   PetscBool        *tmpi, *tmpa;
37732d2bbc9SMatthew G. Knepley   PetscPointFunc   *tmpobj, *tmpf, *tmpup;
378b7e05686SMatthew G. Knepley   PetscPointJac    *tmpg, *tmpgp, *tmpgt;
3792aa1fc23SMatthew G. Knepley   PetscBdPointFunc *tmpfbd;
3802aa1fc23SMatthew G. Knepley   PetscBdPointJac  *tmpgbd;
381194d53e6SMatthew G. Knepley   PetscRiemannFunc *tmpr;
382c371a6d1SMatthew G. Knepley   PetscSimplePointFunc *tmpexactSol;
3830c2f2876SMatthew G. Knepley   void            **tmpctx;
384a6cbbb48SMatthew G. Knepley   PetscInt          Nf = prob->Nf, f, i;
3852764a2aaSMatthew G. Knepley   PetscErrorCode    ierr;
3862764a2aaSMatthew G. Knepley 
3872764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3882764a2aaSMatthew G. Knepley   if (Nf >= NfNew) PetscFunctionReturn(0);
3892764a2aaSMatthew G. Knepley   prob->setup = PETSC_FALSE;
3902764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(prob);CHKERRQ(ierr);
391f744cafaSSander Arens   ierr = PetscMalloc3(NfNew, &tmpd, NfNew, &tmpi, NfNew*2, &tmpa);CHKERRQ(ierr);
392f744cafaSSander 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];}
393f744cafaSSander 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;}
394f744cafaSSander Arens   ierr = PetscFree3(prob->disc, prob->implicit, prob->adjacency);CHKERRQ(ierr);
3952764a2aaSMatthew G. Knepley   prob->Nf        = NfNew;
3962764a2aaSMatthew G. Knepley   prob->disc      = tmpd;
397249df284SMatthew G. Knepley   prob->implicit  = tmpi;
398a6cbbb48SMatthew G. Knepley   prob->adjacency = tmpa;
399b7e05686SMatthew 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);
40032d2bbc9SMatthew G. Knepley   ierr = PetscCalloc1(NfNew, &tmpup);CHKERRQ(ierr);
4012764a2aaSMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpobj[f] = prob->obj[f];
4022764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpf[f] = prob->f[f];
4032764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpg[f] = prob->g[f];
404475e0ac9SMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgp[f] = prob->gp[f];
4050c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpr[f] = prob->r[f];
40632d2bbc9SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpup[f] = prob->update[f];
4070c2f2876SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpctx[f] = prob->ctx[f];
4082764a2aaSMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpobj[f] = NULL;
4092764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpf[f] = NULL;
4102764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpg[f] = NULL;
411475e0ac9SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgp[f] = NULL;
412b7e05686SMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgt[f] = NULL;
4130c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpr[f] = NULL;
41432d2bbc9SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpup[f] = NULL;
4150c2f2876SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpctx[f] = NULL;
416b7e05686SMatthew G. Knepley   ierr = PetscFree7(prob->obj, prob->f, prob->g, prob->gp, prob->gt, prob->r, prob->ctx);CHKERRQ(ierr);
41732d2bbc9SMatthew G. Knepley   ierr = PetscFree(prob->update);CHKERRQ(ierr);
4182764a2aaSMatthew G. Knepley   prob->obj = tmpobj;
4192764a2aaSMatthew G. Knepley   prob->f   = tmpf;
4202764a2aaSMatthew G. Knepley   prob->g   = tmpg;
421475e0ac9SMatthew G. Knepley   prob->gp  = tmpgp;
422b7e05686SMatthew G. Knepley   prob->gt  = tmpgt;
4230c2f2876SMatthew G. Knepley   prob->r   = tmpr;
42432d2bbc9SMatthew G. Knepley   prob->update = tmpup;
4250c2f2876SMatthew G. Knepley   prob->ctx = tmpctx;
426c371a6d1SMatthew G. Knepley   ierr = PetscCalloc3(NfNew*2, &tmpfbd, NfNew*NfNew*4, &tmpgbd, NfNew, &tmpexactSol);CHKERRQ(ierr);
4272764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*2; ++f) tmpfbd[f] = prob->fBd[f];
4282764a2aaSMatthew G. Knepley   for (f = 0; f < Nf*Nf*4; ++f) tmpgbd[f] = prob->gBd[f];
429c371a6d1SMatthew G. Knepley   for (f = 0; f < Nf; ++f) tmpexactSol[f] = prob->exactSol[f];
4302764a2aaSMatthew G. Knepley   for (f = Nf*2; f < NfNew*2; ++f) tmpfbd[f] = NULL;
4312764a2aaSMatthew G. Knepley   for (f = Nf*Nf*4; f < NfNew*NfNew*4; ++f) tmpgbd[f] = NULL;
432c371a6d1SMatthew G. Knepley   for (f = Nf; f < NfNew; ++f) tmpexactSol[f] = NULL;
433c371a6d1SMatthew G. Knepley   ierr = PetscFree3(prob->fBd, prob->gBd, prob->exactSol);CHKERRQ(ierr);
4342764a2aaSMatthew G. Knepley   prob->fBd = tmpfbd;
4352764a2aaSMatthew G. Knepley   prob->gBd = tmpgbd;
436c371a6d1SMatthew G. Knepley   prob->exactSol = tmpexactSol;
4372764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4382764a2aaSMatthew G. Knepley }
4392764a2aaSMatthew G. Knepley 
4402764a2aaSMatthew G. Knepley /*@
4412764a2aaSMatthew G. Knepley   PetscDSDestroy - Destroys a PetscDS object
4422764a2aaSMatthew G. Knepley 
4432764a2aaSMatthew G. Knepley   Collective on PetscDS
4442764a2aaSMatthew G. Knepley 
4452764a2aaSMatthew G. Knepley   Input Parameter:
4462764a2aaSMatthew G. Knepley . prob - the PetscDS object to destroy
4472764a2aaSMatthew G. Knepley 
4482764a2aaSMatthew G. Knepley   Level: developer
4492764a2aaSMatthew G. Knepley 
4502764a2aaSMatthew G. Knepley .seealso PetscDSView()
4512764a2aaSMatthew G. Knepley @*/
4522764a2aaSMatthew G. Knepley PetscErrorCode PetscDSDestroy(PetscDS *prob)
4532764a2aaSMatthew G. Knepley {
4542764a2aaSMatthew G. Knepley   PetscInt       f;
45558ebd649SToby Isaac   DSBoundary     next;
4562764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
4572764a2aaSMatthew G. Knepley 
4582764a2aaSMatthew G. Knepley   PetscFunctionBegin;
4592764a2aaSMatthew G. Knepley   if (!*prob) PetscFunctionReturn(0);
4602764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific((*prob), PETSCDS_CLASSID, 1);
4612764a2aaSMatthew G. Knepley 
4622764a2aaSMatthew G. Knepley   if (--((PetscObject)(*prob))->refct > 0) {*prob = 0; PetscFunctionReturn(0);}
4632764a2aaSMatthew G. Knepley   ((PetscObject) (*prob))->refct = 0;
464df3a45bdSMatthew G. Knepley   if ((*prob)->subprobs) {
465df3a45bdSMatthew G. Knepley     PetscInt dim, d;
466df3a45bdSMatthew G. Knepley 
467df3a45bdSMatthew G. Knepley     ierr = PetscDSGetSpatialDimension(*prob, &dim);CHKERRQ(ierr);
468df3a45bdSMatthew G. Knepley     for (d = 0; d < dim; ++d) {ierr = PetscDSDestroy(&(*prob)->subprobs[d]);CHKERRQ(ierr);}
469df3a45bdSMatthew G. Knepley   }
470df3a45bdSMatthew G. Knepley   ierr = PetscFree((*prob)->subprobs);CHKERRQ(ierr);
4712764a2aaSMatthew G. Knepley   ierr = PetscDSDestroyStructs_Static(*prob);CHKERRQ(ierr);
4722764a2aaSMatthew G. Knepley   for (f = 0; f < (*prob)->Nf; ++f) {
4732764a2aaSMatthew G. Knepley     ierr = PetscObjectDereference((*prob)->disc[f]);CHKERRQ(ierr);
4742764a2aaSMatthew G. Knepley   }
475f744cafaSSander Arens   ierr = PetscFree3((*prob)->disc, (*prob)->implicit, (*prob)->adjacency);CHKERRQ(ierr);
476b7e05686SMatthew G. Knepley   ierr = PetscFree7((*prob)->obj,(*prob)->f,(*prob)->g,(*prob)->gp,(*prob)->gt,(*prob)->r,(*prob)->ctx);CHKERRQ(ierr);
47732d2bbc9SMatthew G. Knepley   ierr = PetscFree((*prob)->update);CHKERRQ(ierr);
478c371a6d1SMatthew G. Knepley   ierr = PetscFree3((*prob)->fBd,(*prob)->gBd,(*prob)->exactSol);CHKERRQ(ierr);
4792764a2aaSMatthew G. Knepley   if ((*prob)->ops->destroy) {ierr = (*(*prob)->ops->destroy)(*prob);CHKERRQ(ierr);}
48058ebd649SToby Isaac   next = (*prob)->boundary;
48158ebd649SToby Isaac   while (next) {
48258ebd649SToby Isaac     DSBoundary b = next;
48358ebd649SToby Isaac 
48458ebd649SToby Isaac     next = b->next;
48558ebd649SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
48658ebd649SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
48758ebd649SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
48858ebd649SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
48958ebd649SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
49058ebd649SToby Isaac   }
49197b6e6e8SMatthew G. Knepley   ierr = PetscFree((*prob)->constants);CHKERRQ(ierr);
4922764a2aaSMatthew G. Knepley   ierr = PetscHeaderDestroy(prob);CHKERRQ(ierr);
4932764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
4942764a2aaSMatthew G. Knepley }
4952764a2aaSMatthew G. Knepley 
4962764a2aaSMatthew G. Knepley /*@
4972764a2aaSMatthew G. Knepley   PetscDSCreate - Creates an empty PetscDS object. The type can then be set with PetscDSSetType().
4982764a2aaSMatthew G. Knepley 
4992764a2aaSMatthew G. Knepley   Collective on MPI_Comm
5002764a2aaSMatthew G. Knepley 
5012764a2aaSMatthew G. Knepley   Input Parameter:
5022764a2aaSMatthew G. Knepley . comm - The communicator for the PetscDS object
5032764a2aaSMatthew G. Knepley 
5042764a2aaSMatthew G. Knepley   Output Parameter:
5052764a2aaSMatthew G. Knepley . prob - The PetscDS object
5062764a2aaSMatthew G. Knepley 
5072764a2aaSMatthew G. Knepley   Level: beginner
5082764a2aaSMatthew G. Knepley 
5092764a2aaSMatthew G. Knepley .seealso: PetscDSSetType(), PETSCDSBASIC
5102764a2aaSMatthew G. Knepley @*/
5112764a2aaSMatthew G. Knepley PetscErrorCode PetscDSCreate(MPI_Comm comm, PetscDS *prob)
5122764a2aaSMatthew G. Knepley {
5132764a2aaSMatthew G. Knepley   PetscDS   p;
5142764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5152764a2aaSMatthew G. Knepley 
5162764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5172764a2aaSMatthew G. Knepley   PetscValidPointer(prob, 2);
5182764a2aaSMatthew G. Knepley   *prob  = NULL;
5192764a2aaSMatthew G. Knepley   ierr = PetscDSInitializePackage();CHKERRQ(ierr);
5202764a2aaSMatthew G. Knepley 
52173107ff1SLisandro Dalcin   ierr = PetscHeaderCreate(p, PETSCDS_CLASSID, "PetscDS", "Discrete System", "PetscDS", comm, PetscDSDestroy, PetscDSView);CHKERRQ(ierr);
5222764a2aaSMatthew G. Knepley 
5232764a2aaSMatthew G. Knepley   p->Nf    = 0;
5242764a2aaSMatthew G. Knepley   p->setup = PETSC_FALSE;
52597b6e6e8SMatthew G. Knepley   p->numConstants  = 0;
52697b6e6e8SMatthew G. Knepley   p->constants     = NULL;
527a859676bSMatthew G. Knepley   p->dimEmbed      = -1;
52803d90f89SMatthew G. Knepley   p->defaultAdj[0] = PETSC_FALSE;
52903d90f89SMatthew G. Knepley   p->defaultAdj[1] = PETSC_TRUE;
5302764a2aaSMatthew G. Knepley 
5312764a2aaSMatthew G. Knepley   *prob = p;
5322764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5332764a2aaSMatthew G. Knepley }
5342764a2aaSMatthew G. Knepley 
535bc4ae4beSMatthew G. Knepley /*@
536bc4ae4beSMatthew G. Knepley   PetscDSGetNumFields - Returns the number of fields in the DS
537bc4ae4beSMatthew G. Knepley 
538bc4ae4beSMatthew G. Knepley   Not collective
539bc4ae4beSMatthew G. Knepley 
540bc4ae4beSMatthew G. Knepley   Input Parameter:
541bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
542bc4ae4beSMatthew G. Knepley 
543bc4ae4beSMatthew G. Knepley   Output Parameter:
544bc4ae4beSMatthew G. Knepley . Nf - The number of fields
545bc4ae4beSMatthew G. Knepley 
546bc4ae4beSMatthew G. Knepley   Level: beginner
547bc4ae4beSMatthew G. Knepley 
548bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetSpatialDimension(), PetscDSCreate()
549bc4ae4beSMatthew G. Knepley @*/
5502764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetNumFields(PetscDS prob, PetscInt *Nf)
5512764a2aaSMatthew G. Knepley {
5522764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5532764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5542764a2aaSMatthew G. Knepley   PetscValidPointer(Nf, 2);
5552764a2aaSMatthew G. Knepley   *Nf = prob->Nf;
5562764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5572764a2aaSMatthew G. Knepley }
5582764a2aaSMatthew G. Knepley 
559bc4ae4beSMatthew G. Knepley /*@
560a859676bSMatthew G. Knepley   PetscDSGetSpatialDimension - Returns the spatial dimension of the DS, meaning the topological dimension of the discretizations
561bc4ae4beSMatthew G. Knepley 
562bc4ae4beSMatthew G. Knepley   Not collective
563bc4ae4beSMatthew G. Knepley 
564bc4ae4beSMatthew G. Knepley   Input Parameter:
565bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
566bc4ae4beSMatthew G. Knepley 
567bc4ae4beSMatthew G. Knepley   Output Parameter:
568bc4ae4beSMatthew G. Knepley . dim - The spatial dimension
569bc4ae4beSMatthew G. Knepley 
570bc4ae4beSMatthew G. Knepley   Level: beginner
571bc4ae4beSMatthew G. Knepley 
572a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetNumFields(), PetscDSCreate()
573bc4ae4beSMatthew G. Knepley @*/
5742764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetSpatialDimension(PetscDS prob, PetscInt *dim)
5752764a2aaSMatthew G. Knepley {
5762764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
5772764a2aaSMatthew G. Knepley 
5782764a2aaSMatthew G. Knepley   PetscFunctionBegin;
5792764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
5802764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
5812764a2aaSMatthew G. Knepley   *dim = 0;
5829de99aefSMatthew G. Knepley   if (prob->Nf) {
5839de99aefSMatthew G. Knepley     PetscObject  obj;
5849de99aefSMatthew G. Knepley     PetscClassId id;
5859de99aefSMatthew G. Knepley 
5869de99aefSMatthew G. Knepley     ierr = PetscDSGetDiscretization(prob, 0, &obj);CHKERRQ(ierr);
5879de99aefSMatthew G. Knepley     ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
5889de99aefSMatthew G. Knepley     if (id == PETSCFE_CLASSID)      {ierr = PetscFEGetSpatialDimension((PetscFE) obj, dim);CHKERRQ(ierr);}
5899de99aefSMatthew G. Knepley     else if (id == PETSCFV_CLASSID) {ierr = PetscFVGetSpatialDimension((PetscFV) obj, dim);CHKERRQ(ierr);}
5909de99aefSMatthew G. Knepley     else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unknown discretization type for field %d", 0);
5919de99aefSMatthew G. Knepley   }
5922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
5932764a2aaSMatthew G. Knepley }
5942764a2aaSMatthew G. Knepley 
595bc4ae4beSMatthew G. Knepley /*@
596a859676bSMatthew G. Knepley   PetscDSGetCoordinateDimension - Returns the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
597a859676bSMatthew G. Knepley 
598a859676bSMatthew G. Knepley   Not collective
599a859676bSMatthew G. Knepley 
600a859676bSMatthew G. Knepley   Input Parameter:
601a859676bSMatthew G. Knepley . prob - The PetscDS object
602a859676bSMatthew G. Knepley 
603a859676bSMatthew G. Knepley   Output Parameter:
604a859676bSMatthew G. Knepley . dimEmbed - The coordinate dimension
605a859676bSMatthew G. Knepley 
606a859676bSMatthew G. Knepley   Level: beginner
607a859676bSMatthew G. Knepley 
608a859676bSMatthew G. Knepley .seealso: PetscDSSetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
609a859676bSMatthew G. Knepley @*/
610a859676bSMatthew G. Knepley PetscErrorCode PetscDSGetCoordinateDimension(PetscDS prob, PetscInt *dimEmbed)
611a859676bSMatthew G. Knepley {
612a859676bSMatthew G. Knepley   PetscFunctionBegin;
613a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
614a859676bSMatthew G. Knepley   PetscValidPointer(dimEmbed, 2);
615a859676bSMatthew G. Knepley   if (prob->dimEmbed < 0) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONGSTATE, "No coordinate dimension set for this DS");
616a859676bSMatthew G. Knepley   *dimEmbed = prob->dimEmbed;
617a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
618a859676bSMatthew G. Knepley }
619a859676bSMatthew G. Knepley 
620a859676bSMatthew G. Knepley /*@
621a859676bSMatthew G. Knepley   PetscDSSetCoordinateDimension - Set the coordinate dimension of the DS, meaning the dimension of the space into which the discretiaztions are embedded
622a859676bSMatthew G. Knepley 
623a859676bSMatthew G. Knepley   Not collective
624a859676bSMatthew G. Knepley 
625a859676bSMatthew G. Knepley   Input Parameters:
626a859676bSMatthew G. Knepley + prob - The PetscDS object
627a859676bSMatthew G. Knepley - dimEmbed - The coordinate dimension
628a859676bSMatthew G. Knepley 
629a859676bSMatthew G. Knepley   Level: beginner
630a859676bSMatthew G. Knepley 
631a859676bSMatthew G. Knepley .seealso: PetscDSGetCoordinateDimension(), PetscDSGetSpatialDimension(), PetscDSGetNumFields(), PetscDSCreate()
632a859676bSMatthew G. Knepley @*/
633a859676bSMatthew G. Knepley PetscErrorCode PetscDSSetCoordinateDimension(PetscDS prob, PetscInt dimEmbed)
634a859676bSMatthew G. Knepley {
635a859676bSMatthew G. Knepley   PetscFunctionBegin;
636a859676bSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
637a859676bSMatthew G. Knepley   prob->dimEmbed = dimEmbed;
638a859676bSMatthew G. Knepley   PetscFunctionReturn(0);
639a859676bSMatthew G. Knepley }
640a859676bSMatthew G. Knepley 
641a859676bSMatthew G. Knepley /*@
642bc4ae4beSMatthew G. Knepley   PetscDSGetTotalDimension - Returns the total size of the approximation space for this system
643bc4ae4beSMatthew G. Knepley 
644bc4ae4beSMatthew G. Knepley   Not collective
645bc4ae4beSMatthew G. Knepley 
646bc4ae4beSMatthew G. Knepley   Input Parameter:
647bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
648bc4ae4beSMatthew G. Knepley 
649bc4ae4beSMatthew G. Knepley   Output Parameter:
650bc4ae4beSMatthew G. Knepley . dim - The total problem dimension
651bc4ae4beSMatthew G. Knepley 
652bc4ae4beSMatthew G. Knepley   Level: beginner
653bc4ae4beSMatthew G. Knepley 
654bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
655bc4ae4beSMatthew G. Knepley @*/
6562764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalDimension(PetscDS prob, PetscInt *dim)
6572764a2aaSMatthew G. Knepley {
6582764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6592764a2aaSMatthew G. Knepley 
6602764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6612764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6622764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6632764a2aaSMatthew G. Knepley   PetscValidPointer(dim, 2);
6642764a2aaSMatthew G. Knepley   *dim = prob->totDim;
6652764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6662764a2aaSMatthew G. Knepley }
6672764a2aaSMatthew G. Knepley 
668bc4ae4beSMatthew G. Knepley /*@
669bc4ae4beSMatthew G. Knepley   PetscDSGetTotalComponents - Returns the total number of components in this system
670bc4ae4beSMatthew G. Knepley 
671bc4ae4beSMatthew G. Knepley   Not collective
672bc4ae4beSMatthew G. Knepley 
673bc4ae4beSMatthew G. Knepley   Input Parameter:
674bc4ae4beSMatthew G. Knepley . prob - The PetscDS object
675bc4ae4beSMatthew G. Knepley 
676bc4ae4beSMatthew G. Knepley   Output Parameter:
677bc4ae4beSMatthew G. Knepley . dim - The total number of components
678bc4ae4beSMatthew G. Knepley 
679bc4ae4beSMatthew G. Knepley   Level: beginner
680bc4ae4beSMatthew G. Knepley 
681bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetNumFields(), PetscDSCreate()
682bc4ae4beSMatthew G. Knepley @*/
6832764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTotalComponents(PetscDS prob, PetscInt *Nc)
6842764a2aaSMatthew G. Knepley {
6852764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
6862764a2aaSMatthew G. Knepley 
6872764a2aaSMatthew G. Knepley   PetscFunctionBegin;
6882764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
6892764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
6902764a2aaSMatthew G. Knepley   PetscValidPointer(Nc, 2);
6912764a2aaSMatthew G. Knepley   *Nc = prob->totComp;
6922764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
6932764a2aaSMatthew G. Knepley }
6942764a2aaSMatthew G. Knepley 
695bc4ae4beSMatthew G. Knepley /*@
696bc4ae4beSMatthew G. Knepley   PetscDSGetDiscretization - Returns the discretization object for the given field
697bc4ae4beSMatthew G. Knepley 
698bc4ae4beSMatthew G. Knepley   Not collective
699bc4ae4beSMatthew G. Knepley 
700bc4ae4beSMatthew G. Knepley   Input Parameters:
701bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
702bc4ae4beSMatthew G. Knepley - f - The field number
703bc4ae4beSMatthew G. Knepley 
704bc4ae4beSMatthew G. Knepley   Output Parameter:
705bc4ae4beSMatthew G. Knepley . disc - The discretization object
706bc4ae4beSMatthew G. Knepley 
707bc4ae4beSMatthew G. Knepley   Level: beginner
708bc4ae4beSMatthew G. Knepley 
709f744cafaSSander Arens .seealso: PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
710bc4ae4beSMatthew G. Knepley @*/
7112764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetDiscretization(PetscDS prob, PetscInt f, PetscObject *disc)
7122764a2aaSMatthew G. Knepley {
7132764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7142764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7152764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
7162764a2aaSMatthew 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);
7172764a2aaSMatthew G. Knepley   *disc = prob->disc[f];
7182764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7192764a2aaSMatthew G. Knepley }
7202764a2aaSMatthew G. Knepley 
721bc4ae4beSMatthew G. Knepley /*@
722bc4ae4beSMatthew G. Knepley   PetscDSSetDiscretization - Sets the discretization object for the given field
723bc4ae4beSMatthew G. Knepley 
724bc4ae4beSMatthew G. Knepley   Not collective
725bc4ae4beSMatthew G. Knepley 
726bc4ae4beSMatthew G. Knepley   Input Parameters:
727bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
728bc4ae4beSMatthew G. Knepley . f - The field number
729bc4ae4beSMatthew G. Knepley - disc - The discretization object
730bc4ae4beSMatthew G. Knepley 
731bc4ae4beSMatthew G. Knepley   Level: beginner
732bc4ae4beSMatthew G. Knepley 
733bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
734bc4ae4beSMatthew G. Knepley @*/
7352764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetDiscretization(PetscDS prob, PetscInt f, PetscObject disc)
7362764a2aaSMatthew G. Knepley {
7372764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7382764a2aaSMatthew G. Knepley 
7392764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7402764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
7412764a2aaSMatthew G. Knepley   PetscValidPointer(disc, 3);
7422764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
7432764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
7442764a2aaSMatthew G. Knepley   if (prob->disc[f]) {ierr = PetscObjectDereference(prob->disc[f]);CHKERRQ(ierr);}
7452764a2aaSMatthew G. Knepley   prob->disc[f] = disc;
7462764a2aaSMatthew G. Knepley   ierr = PetscObjectReference(disc);CHKERRQ(ierr);
747249df284SMatthew G. Knepley   {
748249df284SMatthew G. Knepley     PetscClassId id;
749249df284SMatthew G. Knepley 
750249df284SMatthew G. Knepley     ierr = PetscObjectGetClassId(disc, &id);CHKERRQ(ierr);
7511cf84007SMatthew G. Knepley     if (id == PETSCFE_CLASSID) {
7521cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_TRUE);CHKERRQ(ierr);
7531cf84007SMatthew G. Knepley       ierr = PetscDSSetAdjacency(prob, f, PETSC_FALSE, PETSC_TRUE);CHKERRQ(ierr);
7541cf84007SMatthew G. Knepley     } else if (id == PETSCFV_CLASSID) {
7551cf84007SMatthew G. Knepley       ierr = PetscDSSetImplicit(prob, f, PETSC_FALSE);CHKERRQ(ierr);
7561cf84007SMatthew G. Knepley       ierr = PetscDSSetAdjacency(prob, f, PETSC_TRUE, PETSC_FALSE);CHKERRQ(ierr);
757a6cbbb48SMatthew G. Knepley     }
758249df284SMatthew G. Knepley   }
7592764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7602764a2aaSMatthew G. Knepley }
7612764a2aaSMatthew G. Knepley 
762bc4ae4beSMatthew G. Knepley /*@
763bc4ae4beSMatthew G. Knepley   PetscDSAddDiscretization - Adds a discretization object
764bc4ae4beSMatthew G. Knepley 
765bc4ae4beSMatthew G. Knepley   Not collective
766bc4ae4beSMatthew G. Knepley 
767bc4ae4beSMatthew G. Knepley   Input Parameters:
768bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
769bc4ae4beSMatthew G. Knepley - disc - The boundary discretization object
770bc4ae4beSMatthew G. Knepley 
771bc4ae4beSMatthew G. Knepley   Level: beginner
772bc4ae4beSMatthew G. Knepley 
773bc4ae4beSMatthew G. Knepley .seealso: PetscDSGetDiscretization(), PetscDSSetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
774bc4ae4beSMatthew G. Knepley @*/
7752764a2aaSMatthew G. Knepley PetscErrorCode PetscDSAddDiscretization(PetscDS prob, PetscObject disc)
7762764a2aaSMatthew G. Knepley {
7772764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
7782764a2aaSMatthew G. Knepley 
7792764a2aaSMatthew G. Knepley   PetscFunctionBegin;
7802764a2aaSMatthew G. Knepley   ierr = PetscDSSetDiscretization(prob, prob->Nf, disc);CHKERRQ(ierr);
7812764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
7822764a2aaSMatthew G. Knepley }
7832764a2aaSMatthew G. Knepley 
784249df284SMatthew G. Knepley /*@
785249df284SMatthew G. Knepley   PetscDSGetImplicit - Returns the flag for implicit solve for this field. This is just a guide for IMEX
786249df284SMatthew G. Knepley 
787249df284SMatthew G. Knepley   Not collective
788249df284SMatthew G. Knepley 
789249df284SMatthew G. Knepley   Input Parameters:
790249df284SMatthew G. Knepley + prob - The PetscDS object
791249df284SMatthew G. Knepley - f - The field number
792249df284SMatthew G. Knepley 
793249df284SMatthew G. Knepley   Output Parameter:
794249df284SMatthew G. Knepley . implicit - The flag indicating what kind of solve to use for this field
795249df284SMatthew G. Knepley 
796249df284SMatthew G. Knepley   Level: developer
797249df284SMatthew G. Knepley 
798f744cafaSSander Arens .seealso: PetscDSSetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
799249df284SMatthew G. Knepley @*/
800249df284SMatthew G. Knepley PetscErrorCode PetscDSGetImplicit(PetscDS prob, PetscInt f, PetscBool *implicit)
801249df284SMatthew G. Knepley {
802249df284SMatthew G. Knepley   PetscFunctionBegin;
803249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
804249df284SMatthew G. Knepley   PetscValidPointer(implicit, 3);
805249df284SMatthew 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);
806249df284SMatthew G. Knepley   *implicit = prob->implicit[f];
807249df284SMatthew G. Knepley   PetscFunctionReturn(0);
808249df284SMatthew G. Knepley }
809249df284SMatthew G. Knepley 
810249df284SMatthew G. Knepley /*@
811249df284SMatthew G. Knepley   PetscDSSetImplicit - Set the flag for implicit solve for this field. This is just a guide for IMEX
812249df284SMatthew G. Knepley 
813249df284SMatthew G. Knepley   Not collective
814249df284SMatthew G. Knepley 
815249df284SMatthew G. Knepley   Input Parameters:
816249df284SMatthew G. Knepley + prob - The PetscDS object
817249df284SMatthew G. Knepley . f - The field number
818249df284SMatthew G. Knepley - implicit - The flag indicating what kind of solve to use for this field
819249df284SMatthew G. Knepley 
820249df284SMatthew G. Knepley   Level: developer
821249df284SMatthew G. Knepley 
822f744cafaSSander Arens .seealso: PetscDSGetImplicit(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
823249df284SMatthew G. Knepley @*/
824249df284SMatthew G. Knepley PetscErrorCode PetscDSSetImplicit(PetscDS prob, PetscInt f, PetscBool implicit)
825249df284SMatthew G. Knepley {
826249df284SMatthew G. Knepley   PetscFunctionBegin;
827249df284SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
828249df284SMatthew 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);
829249df284SMatthew G. Knepley   prob->implicit[f] = implicit;
830249df284SMatthew G. Knepley   PetscFunctionReturn(0);
831249df284SMatthew G. Knepley }
832249df284SMatthew G. Knepley 
833a6cbbb48SMatthew G. Knepley /*@
834a6cbbb48SMatthew G. Knepley   PetscDSGetAdjacency - Returns the flags for determining variable influence
835a6cbbb48SMatthew G. Knepley 
836a6cbbb48SMatthew G. Knepley   Not collective
837a6cbbb48SMatthew G. Knepley 
838a6cbbb48SMatthew G. Knepley   Input Parameters:
839a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
840a6cbbb48SMatthew G. Knepley - f - The field number
841a6cbbb48SMatthew G. Knepley 
842a6cbbb48SMatthew G. Knepley   Output Parameter:
843a6cbbb48SMatthew G. Knepley + useCone    - Flag for variable influence starting with the cone operation
844a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
845a6cbbb48SMatthew G. Knepley 
846a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
847a6cbbb48SMatthew G. Knepley 
848a6cbbb48SMatthew G. Knepley   Level: developer
849a6cbbb48SMatthew G. Knepley 
850f744cafaSSander Arens .seealso: PetscDSSetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
851a6cbbb48SMatthew G. Knepley @*/
852a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSGetAdjacency(PetscDS prob, PetscInt f, PetscBool *useCone, PetscBool *useClosure)
853a6cbbb48SMatthew G. Knepley {
854a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
855a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
8561cf84007SMatthew G. Knepley   if (useCone) PetscValidPointer(useCone, 3);
8571cf84007SMatthew G. Knepley   if (useClosure) PetscValidPointer(useClosure, 4);
85806cc46feSMatthew G. Knepley   if (f < 0) {
85906cc46feSMatthew G. Knepley     if (useCone)    *useCone    = prob->defaultAdj[0];
86006cc46feSMatthew G. Knepley     if (useClosure) *useClosure = prob->defaultAdj[1];
86106cc46feSMatthew G. Knepley   } else {
86206cc46feSMatthew G. Knepley     if (f >= prob->Nf) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
8631cf84007SMatthew G. Knepley     if (useCone)    *useCone    = prob->adjacency[f*2+0];
8641cf84007SMatthew G. Knepley     if (useClosure) *useClosure = prob->adjacency[f*2+1];
86506cc46feSMatthew G. Knepley   }
866a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
867a6cbbb48SMatthew G. Knepley }
868a6cbbb48SMatthew G. Knepley 
869a6cbbb48SMatthew G. Knepley /*@
870a6cbbb48SMatthew G. Knepley   PetscDSSetAdjacency - Set the flags for determining variable influence
871a6cbbb48SMatthew G. Knepley 
872a6cbbb48SMatthew G. Knepley   Not collective
873a6cbbb48SMatthew G. Knepley 
874a6cbbb48SMatthew G. Knepley   Input Parameters:
875a6cbbb48SMatthew G. Knepley + prob - The PetscDS object
876a6cbbb48SMatthew G. Knepley . f - The field number
877a6cbbb48SMatthew G. Knepley . useCone    - Flag for variable influence starting with the cone operation
878a6cbbb48SMatthew G. Knepley - useClosure - Flag for variable influence using transitive closure
879a6cbbb48SMatthew G. Knepley 
880a6cbbb48SMatthew G. Knepley   Note: See the discussion in DMPlexGetAdjacencyUseCone() and DMPlexGetAdjacencyUseClosure()
881a6cbbb48SMatthew G. Knepley 
882a6cbbb48SMatthew G. Knepley   Level: developer
883a6cbbb48SMatthew G. Knepley 
884f744cafaSSander Arens .seealso: PetscDSGetAdjacency(), DMPlexGetAdjacencyUseCone(), DMPlexGetAdjacencyUseClosure(), PetscDSSetDiscretization(), PetscDSAddDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
885a6cbbb48SMatthew G. Knepley @*/
886a6cbbb48SMatthew G. Knepley PetscErrorCode PetscDSSetAdjacency(PetscDS prob, PetscInt f, PetscBool useCone, PetscBool useClosure)
887a6cbbb48SMatthew G. Knepley {
888a6cbbb48SMatthew G. Knepley   PetscFunctionBegin;
889a6cbbb48SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
89006cc46feSMatthew G. Knepley   if (f < 0) {
89106cc46feSMatthew G. Knepley     prob->defaultAdj[0] = useCone;
89206cc46feSMatthew G. Knepley     prob->defaultAdj[1] = useClosure;
89306cc46feSMatthew G. Knepley   } else {
89406cc46feSMatthew G. Knepley     if (f >= prob->Nf) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be in [0, %d)", f, prob->Nf);
895a6cbbb48SMatthew G. Knepley     prob->adjacency[f*2+0] = useCone;
896a6cbbb48SMatthew G. Knepley     prob->adjacency[f*2+1] = useClosure;
89706cc46feSMatthew G. Knepley   }
898a6cbbb48SMatthew G. Knepley   PetscFunctionReturn(0);
899a6cbbb48SMatthew G. Knepley }
900a6cbbb48SMatthew G. Knepley 
9012764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetObjective(PetscDS prob, PetscInt f,
90230b9ff8bSMatthew G. Knepley                                    void (**obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
903194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
904194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
90597b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
9062764a2aaSMatthew G. Knepley {
9072764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9082764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9092764a2aaSMatthew G. Knepley   PetscValidPointer(obj, 2);
9102764a2aaSMatthew 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);
9112764a2aaSMatthew G. Knepley   *obj = prob->obj[f];
9122764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9132764a2aaSMatthew G. Knepley }
9142764a2aaSMatthew G. Knepley 
9152764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetObjective(PetscDS prob, PetscInt f,
91630b9ff8bSMatthew G. Knepley                                    void (*obj)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
917194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
918194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
91997b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar obj[]))
9202764a2aaSMatthew G. Knepley {
9212764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
9222764a2aaSMatthew G. Knepley 
9232764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9242764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
925de716cbcSToby Isaac   if (obj) PetscValidFunction(obj, 2);
9262764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
9272764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
9282764a2aaSMatthew G. Knepley   prob->obj[f] = obj;
9292764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9302764a2aaSMatthew G. Knepley }
9312764a2aaSMatthew G. Knepley 
932194d53e6SMatthew G. Knepley /*@C
933194d53e6SMatthew G. Knepley   PetscDSGetResidual - Get the pointwise residual function for a given test field
934194d53e6SMatthew G. Knepley 
935194d53e6SMatthew G. Knepley   Not collective
936194d53e6SMatthew G. Knepley 
937194d53e6SMatthew G. Knepley   Input Parameters:
938194d53e6SMatthew G. Knepley + prob - The PetscDS
939194d53e6SMatthew G. Knepley - f    - The test field number
940194d53e6SMatthew G. Knepley 
941194d53e6SMatthew G. Knepley   Output Parameters:
942194d53e6SMatthew G. Knepley + f0 - integrand for the test function term
943194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
944194d53e6SMatthew G. Knepley 
945194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
946194d53e6SMatthew G. Knepley 
947194d53e6SMatthew 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)
948194d53e6SMatthew G. Knepley 
949194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
950194d53e6SMatthew G. Knepley 
95130b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
952194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
953194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
95430b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
955194d53e6SMatthew G. Knepley 
956194d53e6SMatthew G. Knepley + dim - the spatial dimension
957194d53e6SMatthew G. Knepley . Nf - the number of fields
958194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
959194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
960194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
961194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
962194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
963194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
964194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
965194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
966194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
967194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
968194d53e6SMatthew G. Knepley . t - current time
969194d53e6SMatthew G. Knepley . x - coordinates of the current point
97097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
97197b6e6e8SMatthew G. Knepley . constants - constant parameters
972194d53e6SMatthew G. Knepley - f0 - output values at the current point
973194d53e6SMatthew G. Knepley 
974194d53e6SMatthew G. Knepley   Level: intermediate
975194d53e6SMatthew G. Knepley 
976194d53e6SMatthew G. Knepley .seealso: PetscDSSetResidual()
977194d53e6SMatthew G. Knepley @*/
9782764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetResidual(PetscDS prob, PetscInt f,
97930b9ff8bSMatthew G. Knepley                                   void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
980194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
981194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
98297b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
98330b9ff8bSMatthew G. Knepley                                   void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
984194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
985194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
98697b6e6e8SMatthew G. Knepley                                               PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
9872764a2aaSMatthew G. Knepley {
9882764a2aaSMatthew G. Knepley   PetscFunctionBegin;
9892764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
9902764a2aaSMatthew 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);
9912764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->f[f*2+0];}
9922764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->f[f*2+1];}
9932764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
9942764a2aaSMatthew G. Knepley }
9952764a2aaSMatthew G. Knepley 
996194d53e6SMatthew G. Knepley /*@C
997194d53e6SMatthew G. Knepley   PetscDSSetResidual - Set the pointwise residual function for a given test field
998194d53e6SMatthew G. Knepley 
999194d53e6SMatthew G. Knepley   Not collective
1000194d53e6SMatthew G. Knepley 
1001194d53e6SMatthew G. Knepley   Input Parameters:
1002194d53e6SMatthew G. Knepley + prob - The PetscDS
1003194d53e6SMatthew G. Knepley . f    - The test field number
1004194d53e6SMatthew G. Knepley . f0 - integrand for the test function term
1005194d53e6SMatthew G. Knepley - f1 - integrand for the test function gradient term
1006194d53e6SMatthew G. Knepley 
1007194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1008194d53e6SMatthew G. Knepley 
1009194d53e6SMatthew 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)
1010194d53e6SMatthew G. Knepley 
1011194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1012194d53e6SMatthew G. Knepley 
101330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1014194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1015194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
101630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar f0[])
1017194d53e6SMatthew G. Knepley 
1018194d53e6SMatthew G. Knepley + dim - the spatial dimension
1019194d53e6SMatthew G. Knepley . Nf - the number of fields
1020194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1021194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1022194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1023194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1024194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1025194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1026194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1027194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1028194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1029194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1030194d53e6SMatthew G. Knepley . t - current time
1031194d53e6SMatthew G. Knepley . x - coordinates of the current point
103297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
103397b6e6e8SMatthew G. Knepley . constants - constant parameters
1034194d53e6SMatthew G. Knepley - f0 - output values at the current point
1035194d53e6SMatthew G. Knepley 
1036194d53e6SMatthew G. Knepley   Level: intermediate
1037194d53e6SMatthew G. Knepley 
1038194d53e6SMatthew G. Knepley .seealso: PetscDSGetResidual()
1039194d53e6SMatthew G. Knepley @*/
10402764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetResidual(PetscDS prob, PetscInt f,
104130b9ff8bSMatthew G. Knepley                                   void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1042194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1043194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
104497b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
104530b9ff8bSMatthew G. Knepley                                   void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1046194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1047194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
104897b6e6e8SMatthew G. Knepley                                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
10492764a2aaSMatthew G. Knepley {
10502764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
10512764a2aaSMatthew G. Knepley 
10522764a2aaSMatthew G. Knepley   PetscFunctionBegin;
10532764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1054f866a1d0SMatthew G. Knepley   if (f0) PetscValidFunction(f0, 3);
1055f866a1d0SMatthew G. Knepley   if (f1) PetscValidFunction(f1, 4);
10562764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
10572764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
10582764a2aaSMatthew G. Knepley   prob->f[f*2+0] = f0;
10592764a2aaSMatthew G. Knepley   prob->f[f*2+1] = f1;
10602764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
10612764a2aaSMatthew G. Knepley }
10622764a2aaSMatthew G. Knepley 
10633e75805dSMatthew G. Knepley /*@C
10643e75805dSMatthew G. Knepley   PetscDSHasJacobian - Signals that Jacobian functions have been set
10653e75805dSMatthew G. Knepley 
10663e75805dSMatthew G. Knepley   Not collective
10673e75805dSMatthew G. Knepley 
10683e75805dSMatthew G. Knepley   Input Parameter:
10693e75805dSMatthew G. Knepley . prob - The PetscDS
10703e75805dSMatthew G. Knepley 
10713e75805dSMatthew G. Knepley   Output Parameter:
10723e75805dSMatthew G. Knepley . hasJac - flag that pointwise function for the Jacobian has been set
10733e75805dSMatthew G. Knepley 
10743e75805dSMatthew G. Knepley   Level: intermediate
10753e75805dSMatthew G. Knepley 
10763e75805dSMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
10773e75805dSMatthew G. Knepley @*/
10783e75805dSMatthew G. Knepley PetscErrorCode PetscDSHasJacobian(PetscDS prob, PetscBool *hasJac)
10793e75805dSMatthew G. Knepley {
10803e75805dSMatthew G. Knepley   PetscInt f, g, h;
10813e75805dSMatthew G. Knepley 
10823e75805dSMatthew G. Knepley   PetscFunctionBegin;
10833e75805dSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
10843e75805dSMatthew G. Knepley   *hasJac = PETSC_FALSE;
10853e75805dSMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
10863e75805dSMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
10873e75805dSMatthew G. Knepley       for (h = 0; h < 4; ++h) {
10883e75805dSMatthew G. Knepley         if (prob->g[(f*prob->Nf + g)*4+h]) *hasJac = PETSC_TRUE;
10893e75805dSMatthew G. Knepley       }
10903e75805dSMatthew G. Knepley     }
10913e75805dSMatthew G. Knepley   }
10923e75805dSMatthew G. Knepley   PetscFunctionReturn(0);
10933e75805dSMatthew G. Knepley }
10943e75805dSMatthew G. Knepley 
1095194d53e6SMatthew G. Knepley /*@C
1096194d53e6SMatthew G. Knepley   PetscDSGetJacobian - Get the pointwise Jacobian function for given test and basis field
1097194d53e6SMatthew G. Knepley 
1098194d53e6SMatthew G. Knepley   Not collective
1099194d53e6SMatthew G. Knepley 
1100194d53e6SMatthew G. Knepley   Input Parameters:
1101194d53e6SMatthew G. Knepley + prob - The PetscDS
1102194d53e6SMatthew G. Knepley . f    - The test field number
1103194d53e6SMatthew G. Knepley - g    - The field number
1104194d53e6SMatthew G. Knepley 
1105194d53e6SMatthew G. Knepley   Output Parameters:
1106194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
1107194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1108194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1109194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1110194d53e6SMatthew G. Knepley 
1111194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1112194d53e6SMatthew G. Knepley 
1113194d53e6SMatthew 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
1114194d53e6SMatthew G. Knepley 
1115194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1116194d53e6SMatthew G. Knepley 
111730b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1118194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1119194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
112030b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1121194d53e6SMatthew G. Knepley 
1122194d53e6SMatthew G. Knepley + dim - the spatial dimension
1123194d53e6SMatthew G. Knepley . Nf - the number of fields
1124194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1125194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1126194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1127194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1128194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1129194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1130194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1131194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1132194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1133194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1134194d53e6SMatthew G. Knepley . t - current time
11352aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1136194d53e6SMatthew G. Knepley . x - coordinates of the current point
113797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
113897b6e6e8SMatthew G. Knepley . constants - constant parameters
1139194d53e6SMatthew G. Knepley - g0 - output values at the current point
1140194d53e6SMatthew G. Knepley 
1141194d53e6SMatthew G. Knepley   Level: intermediate
1142194d53e6SMatthew G. Knepley 
1143194d53e6SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1144194d53e6SMatthew G. Knepley @*/
11452764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetJacobian(PetscDS prob, PetscInt f, PetscInt g,
114630b9ff8bSMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1147194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1148194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
114997b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
115030b9ff8bSMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1151194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1152194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
115397b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
115430b9ff8bSMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1155194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1156194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
115797b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
115830b9ff8bSMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1159194d53e6SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1160194d53e6SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
116197b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
11622764a2aaSMatthew G. Knepley {
11632764a2aaSMatthew G. Knepley   PetscFunctionBegin;
11642764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
11652764a2aaSMatthew 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);
11662764a2aaSMatthew 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);
11672764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g[(f*prob->Nf + g)*4+0];}
11682764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g[(f*prob->Nf + g)*4+1];}
11692764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g[(f*prob->Nf + g)*4+2];}
11702764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g[(f*prob->Nf + g)*4+3];}
11712764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
11722764a2aaSMatthew G. Knepley }
11732764a2aaSMatthew G. Knepley 
1174194d53e6SMatthew G. Knepley /*@C
1175194d53e6SMatthew G. Knepley   PetscDSSetJacobian - Set the pointwise Jacobian function for given test and basis fields
1176194d53e6SMatthew G. Knepley 
1177194d53e6SMatthew G. Knepley   Not collective
1178194d53e6SMatthew G. Knepley 
1179194d53e6SMatthew G. Knepley   Input Parameters:
1180194d53e6SMatthew G. Knepley + prob - The PetscDS
1181194d53e6SMatthew G. Knepley . f    - The test field number
1182194d53e6SMatthew G. Knepley . g    - The field number
1183194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
1184194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1185194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1186194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1187194d53e6SMatthew G. Knepley 
1188194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1189194d53e6SMatthew G. Knepley 
1190194d53e6SMatthew 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
1191194d53e6SMatthew G. Knepley 
1192194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1193194d53e6SMatthew G. Knepley 
119430b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1195194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1196194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
119730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1198194d53e6SMatthew G. Knepley 
1199194d53e6SMatthew G. Knepley + dim - the spatial dimension
1200194d53e6SMatthew G. Knepley . Nf - the number of fields
1201194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1202194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1203194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1204194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1205194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1206194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1207194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1208194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1209194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1210194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1211194d53e6SMatthew G. Knepley . t - current time
12122aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1213194d53e6SMatthew G. Knepley . x - coordinates of the current point
121497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
121597b6e6e8SMatthew G. Knepley . constants - constant parameters
1216194d53e6SMatthew G. Knepley - g0 - output values at the current point
1217194d53e6SMatthew G. Knepley 
1218194d53e6SMatthew G. Knepley   Level: intermediate
1219194d53e6SMatthew G. Knepley 
1220194d53e6SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1221194d53e6SMatthew G. Knepley @*/
12222764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetJacobian(PetscDS prob, PetscInt f, PetscInt g,
122330b9ff8bSMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1224194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1225194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
122697b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
122730b9ff8bSMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1228194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1229194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123097b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
123130b9ff8bSMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1232194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1233194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123497b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
123530b9ff8bSMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1236194d53e6SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1237194d53e6SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
123897b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
12392764a2aaSMatthew G. Knepley {
12402764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
12412764a2aaSMatthew G. Knepley 
12422764a2aaSMatthew G. Knepley   PetscFunctionBegin;
12432764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
12442764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
12452764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
12462764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
12472764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
12482764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
12492764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
12502764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
12512764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+0] = g0;
12522764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+1] = g1;
12532764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+2] = g2;
12542764a2aaSMatthew G. Knepley   prob->g[(f*prob->Nf + g)*4+3] = g3;
12552764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
12562764a2aaSMatthew G. Knepley }
12572764a2aaSMatthew G. Knepley 
1258475e0ac9SMatthew G. Knepley /*@C
1259475e0ac9SMatthew G. Knepley   PetscDSHasJacobianPreconditioner - Signals that a Jacobian preconditioner matrix has been set
1260475e0ac9SMatthew G. Knepley 
1261475e0ac9SMatthew G. Knepley   Not collective
1262475e0ac9SMatthew G. Knepley 
1263475e0ac9SMatthew G. Knepley   Input Parameter:
1264475e0ac9SMatthew G. Knepley . prob - The PetscDS
1265475e0ac9SMatthew G. Knepley 
1266475e0ac9SMatthew G. Knepley   Output Parameter:
1267475e0ac9SMatthew G. Knepley . hasJacPre - flag that pointwise function for Jacobian preconditioner matrix has been set
1268475e0ac9SMatthew G. Knepley 
1269475e0ac9SMatthew G. Knepley   Level: intermediate
1270475e0ac9SMatthew G. Knepley 
1271475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1272475e0ac9SMatthew G. Knepley @*/
1273475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSHasJacobianPreconditioner(PetscDS prob, PetscBool *hasJacPre)
1274475e0ac9SMatthew G. Knepley {
1275475e0ac9SMatthew G. Knepley   PetscInt f, g, h;
1276475e0ac9SMatthew G. Knepley 
1277475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1278475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1279475e0ac9SMatthew G. Knepley   *hasJacPre = PETSC_FALSE;
1280475e0ac9SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1281475e0ac9SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1282475e0ac9SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1283475e0ac9SMatthew G. Knepley         if (prob->gp[(f*prob->Nf + g)*4+h]) *hasJacPre = PETSC_TRUE;
1284475e0ac9SMatthew G. Knepley       }
1285475e0ac9SMatthew G. Knepley     }
1286475e0ac9SMatthew G. Knepley   }
1287475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1288475e0ac9SMatthew G. Knepley }
1289475e0ac9SMatthew G. Knepley 
1290475e0ac9SMatthew G. Knepley /*@C
1291475e0ac9SMatthew 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.
1292475e0ac9SMatthew G. Knepley 
1293475e0ac9SMatthew G. Knepley   Not collective
1294475e0ac9SMatthew G. Knepley 
1295475e0ac9SMatthew G. Knepley   Input Parameters:
1296475e0ac9SMatthew G. Knepley + prob - The PetscDS
1297475e0ac9SMatthew G. Knepley . f    - The test field number
1298475e0ac9SMatthew G. Knepley - g    - The field number
1299475e0ac9SMatthew G. Knepley 
1300475e0ac9SMatthew G. Knepley   Output Parameters:
1301475e0ac9SMatthew G. Knepley + g0 - integrand for the test and basis function term
1302475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1303475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1304475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1305475e0ac9SMatthew G. Knepley 
1306475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1307475e0ac9SMatthew G. Knepley 
1308475e0ac9SMatthew 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
1309475e0ac9SMatthew G. Knepley 
1310475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1311475e0ac9SMatthew G. Knepley 
1312475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1313475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1314475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1315475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1316475e0ac9SMatthew G. Knepley 
1317475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1318475e0ac9SMatthew G. Knepley . Nf - the number of fields
1319475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1320475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1321475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1322475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1323475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1324475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1325475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1326475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1327475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1328475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1329475e0ac9SMatthew G. Knepley . t - current time
1330475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1331475e0ac9SMatthew G. Knepley . x - coordinates of the current point
133297b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
133397b6e6e8SMatthew G. Knepley . constants - constant parameters
1334475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1335475e0ac9SMatthew G. Knepley 
1336475e0ac9SMatthew G. Knepley   Level: intermediate
1337475e0ac9SMatthew G. Knepley 
1338475e0ac9SMatthew G. Knepley .seealso: PetscDSSetJacobianPreconditioner(), PetscDSGetJacobian()
1339475e0ac9SMatthew G. Knepley @*/
1340475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSGetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1341475e0ac9SMatthew G. Knepley                                   void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1342475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1343475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
134497b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1345475e0ac9SMatthew G. Knepley                                   void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1346475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1347475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
134897b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1349475e0ac9SMatthew G. Knepley                                   void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1350475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1351475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
135297b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1353475e0ac9SMatthew G. Knepley                                   void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1354475e0ac9SMatthew G. Knepley                                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1355475e0ac9SMatthew G. Knepley                                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
135697b6e6e8SMatthew G. Knepley                                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1357475e0ac9SMatthew G. Knepley {
1358475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1359475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1360475e0ac9SMatthew 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);
1361475e0ac9SMatthew 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);
1362475e0ac9SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gp[(f*prob->Nf + g)*4+0];}
1363475e0ac9SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gp[(f*prob->Nf + g)*4+1];}
1364475e0ac9SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gp[(f*prob->Nf + g)*4+2];}
1365475e0ac9SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gp[(f*prob->Nf + g)*4+3];}
1366475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1367475e0ac9SMatthew G. Knepley }
1368475e0ac9SMatthew G. Knepley 
1369475e0ac9SMatthew G. Knepley /*@C
1370475e0ac9SMatthew 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.
1371475e0ac9SMatthew G. Knepley 
1372475e0ac9SMatthew G. Knepley   Not collective
1373475e0ac9SMatthew G. Knepley 
1374475e0ac9SMatthew G. Knepley   Input Parameters:
1375475e0ac9SMatthew G. Knepley + prob - The PetscDS
1376475e0ac9SMatthew G. Knepley . f    - The test field number
1377475e0ac9SMatthew G. Knepley . g    - The field number
1378475e0ac9SMatthew G. Knepley . g0 - integrand for the test and basis function term
1379475e0ac9SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1380475e0ac9SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1381475e0ac9SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1382475e0ac9SMatthew G. Knepley 
1383475e0ac9SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1384475e0ac9SMatthew G. Knepley 
1385475e0ac9SMatthew 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
1386475e0ac9SMatthew G. Knepley 
1387475e0ac9SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1388475e0ac9SMatthew G. Knepley 
1389475e0ac9SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1390475e0ac9SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1391475e0ac9SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1392475e0ac9SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1393475e0ac9SMatthew G. Knepley 
1394475e0ac9SMatthew G. Knepley + dim - the spatial dimension
1395475e0ac9SMatthew G. Knepley . Nf - the number of fields
1396475e0ac9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1397475e0ac9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1398475e0ac9SMatthew G. Knepley . u - each field evaluated at the current point
1399475e0ac9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1400475e0ac9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1401475e0ac9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1402475e0ac9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1403475e0ac9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1404475e0ac9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1405475e0ac9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1406475e0ac9SMatthew G. Knepley . t - current time
1407475e0ac9SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1408475e0ac9SMatthew G. Knepley . x - coordinates of the current point
140997b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
141097b6e6e8SMatthew G. Knepley . constants - constant parameters
1411475e0ac9SMatthew G. Knepley - g0 - output values at the current point
1412475e0ac9SMatthew G. Knepley 
1413475e0ac9SMatthew G. Knepley   Level: intermediate
1414475e0ac9SMatthew G. Knepley 
1415475e0ac9SMatthew G. Knepley .seealso: PetscDSGetJacobianPreconditioner(), PetscDSSetJacobian()
1416475e0ac9SMatthew G. Knepley @*/
1417475e0ac9SMatthew G. Knepley PetscErrorCode PetscDSSetJacobianPreconditioner(PetscDS prob, PetscInt f, PetscInt g,
1418475e0ac9SMatthew G. Knepley                                   void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1419475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1420475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
142197b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1422475e0ac9SMatthew G. Knepley                                   void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1423475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1424475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
142597b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1426475e0ac9SMatthew G. Knepley                                   void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1427475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1428475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
142997b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1430475e0ac9SMatthew G. Knepley                                   void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1431475e0ac9SMatthew G. Knepley                                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1432475e0ac9SMatthew G. Knepley                                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
143397b6e6e8SMatthew G. Knepley                                              PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1434475e0ac9SMatthew G. Knepley {
1435475e0ac9SMatthew G. Knepley   PetscErrorCode ierr;
1436475e0ac9SMatthew G. Knepley 
1437475e0ac9SMatthew G. Knepley   PetscFunctionBegin;
1438475e0ac9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1439475e0ac9SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1440475e0ac9SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1441475e0ac9SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1442475e0ac9SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1443475e0ac9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1444475e0ac9SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1445475e0ac9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1446475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+0] = g0;
1447475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+1] = g1;
1448475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+2] = g2;
1449475e0ac9SMatthew G. Knepley   prob->gp[(f*prob->Nf + g)*4+3] = g3;
1450475e0ac9SMatthew G. Knepley   PetscFunctionReturn(0);
1451475e0ac9SMatthew G. Knepley }
1452475e0ac9SMatthew G. Knepley 
1453b7e05686SMatthew G. Knepley /*@C
1454b7e05686SMatthew G. Knepley   PetscDSHasDynamicJacobian - Signals that a dynamic Jacobian, dF/du_t, has been set
1455b7e05686SMatthew G. Knepley 
1456b7e05686SMatthew G. Knepley   Not collective
1457b7e05686SMatthew G. Knepley 
1458b7e05686SMatthew G. Knepley   Input Parameter:
1459b7e05686SMatthew G. Knepley . prob - The PetscDS
1460b7e05686SMatthew G. Knepley 
1461b7e05686SMatthew G. Knepley   Output Parameter:
1462b7e05686SMatthew G. Knepley . hasDynJac - flag that pointwise function for dynamic Jacobian has been set
1463b7e05686SMatthew G. Knepley 
1464b7e05686SMatthew G. Knepley   Level: intermediate
1465b7e05686SMatthew G. Knepley 
1466b7e05686SMatthew G. Knepley .seealso: PetscDSGetDynamicJacobian(), PetscDSSetDynamicJacobian(), PetscDSGetJacobian()
1467b7e05686SMatthew G. Knepley @*/
1468b7e05686SMatthew G. Knepley PetscErrorCode PetscDSHasDynamicJacobian(PetscDS prob, PetscBool *hasDynJac)
1469b7e05686SMatthew G. Knepley {
1470b7e05686SMatthew G. Knepley   PetscInt f, g, h;
1471b7e05686SMatthew G. Knepley 
1472b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1473b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1474b7e05686SMatthew G. Knepley   *hasDynJac = PETSC_FALSE;
1475b7e05686SMatthew G. Knepley   for (f = 0; f < prob->Nf; ++f) {
1476b7e05686SMatthew G. Knepley     for (g = 0; g < prob->Nf; ++g) {
1477b7e05686SMatthew G. Knepley       for (h = 0; h < 4; ++h) {
1478b7e05686SMatthew G. Knepley         if (prob->gt[(f*prob->Nf + g)*4+h]) *hasDynJac = PETSC_TRUE;
1479b7e05686SMatthew G. Knepley       }
1480b7e05686SMatthew G. Knepley     }
1481b7e05686SMatthew G. Knepley   }
1482b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1483b7e05686SMatthew G. Knepley }
1484b7e05686SMatthew G. Knepley 
1485b7e05686SMatthew G. Knepley /*@C
1486b7e05686SMatthew G. Knepley   PetscDSGetDynamicJacobian - Get the pointwise dynamic Jacobian, dF/du_t, function for given test and basis field
1487b7e05686SMatthew G. Knepley 
1488b7e05686SMatthew G. Knepley   Not collective
1489b7e05686SMatthew G. Knepley 
1490b7e05686SMatthew G. Knepley   Input Parameters:
1491b7e05686SMatthew G. Knepley + prob - The PetscDS
1492b7e05686SMatthew G. Knepley . f    - The test field number
1493b7e05686SMatthew G. Knepley - g    - The field number
1494b7e05686SMatthew G. Knepley 
1495b7e05686SMatthew G. Knepley   Output Parameters:
1496b7e05686SMatthew G. Knepley + g0 - integrand for the test and basis function term
1497b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1498b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1499b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1500b7e05686SMatthew G. Knepley 
1501b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1502b7e05686SMatthew G. Knepley 
1503b7e05686SMatthew 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
1504b7e05686SMatthew G. Knepley 
1505b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1506b7e05686SMatthew G. Knepley 
1507b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1508b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1509b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1510b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal u_tShift, const PetscReal x[], PetscScalar g0[])
1511b7e05686SMatthew G. Knepley 
1512b7e05686SMatthew G. Knepley + dim - the spatial dimension
1513b7e05686SMatthew G. Knepley . Nf - the number of fields
1514b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1515b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1516b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1517b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1518b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1519b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1520b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1521b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1522b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1523b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1524b7e05686SMatthew G. Knepley . t - current time
1525b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1526b7e05686SMatthew G. Knepley . x - coordinates of the current point
152797b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
152897b6e6e8SMatthew G. Knepley . constants - constant parameters
1529b7e05686SMatthew G. Knepley - g0 - output values at the current point
1530b7e05686SMatthew G. Knepley 
1531b7e05686SMatthew G. Knepley   Level: intermediate
1532b7e05686SMatthew G. Knepley 
1533b7e05686SMatthew G. Knepley .seealso: PetscDSSetJacobian()
1534b7e05686SMatthew G. Knepley @*/
1535b7e05686SMatthew G. Knepley PetscErrorCode PetscDSGetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1536b7e05686SMatthew G. Knepley                                          void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1537b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1538b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
153997b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1540b7e05686SMatthew G. Knepley                                          void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1541b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1542b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154397b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1544b7e05686SMatthew G. Knepley                                          void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1545b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1546b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
154797b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1548b7e05686SMatthew G. Knepley                                          void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1549b7e05686SMatthew G. Knepley                                                      const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1550b7e05686SMatthew G. Knepley                                                      const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
155197b6e6e8SMatthew G. Knepley                                                      PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1552b7e05686SMatthew G. Knepley {
1553b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1554b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1555b7e05686SMatthew 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);
1556b7e05686SMatthew 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);
1557b7e05686SMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gt[(f*prob->Nf + g)*4+0];}
1558b7e05686SMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gt[(f*prob->Nf + g)*4+1];}
1559b7e05686SMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gt[(f*prob->Nf + g)*4+2];}
1560b7e05686SMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gt[(f*prob->Nf + g)*4+3];}
1561b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1562b7e05686SMatthew G. Knepley }
1563b7e05686SMatthew G. Knepley 
1564b7e05686SMatthew G. Knepley /*@C
1565b7e05686SMatthew G. Knepley   PetscDSSetDynamicJacobian - Set the pointwise dynamic Jacobian, dF/du_t, function for given test and basis fields
1566b7e05686SMatthew G. Knepley 
1567b7e05686SMatthew G. Knepley   Not collective
1568b7e05686SMatthew G. Knepley 
1569b7e05686SMatthew G. Knepley   Input Parameters:
1570b7e05686SMatthew G. Knepley + prob - The PetscDS
1571b7e05686SMatthew G. Knepley . f    - The test field number
1572b7e05686SMatthew G. Knepley . g    - The field number
1573b7e05686SMatthew G. Knepley . g0 - integrand for the test and basis function term
1574b7e05686SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
1575b7e05686SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
1576b7e05686SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
1577b7e05686SMatthew G. Knepley 
1578b7e05686SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1579b7e05686SMatthew G. Knepley 
1580b7e05686SMatthew 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
1581b7e05686SMatthew G. Knepley 
1582b7e05686SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
1583b7e05686SMatthew G. Knepley 
1584b7e05686SMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1585b7e05686SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1586b7e05686SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
1587b7e05686SMatthew G. Knepley $    PetscReal t, const PetscReal x[], PetscScalar g0[])
1588b7e05686SMatthew G. Knepley 
1589b7e05686SMatthew G. Knepley + dim - the spatial dimension
1590b7e05686SMatthew G. Knepley . Nf - the number of fields
1591b7e05686SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1592b7e05686SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1593b7e05686SMatthew G. Knepley . u - each field evaluated at the current point
1594b7e05686SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1595b7e05686SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1596b7e05686SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1597b7e05686SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1598b7e05686SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1599b7e05686SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1600b7e05686SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1601b7e05686SMatthew G. Knepley . t - current time
1602b7e05686SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
1603b7e05686SMatthew G. Knepley . x - coordinates of the current point
160497b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
160597b6e6e8SMatthew G. Knepley . constants - constant parameters
1606b7e05686SMatthew G. Knepley - g0 - output values at the current point
1607b7e05686SMatthew G. Knepley 
1608b7e05686SMatthew G. Knepley   Level: intermediate
1609b7e05686SMatthew G. Knepley 
1610b7e05686SMatthew G. Knepley .seealso: PetscDSGetJacobian()
1611b7e05686SMatthew G. Knepley @*/
1612b7e05686SMatthew G. Knepley PetscErrorCode PetscDSSetDynamicJacobian(PetscDS prob, PetscInt f, PetscInt g,
1613b7e05686SMatthew G. Knepley                                          void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1614b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1615b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
161697b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
1617b7e05686SMatthew G. Knepley                                          void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1618b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1619b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162097b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
1621b7e05686SMatthew G. Knepley                                          void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1622b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1623b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162497b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
1625b7e05686SMatthew G. Knepley                                          void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1626b7e05686SMatthew G. Knepley                                                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1627b7e05686SMatthew G. Knepley                                                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
162897b6e6e8SMatthew G. Knepley                                                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
1629b7e05686SMatthew G. Knepley {
1630b7e05686SMatthew G. Knepley   PetscErrorCode ierr;
1631b7e05686SMatthew G. Knepley 
1632b7e05686SMatthew G. Knepley   PetscFunctionBegin;
1633b7e05686SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1634b7e05686SMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
1635b7e05686SMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
1636b7e05686SMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
1637b7e05686SMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
1638b7e05686SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
1639b7e05686SMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
1640b7e05686SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
1641b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+0] = g0;
1642b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+1] = g1;
1643b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+2] = g2;
1644b7e05686SMatthew G. Knepley   prob->gt[(f*prob->Nf + g)*4+3] = g3;
1645b7e05686SMatthew G. Knepley   PetscFunctionReturn(0);
1646b7e05686SMatthew G. Knepley }
1647b7e05686SMatthew G. Knepley 
16480c2f2876SMatthew G. Knepley /*@C
16490c2f2876SMatthew G. Knepley   PetscDSGetRiemannSolver - Returns the Riemann solver for the given field
16500c2f2876SMatthew G. Knepley 
16510c2f2876SMatthew G. Knepley   Not collective
16520c2f2876SMatthew G. Knepley 
16530c2f2876SMatthew G. Knepley   Input Arguments:
16540c2f2876SMatthew G. Knepley + prob - The PetscDS object
16550c2f2876SMatthew G. Knepley - f    - The field number
16560c2f2876SMatthew G. Knepley 
16570c2f2876SMatthew G. Knepley   Output Argument:
16580c2f2876SMatthew G. Knepley . r    - Riemann solver
16590c2f2876SMatthew G. Knepley 
16600c2f2876SMatthew G. Knepley   Calling sequence for r:
16610c2f2876SMatthew G. Knepley 
16625db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
16630c2f2876SMatthew G. Knepley 
16645db36cf9SMatthew G. Knepley + dim  - The spatial dimension
16655db36cf9SMatthew G. Knepley . Nf   - The number of fields
16665db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
16670c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
16680c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
16690c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
16700c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
167197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
167297b6e6e8SMatthew G. Knepley . constants - constant parameters
16730c2f2876SMatthew G. Knepley - ctx  - optional user context
16740c2f2876SMatthew G. Knepley 
16750c2f2876SMatthew G. Knepley   Level: intermediate
16760c2f2876SMatthew G. Knepley 
16770c2f2876SMatthew G. Knepley .seealso: PetscDSSetRiemannSolver()
16780c2f2876SMatthew G. Knepley @*/
16790c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetRiemannSolver(PetscDS prob, PetscInt f,
168097b6e6e8SMatthew 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))
16810c2f2876SMatthew G. Knepley {
16820c2f2876SMatthew G. Knepley   PetscFunctionBegin;
16830c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
16840c2f2876SMatthew 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);
16850c2f2876SMatthew G. Knepley   PetscValidPointer(r, 3);
16860c2f2876SMatthew G. Knepley   *r = prob->r[f];
16870c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
16880c2f2876SMatthew G. Knepley }
16890c2f2876SMatthew G. Knepley 
16900c2f2876SMatthew G. Knepley /*@C
16910c2f2876SMatthew G. Knepley   PetscDSSetRiemannSolver - Sets the Riemann solver for the given field
16920c2f2876SMatthew G. Knepley 
16930c2f2876SMatthew G. Knepley   Not collective
16940c2f2876SMatthew G. Knepley 
16950c2f2876SMatthew G. Knepley   Input Arguments:
16960c2f2876SMatthew G. Knepley + prob - The PetscDS object
16970c2f2876SMatthew G. Knepley . f    - The field number
16980c2f2876SMatthew G. Knepley - r    - Riemann solver
16990c2f2876SMatthew G. Knepley 
17000c2f2876SMatthew G. Knepley   Calling sequence for r:
17010c2f2876SMatthew G. Knepley 
17025db36cf9SMatthew G. Knepley $ r(PetscInt dim, PetscInt Nf, const PetscReal x[], const PetscReal n[], const PetscScalar uL[], const PetscScalar uR[], PetscScalar flux[], void *ctx)
17030c2f2876SMatthew G. Knepley 
17045db36cf9SMatthew G. Knepley + dim  - The spatial dimension
17055db36cf9SMatthew G. Knepley . Nf   - The number of fields
17065db36cf9SMatthew G. Knepley . x    - The coordinates at a point on the interface
17070c2f2876SMatthew G. Knepley . n    - The normal vector to the interface
17080c2f2876SMatthew G. Knepley . uL   - The state vector to the left of the interface
17090c2f2876SMatthew G. Knepley . uR   - The state vector to the right of the interface
17100c2f2876SMatthew G. Knepley . flux - output array of flux through the interface
171197b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
171297b6e6e8SMatthew G. Knepley . constants - constant parameters
17130c2f2876SMatthew G. Knepley - ctx  - optional user context
17140c2f2876SMatthew G. Knepley 
17150c2f2876SMatthew G. Knepley   Level: intermediate
17160c2f2876SMatthew G. Knepley 
17170c2f2876SMatthew G. Knepley .seealso: PetscDSGetRiemannSolver()
17180c2f2876SMatthew G. Knepley @*/
17190c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetRiemannSolver(PetscDS prob, PetscInt f,
172097b6e6e8SMatthew 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))
17210c2f2876SMatthew G. Knepley {
17220c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
17230c2f2876SMatthew G. Knepley 
17240c2f2876SMatthew G. Knepley   PetscFunctionBegin;
17250c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
1726de716cbcSToby Isaac   if (r) PetscValidFunction(r, 3);
17270c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
17280c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
17290c2f2876SMatthew G. Knepley   prob->r[f] = r;
17300c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
17310c2f2876SMatthew G. Knepley }
17320c2f2876SMatthew G. Knepley 
173332d2bbc9SMatthew G. Knepley /*@C
173432d2bbc9SMatthew G. Knepley   PetscDSGetUpdate - Get the pointwise update function for a given field
173532d2bbc9SMatthew G. Knepley 
173632d2bbc9SMatthew G. Knepley   Not collective
173732d2bbc9SMatthew G. Knepley 
173832d2bbc9SMatthew G. Knepley   Input Parameters:
173932d2bbc9SMatthew G. Knepley + prob - The PetscDS
174032d2bbc9SMatthew G. Knepley - f    - The field number
174132d2bbc9SMatthew G. Knepley 
174232d2bbc9SMatthew G. Knepley   Output Parameters:
174332d2bbc9SMatthew G. Knepley + update - update function
174432d2bbc9SMatthew G. Knepley 
174532d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
174632d2bbc9SMatthew G. Knepley 
174732d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
174832d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
174932d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
175032d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
175132d2bbc9SMatthew G. Knepley 
175232d2bbc9SMatthew G. Knepley + dim - the spatial dimension
175332d2bbc9SMatthew G. Knepley . Nf - the number of fields
175432d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
175532d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
175632d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
175732d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
175832d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
175932d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
176032d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
176132d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
176232d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
176332d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
176432d2bbc9SMatthew G. Knepley . t - current time
176532d2bbc9SMatthew G. Knepley . x - coordinates of the current point
176632d2bbc9SMatthew G. Knepley - uNew - new value for field at the current point
176732d2bbc9SMatthew G. Knepley 
176832d2bbc9SMatthew G. Knepley   Level: intermediate
176932d2bbc9SMatthew G. Knepley 
177032d2bbc9SMatthew G. Knepley .seealso: PetscDSSetUpdate(), PetscDSSetResidual()
177132d2bbc9SMatthew G. Knepley @*/
177232d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSGetUpdate(PetscDS prob, PetscInt f,
177332d2bbc9SMatthew G. Knepley                                   void (**update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
177432d2bbc9SMatthew G. Knepley                                                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
177532d2bbc9SMatthew G. Knepley                                                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
17763fa77dffSMatthew G. Knepley                                                   PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
177732d2bbc9SMatthew G. Knepley {
177832d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
177932d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
178032d2bbc9SMatthew 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);
178132d2bbc9SMatthew G. Knepley   if (update) {PetscValidPointer(update, 3); *update = prob->update[f];}
178232d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
178332d2bbc9SMatthew G. Knepley }
178432d2bbc9SMatthew G. Knepley 
178532d2bbc9SMatthew G. Knepley /*@C
17863fa77dffSMatthew G. Knepley   PetscDSSetUpdate - Set the pointwise update function for a given field
178732d2bbc9SMatthew G. Knepley 
178832d2bbc9SMatthew G. Knepley   Not collective
178932d2bbc9SMatthew G. Knepley 
179032d2bbc9SMatthew G. Knepley   Input Parameters:
179132d2bbc9SMatthew G. Knepley + prob   - The PetscDS
179232d2bbc9SMatthew G. Knepley . f      - The field number
179332d2bbc9SMatthew G. Knepley - update - update function
179432d2bbc9SMatthew G. Knepley 
179532d2bbc9SMatthew G. Knepley   Note: The calling sequence for the callback update is given by:
179632d2bbc9SMatthew G. Knepley 
179732d2bbc9SMatthew G. Knepley $ update(PetscInt dim, PetscInt Nf, PetscInt NfAux,
179832d2bbc9SMatthew G. Knepley $        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
179932d2bbc9SMatthew G. Knepley $        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
180032d2bbc9SMatthew G. Knepley $        PetscReal t, const PetscReal x[], PetscScalar uNew[])
180132d2bbc9SMatthew G. Knepley 
180232d2bbc9SMatthew G. Knepley + dim - the spatial dimension
180332d2bbc9SMatthew G. Knepley . Nf - the number of fields
180432d2bbc9SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
180532d2bbc9SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
180632d2bbc9SMatthew G. Knepley . u - each field evaluated at the current point
180732d2bbc9SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
180832d2bbc9SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
180932d2bbc9SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
181032d2bbc9SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
181132d2bbc9SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
181232d2bbc9SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
181332d2bbc9SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
181432d2bbc9SMatthew G. Knepley . t - current time
181532d2bbc9SMatthew G. Knepley . x - coordinates of the current point
181632d2bbc9SMatthew G. Knepley - uNew - new field values at the current point
181732d2bbc9SMatthew G. Knepley 
181832d2bbc9SMatthew G. Knepley   Level: intermediate
181932d2bbc9SMatthew G. Knepley 
182032d2bbc9SMatthew G. Knepley .seealso: PetscDSGetResidual()
182132d2bbc9SMatthew G. Knepley @*/
182232d2bbc9SMatthew G. Knepley PetscErrorCode PetscDSSetUpdate(PetscDS prob, PetscInt f,
182332d2bbc9SMatthew G. Knepley                                 void (*update)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
182432d2bbc9SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
182532d2bbc9SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
18263fa77dffSMatthew G. Knepley                                                PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uNew[]))
182732d2bbc9SMatthew G. Knepley {
182832d2bbc9SMatthew G. Knepley   PetscErrorCode ierr;
182932d2bbc9SMatthew G. Knepley 
183032d2bbc9SMatthew G. Knepley   PetscFunctionBegin;
183132d2bbc9SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
183232d2bbc9SMatthew G. Knepley   if (update) PetscValidFunction(update, 3);
183332d2bbc9SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
183432d2bbc9SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
183532d2bbc9SMatthew G. Knepley   prob->update[f] = update;
183632d2bbc9SMatthew G. Knepley   PetscFunctionReturn(0);
183732d2bbc9SMatthew G. Knepley }
183832d2bbc9SMatthew G. Knepley 
18390c2f2876SMatthew G. Knepley PetscErrorCode PetscDSGetContext(PetscDS prob, PetscInt f, void **ctx)
18400c2f2876SMatthew G. Knepley {
18410c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18420c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18430c2f2876SMatthew 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);
18440c2f2876SMatthew G. Knepley   PetscValidPointer(ctx, 3);
18450c2f2876SMatthew G. Knepley   *ctx = prob->ctx[f];
18460c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18470c2f2876SMatthew G. Knepley }
18480c2f2876SMatthew G. Knepley 
18490c2f2876SMatthew G. Knepley PetscErrorCode PetscDSSetContext(PetscDS prob, PetscInt f, void *ctx)
18500c2f2876SMatthew G. Knepley {
18510c2f2876SMatthew G. Knepley   PetscErrorCode ierr;
18520c2f2876SMatthew G. Knepley 
18530c2f2876SMatthew G. Knepley   PetscFunctionBegin;
18540c2f2876SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
18550c2f2876SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
18560c2f2876SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
18570c2f2876SMatthew G. Knepley   prob->ctx[f] = ctx;
18580c2f2876SMatthew G. Knepley   PetscFunctionReturn(0);
18590c2f2876SMatthew G. Knepley }
18600c2f2876SMatthew G. Knepley 
1861194d53e6SMatthew G. Knepley /*@C
1862194d53e6SMatthew G. Knepley   PetscDSGetBdResidual - Get the pointwise boundary residual function for a given test field
1863194d53e6SMatthew G. Knepley 
1864194d53e6SMatthew G. Knepley   Not collective
1865194d53e6SMatthew G. Knepley 
1866194d53e6SMatthew G. Knepley   Input Parameters:
1867194d53e6SMatthew G. Knepley + prob - The PetscDS
1868194d53e6SMatthew G. Knepley - f    - The test field number
1869194d53e6SMatthew G. Knepley 
1870194d53e6SMatthew G. Knepley   Output Parameters:
1871194d53e6SMatthew G. Knepley + f0 - boundary integrand for the test function term
1872194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1873194d53e6SMatthew G. Knepley 
1874194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1875194d53e6SMatthew G. Knepley 
1876194d53e6SMatthew 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
1877194d53e6SMatthew G. Knepley 
1878194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1879194d53e6SMatthew G. Knepley 
188030b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1881194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1882194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
188330b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1884194d53e6SMatthew G. Knepley 
1885194d53e6SMatthew G. Knepley + dim - the spatial dimension
1886194d53e6SMatthew G. Knepley . Nf - the number of fields
1887194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1888194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1889194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1890194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1891194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1892194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1893194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1894194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1895194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1896194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1897194d53e6SMatthew G. Knepley . t - current time
1898194d53e6SMatthew G. Knepley . x - coordinates of the current point
1899194d53e6SMatthew G. Knepley . n - unit normal at the current point
190097b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
190197b6e6e8SMatthew G. Knepley . constants - constant parameters
1902194d53e6SMatthew G. Knepley - f0 - output values at the current point
1903194d53e6SMatthew G. Knepley 
1904194d53e6SMatthew G. Knepley   Level: intermediate
1905194d53e6SMatthew G. Knepley 
1906194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdResidual()
1907194d53e6SMatthew G. Knepley @*/
19082764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdResidual(PetscDS prob, PetscInt f,
190930b9ff8bSMatthew G. Knepley                                     void (**f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1910194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1911194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
191297b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
191330b9ff8bSMatthew G. Knepley                                     void (**f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1914194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1915194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
191697b6e6e8SMatthew G. Knepley                                                 PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
19172764a2aaSMatthew G. Knepley {
19182764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19192764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19202764a2aaSMatthew 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);
19212764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 3); *f0 = prob->fBd[f*2+0];}
19222764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 4); *f1 = prob->fBd[f*2+1];}
19232764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
19242764a2aaSMatthew G. Knepley }
19252764a2aaSMatthew G. Knepley 
1926194d53e6SMatthew G. Knepley /*@C
1927194d53e6SMatthew G. Knepley   PetscDSSetBdResidual - Get the pointwise boundary residual function for a given test field
1928194d53e6SMatthew G. Knepley 
1929194d53e6SMatthew G. Knepley   Not collective
1930194d53e6SMatthew G. Knepley 
1931194d53e6SMatthew G. Knepley   Input Parameters:
1932194d53e6SMatthew G. Knepley + prob - The PetscDS
1933194d53e6SMatthew G. Knepley . f    - The test field number
1934194d53e6SMatthew G. Knepley . f0 - boundary integrand for the test function term
1935194d53e6SMatthew G. Knepley - f1 - boundary integrand for the test function gradient term
1936194d53e6SMatthew G. Knepley 
1937194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
1938194d53e6SMatthew G. Knepley 
1939194d53e6SMatthew G. Knepley   \int_\Gamma \phi {\vec 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
1940194d53e6SMatthew G. Knepley 
1941194d53e6SMatthew G. Knepley The calling sequence for the callbacks f0 and f1 is given by:
1942194d53e6SMatthew G. Knepley 
194330b9ff8bSMatthew G. Knepley $ f0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1944194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1945194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
194630b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar f0[])
1947194d53e6SMatthew G. Knepley 
1948194d53e6SMatthew G. Knepley + dim - the spatial dimension
1949194d53e6SMatthew G. Knepley . Nf - the number of fields
1950194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
1951194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
1952194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
1953194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
1954194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
1955194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
1956194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
1957194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
1958194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
1959194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
1960194d53e6SMatthew G. Knepley . t - current time
1961194d53e6SMatthew G. Knepley . x - coordinates of the current point
1962194d53e6SMatthew G. Knepley . n - unit normal at the current point
196397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
196497b6e6e8SMatthew G. Knepley . constants - constant parameters
1965194d53e6SMatthew G. Knepley - f0 - output values at the current point
1966194d53e6SMatthew G. Knepley 
1967194d53e6SMatthew G. Knepley   Level: intermediate
1968194d53e6SMatthew G. Knepley 
1969194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdResidual()
1970194d53e6SMatthew G. Knepley @*/
19712764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdResidual(PetscDS prob, PetscInt f,
197230b9ff8bSMatthew G. Knepley                                     void (*f0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1973194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1974194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
197597b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[]),
197630b9ff8bSMatthew G. Knepley                                     void (*f1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
1977194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
1978194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
197997b6e6e8SMatthew G. Knepley                                                PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[]))
19802764a2aaSMatthew G. Knepley {
19812764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
19822764a2aaSMatthew G. Knepley 
19832764a2aaSMatthew G. Knepley   PetscFunctionBegin;
19842764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
19852764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
19862764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
19872764a2aaSMatthew G. Knepley   if (f0) {PetscValidFunction(f0, 3); prob->fBd[f*2+0] = f0;}
19882764a2aaSMatthew G. Knepley   if (f1) {PetscValidFunction(f1, 4); prob->fBd[f*2+1] = f1;}
19892764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
19902764a2aaSMatthew G. Knepley }
19912764a2aaSMatthew G. Knepley 
1992194d53e6SMatthew G. Knepley /*@C
1993194d53e6SMatthew G. Knepley   PetscDSGetBdJacobian - Get the pointwise boundary Jacobian function for given test and basis field
1994194d53e6SMatthew G. Knepley 
1995194d53e6SMatthew G. Knepley   Not collective
1996194d53e6SMatthew G. Knepley 
1997194d53e6SMatthew G. Knepley   Input Parameters:
1998194d53e6SMatthew G. Knepley + prob - The PetscDS
1999194d53e6SMatthew G. Knepley . f    - The test field number
2000194d53e6SMatthew G. Knepley - g    - The field number
2001194d53e6SMatthew G. Knepley 
2002194d53e6SMatthew G. Knepley   Output Parameters:
2003194d53e6SMatthew G. Knepley + g0 - integrand for the test and basis function term
2004194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2005194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2006194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2007194d53e6SMatthew G. Knepley 
2008194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2009194d53e6SMatthew G. Knepley 
2010194d53e6SMatthew 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
2011194d53e6SMatthew G. Knepley 
2012194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2013194d53e6SMatthew G. Knepley 
201430b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2015194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2016194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
201730b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2018194d53e6SMatthew G. Knepley 
2019194d53e6SMatthew G. Knepley + dim - the spatial dimension
2020194d53e6SMatthew G. Knepley . Nf - the number of fields
2021194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2022194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2023194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2024194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2025194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2026194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2027194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2028194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2029194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2030194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2031194d53e6SMatthew G. Knepley . t - current time
20322aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2033194d53e6SMatthew G. Knepley . x - coordinates of the current point
2034194d53e6SMatthew G. Knepley . n - normal at the current point
203597b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
203697b6e6e8SMatthew G. Knepley . constants - constant parameters
2037194d53e6SMatthew G. Knepley - g0 - output values at the current point
2038194d53e6SMatthew G. Knepley 
2039194d53e6SMatthew G. Knepley   Level: intermediate
2040194d53e6SMatthew G. Knepley 
2041194d53e6SMatthew G. Knepley .seealso: PetscDSSetBdJacobian()
2042194d53e6SMatthew G. Knepley @*/
20432764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
204430b9ff8bSMatthew G. Knepley                                     void (**g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2045194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2046194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
204797b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
204830b9ff8bSMatthew G. Knepley                                     void (**g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2049194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2050194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
205197b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
205230b9ff8bSMatthew G. Knepley                                     void (**g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2053194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2054194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
205597b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
205630b9ff8bSMatthew G. Knepley                                     void (**g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2057194d53e6SMatthew G. Knepley                                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2058194d53e6SMatthew G. Knepley                                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
205997b6e6e8SMatthew G. Knepley                                                 PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
20602764a2aaSMatthew G. Knepley {
20612764a2aaSMatthew G. Knepley   PetscFunctionBegin;
20622764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
20632764a2aaSMatthew 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);
20642764a2aaSMatthew 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);
20652764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->gBd[(f*prob->Nf + g)*4+0];}
20662764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->gBd[(f*prob->Nf + g)*4+1];}
20672764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->gBd[(f*prob->Nf + g)*4+2];}
20682764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->gBd[(f*prob->Nf + g)*4+3];}
20692764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
20702764a2aaSMatthew G. Knepley }
20712764a2aaSMatthew G. Knepley 
2072194d53e6SMatthew G. Knepley /*@C
2073194d53e6SMatthew G. Knepley   PetscDSSetBdJacobian - Set the pointwise boundary Jacobian function for given test and basis field
2074194d53e6SMatthew G. Knepley 
2075194d53e6SMatthew G. Knepley   Not collective
2076194d53e6SMatthew G. Knepley 
2077194d53e6SMatthew G. Knepley   Input Parameters:
2078194d53e6SMatthew G. Knepley + prob - The PetscDS
2079194d53e6SMatthew G. Knepley . f    - The test field number
2080194d53e6SMatthew G. Knepley . g    - The field number
2081194d53e6SMatthew G. Knepley . g0 - integrand for the test and basis function term
2082194d53e6SMatthew G. Knepley . g1 - integrand for the test function and basis function gradient term
2083194d53e6SMatthew G. Knepley . g2 - integrand for the test function gradient and basis function term
2084194d53e6SMatthew G. Knepley - g3 - integrand for the test function gradient and basis function gradient term
2085194d53e6SMatthew G. Knepley 
2086194d53e6SMatthew G. Knepley   Note: We are using a first order FEM model for the weak form:
2087194d53e6SMatthew G. Knepley 
2088194d53e6SMatthew 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
2089194d53e6SMatthew G. Knepley 
2090194d53e6SMatthew G. Knepley The calling sequence for the callbacks g0, g1, g2 and g3 is given by:
2091194d53e6SMatthew G. Knepley 
209230b9ff8bSMatthew G. Knepley $ g0(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2093194d53e6SMatthew G. Knepley $    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2094194d53e6SMatthew G. Knepley $    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
209530b9ff8bSMatthew G. Knepley $    PetscReal t, const PetscReal x[], const PetscReal n[], PetscScalar g0[])
2096194d53e6SMatthew G. Knepley 
2097194d53e6SMatthew G. Knepley + dim - the spatial dimension
2098194d53e6SMatthew G. Knepley . Nf - the number of fields
2099194d53e6SMatthew G. Knepley . uOff - the offset into u[] and u_t[] for each field
2100194d53e6SMatthew G. Knepley . uOff_x - the offset into u_x[] for each field
2101194d53e6SMatthew G. Knepley . u - each field evaluated at the current point
2102194d53e6SMatthew G. Knepley . u_t - the time derivative of each field evaluated at the current point
2103194d53e6SMatthew G. Knepley . u_x - the gradient of each field evaluated at the current point
2104194d53e6SMatthew G. Knepley . aOff - the offset into a[] and a_t[] for each auxiliary field
2105194d53e6SMatthew G. Knepley . aOff_x - the offset into a_x[] for each auxiliary field
2106194d53e6SMatthew G. Knepley . a - each auxiliary field evaluated at the current point
2107194d53e6SMatthew G. Knepley . a_t - the time derivative of each auxiliary field evaluated at the current point
2108194d53e6SMatthew G. Knepley . a_x - the gradient of auxiliary each field evaluated at the current point
2109194d53e6SMatthew G. Knepley . t - current time
21102aa1fc23SMatthew G. Knepley . u_tShift - the multiplier a for dF/dU_t
2111194d53e6SMatthew G. Knepley . x - coordinates of the current point
2112194d53e6SMatthew G. Knepley . n - normal at the current point
211397b6e6e8SMatthew G. Knepley . numConstants - number of constant parameters
211497b6e6e8SMatthew G. Knepley . constants - constant parameters
2115194d53e6SMatthew G. Knepley - g0 - output values at the current point
2116194d53e6SMatthew G. Knepley 
2117194d53e6SMatthew G. Knepley   Level: intermediate
2118194d53e6SMatthew G. Knepley 
2119194d53e6SMatthew G. Knepley .seealso: PetscDSGetBdJacobian()
2120194d53e6SMatthew G. Knepley @*/
21212764a2aaSMatthew G. Knepley PetscErrorCode PetscDSSetBdJacobian(PetscDS prob, PetscInt f, PetscInt g,
212230b9ff8bSMatthew G. Knepley                                     void (*g0)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2123194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2124194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
212597b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]),
212630b9ff8bSMatthew G. Knepley                                     void (*g1)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2127194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2128194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
212997b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g1[]),
213030b9ff8bSMatthew G. Knepley                                     void (*g2)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2131194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2132194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
213397b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g2[]),
213430b9ff8bSMatthew G. Knepley                                     void (*g3)(PetscInt dim, PetscInt Nf, PetscInt NfAux,
2135194d53e6SMatthew G. Knepley                                                const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
2136194d53e6SMatthew G. Knepley                                                const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
213797b6e6e8SMatthew G. Knepley                                                PetscReal t, PetscReal u_tShift, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[]))
21382764a2aaSMatthew G. Knepley {
21392764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
21402764a2aaSMatthew G. Knepley 
21412764a2aaSMatthew G. Knepley   PetscFunctionBegin;
21422764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
21432764a2aaSMatthew G. Knepley   if (g0) PetscValidFunction(g0, 4);
21442764a2aaSMatthew G. Knepley   if (g1) PetscValidFunction(g1, 5);
21452764a2aaSMatthew G. Knepley   if (g2) PetscValidFunction(g2, 6);
21462764a2aaSMatthew G. Knepley   if (g3) PetscValidFunction(g3, 7);
21472764a2aaSMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
21482764a2aaSMatthew G. Knepley   if (g < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", g);
21492764a2aaSMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, PetscMax(f, g)+1);CHKERRQ(ierr);
21502764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+0] = g0;
21512764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+1] = g1;
21522764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+2] = g2;
21532764a2aaSMatthew G. Knepley   prob->gBd[(f*prob->Nf + g)*4+3] = g3;
21542764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
21552764a2aaSMatthew G. Knepley }
21562764a2aaSMatthew G. Knepley 
21570d3e9b51SMatthew G. Knepley /*@C
2158c371a6d1SMatthew G. Knepley   PetscDSGetExactSolution - Get the pointwise exact solution function for a given test field
2159c371a6d1SMatthew G. Knepley 
2160c371a6d1SMatthew G. Knepley   Not collective
2161c371a6d1SMatthew G. Knepley 
2162c371a6d1SMatthew G. Knepley   Input Parameters:
2163c371a6d1SMatthew G. Knepley + prob - The PetscDS
2164c371a6d1SMatthew G. Knepley - f    - The test field number
2165c371a6d1SMatthew G. Knepley 
2166c371a6d1SMatthew G. Knepley   Output Parameter:
2167c371a6d1SMatthew G. Knepley . exactSol - exact solution for the test field
2168c371a6d1SMatthew G. Knepley 
2169c371a6d1SMatthew G. Knepley   Note: The calling sequence for the solution functions is given by:
2170c371a6d1SMatthew G. Knepley 
2171c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2172c371a6d1SMatthew G. Knepley 
2173c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2174c371a6d1SMatthew G. Knepley . t - current time
2175c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2176c371a6d1SMatthew G. Knepley . Nc - the number of field components
2177c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2178c371a6d1SMatthew G. Knepley - ctx - a user context
2179c371a6d1SMatthew G. Knepley 
2180c371a6d1SMatthew G. Knepley   Level: intermediate
2181c371a6d1SMatthew G. Knepley 
2182c371a6d1SMatthew G. Knepley .seealso: PetscDSSetExactSolution()
2183c371a6d1SMatthew G. Knepley @*/
2184c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSGetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (**sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2185c371a6d1SMatthew G. Knepley {
2186c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2187c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2188c371a6d1SMatthew 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);
2189c371a6d1SMatthew G. Knepley   if (sol) {PetscValidPointer(sol, 3); *sol = prob->exactSol[f];}
2190c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2191c371a6d1SMatthew G. Knepley }
2192c371a6d1SMatthew G. Knepley 
2193c371a6d1SMatthew G. Knepley /*@C
2194c371a6d1SMatthew G. Knepley   PetscDSSetExactSolution - Get the pointwise exact solution function for a given test field
2195c371a6d1SMatthew G. Knepley 
2196c371a6d1SMatthew G. Knepley   Not collective
2197c371a6d1SMatthew G. Knepley 
2198c371a6d1SMatthew G. Knepley   Input Parameters:
2199c371a6d1SMatthew G. Knepley + prob - The PetscDS
2200c371a6d1SMatthew G. Knepley . f    - The test field number
2201c371a6d1SMatthew G. Knepley - sol  - solution function for the test fields
2202c371a6d1SMatthew G. Knepley 
2203c371a6d1SMatthew G. Knepley   Note: The calling sequence for solution functions is given by:
2204c371a6d1SMatthew G. Knepley 
2205c371a6d1SMatthew G. Knepley $ sol(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx)
2206c371a6d1SMatthew G. Knepley 
2207c371a6d1SMatthew G. Knepley + dim - the spatial dimension
2208c371a6d1SMatthew G. Knepley . t - current time
2209c371a6d1SMatthew G. Knepley . x - coordinates of the current point
2210c371a6d1SMatthew G. Knepley . Nc - the number of field components
2211c371a6d1SMatthew G. Knepley . u - the solution field evaluated at the current point
2212c371a6d1SMatthew G. Knepley - ctx - a user context
2213c371a6d1SMatthew G. Knepley 
2214c371a6d1SMatthew G. Knepley   Level: intermediate
2215c371a6d1SMatthew G. Knepley 
2216c371a6d1SMatthew G. Knepley .seealso: PetscDSGetExactSolution()
2217c371a6d1SMatthew G. Knepley @*/
2218c371a6d1SMatthew G. Knepley PetscErrorCode PetscDSSetExactSolution(PetscDS prob, PetscInt f, PetscErrorCode (*sol)(PetscInt dim, PetscReal t, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx))
2219c371a6d1SMatthew G. Knepley {
2220c371a6d1SMatthew G. Knepley   PetscErrorCode ierr;
2221c371a6d1SMatthew G. Knepley 
2222c371a6d1SMatthew G. Knepley   PetscFunctionBegin;
2223c371a6d1SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2224c371a6d1SMatthew G. Knepley   if (f < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Field number %d must be non-negative", f);
2225c371a6d1SMatthew G. Knepley   ierr = PetscDSEnlarge_Static(prob, f+1);CHKERRQ(ierr);
2226c371a6d1SMatthew G. Knepley   if (sol) {PetscValidFunction(sol, 3); prob->exactSol[f] = sol;}
2227c371a6d1SMatthew G. Knepley   PetscFunctionReturn(0);
2228c371a6d1SMatthew G. Knepley }
2229c371a6d1SMatthew G. Knepley 
22305638fd0eSMatthew G. Knepley /*@C
223197b6e6e8SMatthew G. Knepley   PetscDSGetConstants - Returns the array of constants passed to point functions
223297b6e6e8SMatthew G. Knepley 
223397b6e6e8SMatthew G. Knepley   Not collective
223497b6e6e8SMatthew G. Knepley 
223597b6e6e8SMatthew G. Knepley   Input Parameter:
223697b6e6e8SMatthew G. Knepley . prob - The PetscDS object
223797b6e6e8SMatthew G. Knepley 
223897b6e6e8SMatthew G. Knepley   Output Parameters:
223997b6e6e8SMatthew G. Knepley + numConstants - The number of constants
224097b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
224197b6e6e8SMatthew G. Knepley 
224297b6e6e8SMatthew G. Knepley   Level: intermediate
224397b6e6e8SMatthew G. Knepley 
224497b6e6e8SMatthew G. Knepley .seealso: PetscDSSetConstants(), PetscDSCreate()
224597b6e6e8SMatthew G. Knepley @*/
224697b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSGetConstants(PetscDS prob, PetscInt *numConstants, const PetscScalar *constants[])
224797b6e6e8SMatthew G. Knepley {
224897b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
224997b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
225097b6e6e8SMatthew G. Knepley   if (numConstants) {PetscValidPointer(numConstants, 2); *numConstants = prob->numConstants;}
225197b6e6e8SMatthew G. Knepley   if (constants)    {PetscValidPointer(constants, 3);    *constants    = prob->constants;}
225297b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
225397b6e6e8SMatthew G. Knepley }
225497b6e6e8SMatthew G. Knepley 
22550d3e9b51SMatthew G. Knepley /*@C
225697b6e6e8SMatthew G. Knepley   PetscDSSetConstants - Set the array of constants passed to point functions
225797b6e6e8SMatthew G. Knepley 
225897b6e6e8SMatthew G. Knepley   Not collective
225997b6e6e8SMatthew G. Knepley 
226097b6e6e8SMatthew G. Knepley   Input Parameters:
226197b6e6e8SMatthew G. Knepley + prob         - The PetscDS object
226297b6e6e8SMatthew G. Knepley . numConstants - The number of constants
226397b6e6e8SMatthew G. Knepley - constants    - The array of constants, NULL if there are none
226497b6e6e8SMatthew G. Knepley 
226597b6e6e8SMatthew G. Knepley   Level: intermediate
226697b6e6e8SMatthew G. Knepley 
226797b6e6e8SMatthew G. Knepley .seealso: PetscDSGetConstants(), PetscDSCreate()
226897b6e6e8SMatthew G. Knepley @*/
226997b6e6e8SMatthew G. Knepley PetscErrorCode PetscDSSetConstants(PetscDS prob, PetscInt numConstants, PetscScalar constants[])
227097b6e6e8SMatthew G. Knepley {
227197b6e6e8SMatthew G. Knepley   PetscErrorCode ierr;
227297b6e6e8SMatthew G. Knepley 
227397b6e6e8SMatthew G. Knepley   PetscFunctionBegin;
227497b6e6e8SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
227597b6e6e8SMatthew G. Knepley   if (numConstants != prob->numConstants) {
227697b6e6e8SMatthew G. Knepley     ierr = PetscFree(prob->constants);CHKERRQ(ierr);
227797b6e6e8SMatthew G. Knepley     prob->numConstants = numConstants;
227897b6e6e8SMatthew G. Knepley     if (prob->numConstants) {
227997b6e6e8SMatthew G. Knepley       ierr = PetscMalloc1(prob->numConstants, &prob->constants);CHKERRQ(ierr);
228020be0f5bSMatthew G. Knepley     } else {
228120be0f5bSMatthew G. Knepley       prob->constants = NULL;
228220be0f5bSMatthew G. Knepley     }
228320be0f5bSMatthew G. Knepley   }
228420be0f5bSMatthew G. Knepley   if (prob->numConstants) {
228520be0f5bSMatthew G. Knepley     PetscValidPointer(constants, 3);
228697b6e6e8SMatthew G. Knepley     ierr = PetscMemcpy(prob->constants, constants, prob->numConstants * sizeof(PetscScalar));CHKERRQ(ierr);
228797b6e6e8SMatthew G. Knepley   }
228897b6e6e8SMatthew G. Knepley   PetscFunctionReturn(0);
228997b6e6e8SMatthew G. Knepley }
229097b6e6e8SMatthew G. Knepley 
22914cd1e086SMatthew G. Knepley /*@
22924cd1e086SMatthew G. Knepley   PetscDSGetFieldIndex - Returns the index of the given field
22934cd1e086SMatthew G. Knepley 
22944cd1e086SMatthew G. Knepley   Not collective
22954cd1e086SMatthew G. Knepley 
22964cd1e086SMatthew G. Knepley   Input Parameters:
22974cd1e086SMatthew G. Knepley + prob - The PetscDS object
22984cd1e086SMatthew G. Knepley - disc - The discretization object
22994cd1e086SMatthew G. Knepley 
23004cd1e086SMatthew G. Knepley   Output Parameter:
23014cd1e086SMatthew G. Knepley . f - The field number
23024cd1e086SMatthew G. Knepley 
23034cd1e086SMatthew G. Knepley   Level: beginner
23044cd1e086SMatthew G. Knepley 
2305f744cafaSSander Arens .seealso: PetscGetDiscretization(), PetscDSGetNumFields(), PetscDSCreate()
23064cd1e086SMatthew G. Knepley @*/
23074cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldIndex(PetscDS prob, PetscObject disc, PetscInt *f)
23084cd1e086SMatthew G. Knepley {
23094cd1e086SMatthew G. Knepley   PetscInt g;
23104cd1e086SMatthew G. Knepley 
23114cd1e086SMatthew G. Knepley   PetscFunctionBegin;
23124cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23134cd1e086SMatthew G. Knepley   PetscValidPointer(f, 3);
23144cd1e086SMatthew G. Knepley   *f = -1;
23154cd1e086SMatthew G. Knepley   for (g = 0; g < prob->Nf; ++g) {if (disc == prob->disc[g]) break;}
23164cd1e086SMatthew G. Knepley   if (g == prob->Nf) SETERRQ(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Field not found in PetscDS.");
23174cd1e086SMatthew G. Knepley   *f = g;
23184cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
23194cd1e086SMatthew G. Knepley }
23204cd1e086SMatthew G. Knepley 
23214cd1e086SMatthew G. Knepley /*@
23224cd1e086SMatthew G. Knepley   PetscDSGetFieldSize - Returns the size of the given field in the full space basis
23234cd1e086SMatthew G. Knepley 
23244cd1e086SMatthew G. Knepley   Not collective
23254cd1e086SMatthew G. Knepley 
23264cd1e086SMatthew G. Knepley   Input Parameters:
23274cd1e086SMatthew G. Knepley + prob - The PetscDS object
23284cd1e086SMatthew G. Knepley - f - The field number
23294cd1e086SMatthew G. Knepley 
23304cd1e086SMatthew G. Knepley   Output Parameter:
23314cd1e086SMatthew G. Knepley . size - The size
23324cd1e086SMatthew G. Knepley 
23334cd1e086SMatthew G. Knepley   Level: beginner
23344cd1e086SMatthew G. Knepley 
2335f744cafaSSander Arens .seealso: PetscDSGetFieldOffset(), PetscDSGetNumFields(), PetscDSCreate()
23364cd1e086SMatthew G. Knepley @*/
23374cd1e086SMatthew G. Knepley PetscErrorCode PetscDSGetFieldSize(PetscDS prob, PetscInt f, PetscInt *size)
23384cd1e086SMatthew G. Knepley {
23392166fd64SMatthew G. Knepley   PetscErrorCode ierr;
23402166fd64SMatthew G. Knepley 
23414cd1e086SMatthew G. Knepley   PetscFunctionBegin;
23424cd1e086SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23434cd1e086SMatthew G. Knepley   PetscValidPointer(size, 3);
23444cd1e086SMatthew 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);
23452166fd64SMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
2346d4742ddaSMatthew G. Knepley   *size = prob->Nb[f];
23474cd1e086SMatthew G. Knepley   PetscFunctionReturn(0);
23484cd1e086SMatthew G. Knepley }
23494cd1e086SMatthew G. Knepley 
2350bc4ae4beSMatthew G. Knepley /*@
2351bc4ae4beSMatthew G. Knepley   PetscDSGetFieldOffset - Returns the offset of the given field in the full space basis
2352bc4ae4beSMatthew G. Knepley 
2353bc4ae4beSMatthew G. Knepley   Not collective
2354bc4ae4beSMatthew G. Knepley 
2355bc4ae4beSMatthew G. Knepley   Input Parameters:
2356bc4ae4beSMatthew G. Knepley + prob - The PetscDS object
2357bc4ae4beSMatthew G. Knepley - f - The field number
2358bc4ae4beSMatthew G. Knepley 
2359bc4ae4beSMatthew G. Knepley   Output Parameter:
2360bc4ae4beSMatthew G. Knepley . off - The offset
2361bc4ae4beSMatthew G. Knepley 
2362bc4ae4beSMatthew G. Knepley   Level: beginner
2363bc4ae4beSMatthew G. Knepley 
2364f744cafaSSander Arens .seealso: PetscDSGetFieldSize(), PetscDSGetNumFields(), PetscDSCreate()
2365bc4ae4beSMatthew G. Knepley @*/
23662764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetFieldOffset(PetscDS prob, PetscInt f, PetscInt *off)
23672764a2aaSMatthew G. Knepley {
23684cd1e086SMatthew G. Knepley   PetscInt       size, g;
23692764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
23702764a2aaSMatthew G. Knepley 
23712764a2aaSMatthew G. Knepley   PetscFunctionBegin;
23722764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
23732764a2aaSMatthew G. Knepley   PetscValidPointer(off, 3);
23742764a2aaSMatthew 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);
23752764a2aaSMatthew G. Knepley   *off = 0;
23762764a2aaSMatthew G. Knepley   for (g = 0; g < f; ++g) {
23774cd1e086SMatthew G. Knepley     ierr = PetscDSGetFieldSize(prob, g, &size);CHKERRQ(ierr);
23784cd1e086SMatthew G. Knepley     *off += size;
23792764a2aaSMatthew G. Knepley   }
23802764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
23812764a2aaSMatthew G. Knepley }
23822764a2aaSMatthew G. Knepley 
2383bc4ae4beSMatthew G. Knepley /*@
238447e57110SSander Arens   PetscDSGetDimensions - Returns the size of the approximation space for each field on an evaluation point
2385bc4ae4beSMatthew G. Knepley 
2386bc4ae4beSMatthew G. Knepley   Not collective
2387bc4ae4beSMatthew G. Knepley 
238847e57110SSander Arens   Input Parameter:
238947e57110SSander Arens . prob - The PetscDS object
2390bc4ae4beSMatthew G. Knepley 
2391bc4ae4beSMatthew G. Knepley   Output Parameter:
239247e57110SSander Arens . dimensions - The number of dimensions
2393bc4ae4beSMatthew G. Knepley 
2394bc4ae4beSMatthew G. Knepley   Level: beginner
2395bc4ae4beSMatthew G. Knepley 
239647e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
2397bc4ae4beSMatthew G. Knepley @*/
239847e57110SSander Arens PetscErrorCode PetscDSGetDimensions(PetscDS prob, PetscInt *dimensions[])
23992764a2aaSMatthew G. Knepley {
24002764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
24012764a2aaSMatthew G. Knepley 
24022764a2aaSMatthew G. Knepley   PetscFunctionBegin;
24032764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
240447e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
240547e57110SSander Arens   PetscValidPointer(dimensions, 2);
240647e57110SSander Arens   *dimensions = prob->Nb;
240747e57110SSander Arens   PetscFunctionReturn(0);
24086ce16762SMatthew G. Knepley }
240947e57110SSander Arens 
241047e57110SSander Arens /*@
241147e57110SSander Arens   PetscDSGetComponents - Returns the number of components for each field on an evaluation point
241247e57110SSander Arens 
241347e57110SSander Arens   Not collective
241447e57110SSander Arens 
241547e57110SSander Arens   Input Parameter:
241647e57110SSander Arens . prob - The PetscDS object
241747e57110SSander Arens 
241847e57110SSander Arens   Output Parameter:
241947e57110SSander Arens . components - The number of components
242047e57110SSander Arens 
242147e57110SSander Arens   Level: beginner
242247e57110SSander Arens 
242347e57110SSander Arens .seealso: PetscDSGetComponentOffsets(), PetscDSGetNumFields(), PetscDSCreate()
242447e57110SSander Arens @*/
242547e57110SSander Arens PetscErrorCode PetscDSGetComponents(PetscDS prob, PetscInt *components[])
242647e57110SSander Arens {
242747e57110SSander Arens   PetscErrorCode ierr;
242847e57110SSander Arens 
242947e57110SSander Arens   PetscFunctionBegin;
243047e57110SSander Arens   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
243147e57110SSander Arens   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
243247e57110SSander Arens   PetscValidPointer(components, 2);
243347e57110SSander Arens   *components = prob->Nc;
24346ce16762SMatthew G. Knepley   PetscFunctionReturn(0);
24356ce16762SMatthew G. Knepley }
24366ce16762SMatthew G. Knepley 
24376ce16762SMatthew G. Knepley /*@
24386ce16762SMatthew G. Knepley   PetscDSGetComponentOffset - Returns the offset of the given field on an evaluation point
24396ce16762SMatthew G. Knepley 
24406ce16762SMatthew G. Knepley   Not collective
24416ce16762SMatthew G. Knepley 
24426ce16762SMatthew G. Knepley   Input Parameters:
24436ce16762SMatthew G. Knepley + prob - The PetscDS object
24446ce16762SMatthew G. Knepley - f - The field number
24456ce16762SMatthew G. Knepley 
24466ce16762SMatthew G. Knepley   Output Parameter:
24476ce16762SMatthew G. Knepley . off - The offset
24486ce16762SMatthew G. Knepley 
24496ce16762SMatthew G. Knepley   Level: beginner
24506ce16762SMatthew G. Knepley 
2451f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
24526ce16762SMatthew G. Knepley @*/
24536ce16762SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffset(PetscDS prob, PetscInt f, PetscInt *off)
24546ce16762SMatthew G. Knepley {
24556ce16762SMatthew G. Knepley   PetscFunctionBegin;
24566ce16762SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
24576ce16762SMatthew G. Knepley   PetscValidPointer(off, 3);
24586ce16762SMatthew 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);
245947e57110SSander Arens   *off = prob->off[f];
24602764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
24612764a2aaSMatthew G. Knepley }
24622764a2aaSMatthew G. Knepley 
2463194d53e6SMatthew G. Knepley /*@
2464194d53e6SMatthew G. Knepley   PetscDSGetComponentOffsets - Returns the offset of each field on an evaluation point
2465194d53e6SMatthew G. Knepley 
2466194d53e6SMatthew G. Knepley   Not collective
2467194d53e6SMatthew G. Knepley 
2468194d53e6SMatthew G. Knepley   Input Parameter:
2469194d53e6SMatthew G. Knepley . prob - The PetscDS object
2470194d53e6SMatthew G. Knepley 
2471194d53e6SMatthew G. Knepley   Output Parameter:
2472194d53e6SMatthew G. Knepley . offsets - The offsets
2473194d53e6SMatthew G. Knepley 
2474194d53e6SMatthew G. Knepley   Level: beginner
2475194d53e6SMatthew G. Knepley 
2476f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2477194d53e6SMatthew G. Knepley @*/
2478194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentOffsets(PetscDS prob, PetscInt *offsets[])
2479194d53e6SMatthew G. Knepley {
2480194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2481194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2482194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2483194d53e6SMatthew G. Knepley   *offsets = prob->off;
2484194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2485194d53e6SMatthew G. Knepley }
2486194d53e6SMatthew G. Knepley 
2487194d53e6SMatthew G. Knepley /*@
2488194d53e6SMatthew G. Knepley   PetscDSGetComponentDerivativeOffsets - Returns the offset of each field derivative on an evaluation point
2489194d53e6SMatthew G. Knepley 
2490194d53e6SMatthew G. Knepley   Not collective
2491194d53e6SMatthew G. Knepley 
2492194d53e6SMatthew G. Knepley   Input Parameter:
2493194d53e6SMatthew G. Knepley . prob - The PetscDS object
2494194d53e6SMatthew G. Knepley 
2495194d53e6SMatthew G. Knepley   Output Parameter:
2496194d53e6SMatthew G. Knepley . offsets - The offsets
2497194d53e6SMatthew G. Knepley 
2498194d53e6SMatthew G. Knepley   Level: beginner
2499194d53e6SMatthew G. Knepley 
2500f744cafaSSander Arens .seealso: PetscDSGetNumFields(), PetscDSCreate()
2501194d53e6SMatthew G. Knepley @*/
2502194d53e6SMatthew G. Knepley PetscErrorCode PetscDSGetComponentDerivativeOffsets(PetscDS prob, PetscInt *offsets[])
2503194d53e6SMatthew G. Knepley {
2504194d53e6SMatthew G. Knepley   PetscFunctionBegin;
2505194d53e6SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2506194d53e6SMatthew G. Knepley   PetscValidPointer(offsets, 2);
2507194d53e6SMatthew G. Knepley   *offsets = prob->offDer;
2508194d53e6SMatthew G. Knepley   PetscFunctionReturn(0);
2509194d53e6SMatthew G. Knepley }
2510194d53e6SMatthew G. Knepley 
251168c9edb9SMatthew G. Knepley /*@C
251268c9edb9SMatthew G. Knepley   PetscDSGetTabulation - Return the basis tabulation at quadrature points for the volume discretization
251368c9edb9SMatthew G. Knepley 
251468c9edb9SMatthew G. Knepley   Not collective
251568c9edb9SMatthew G. Knepley 
251668c9edb9SMatthew G. Knepley   Input Parameter:
251768c9edb9SMatthew G. Knepley . prob - The PetscDS object
251868c9edb9SMatthew G. Knepley 
251968c9edb9SMatthew G. Knepley   Output Parameters:
252068c9edb9SMatthew G. Knepley + basis - The basis function tabulation at quadrature points
252168c9edb9SMatthew G. Knepley - basisDer - The basis function derivative tabulation at quadrature points
252268c9edb9SMatthew G. Knepley 
252368c9edb9SMatthew G. Knepley   Level: intermediate
252468c9edb9SMatthew G. Knepley 
2525f744cafaSSander Arens .seealso: PetscDSCreate()
252668c9edb9SMatthew G. Knepley @*/
25272764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
25282764a2aaSMatthew G. Knepley {
25292764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25302764a2aaSMatthew G. Knepley 
25312764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25322764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25332764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25342764a2aaSMatthew G. Knepley   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basis;}
25352764a2aaSMatthew G. Knepley   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDer;}
25362764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25372764a2aaSMatthew G. Knepley }
25382764a2aaSMatthew G. Knepley 
253968c9edb9SMatthew G. Knepley /*@C
25404d0b9603SSander Arens   PetscDSGetFaceTabulation - Return the basis tabulation at quadrature points on the faces
254168c9edb9SMatthew G. Knepley 
254268c9edb9SMatthew G. Knepley   Not collective
254368c9edb9SMatthew G. Knepley 
254468c9edb9SMatthew G. Knepley   Input Parameter:
254568c9edb9SMatthew G. Knepley . prob - The PetscDS object
254668c9edb9SMatthew G. Knepley 
254768c9edb9SMatthew G. Knepley   Output Parameters:
25484d0b9603SSander Arens + basisFace - The basis function tabulation at quadrature points
25494d0b9603SSander Arens - basisDerFace - The basis function derivative tabulation at quadrature points
255068c9edb9SMatthew G. Knepley 
255168c9edb9SMatthew G. Knepley   Level: intermediate
255268c9edb9SMatthew G. Knepley 
255368c9edb9SMatthew G. Knepley .seealso: PetscDSGetTabulation(), PetscDSCreate()
255468c9edb9SMatthew G. Knepley @*/
25554d0b9603SSander Arens PetscErrorCode PetscDSGetFaceTabulation(PetscDS prob, PetscReal ***basis, PetscReal ***basisDer)
25562764a2aaSMatthew G. Knepley {
25572764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25582764a2aaSMatthew G. Knepley 
25592764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25602764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25612764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25624d0b9603SSander Arens   if (basis)    {PetscValidPointer(basis, 2);    *basis    = prob->basisFace;}
25634d0b9603SSander Arens   if (basisDer) {PetscValidPointer(basisDer, 3); *basisDer = prob->basisDerFace;}
25642764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25652764a2aaSMatthew G. Knepley }
25662764a2aaSMatthew G. Knepley 
25672764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetEvaluationArrays(PetscDS prob, PetscScalar **u, PetscScalar **u_t, PetscScalar **u_x)
25682764a2aaSMatthew G. Knepley {
25692764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25702764a2aaSMatthew G. Knepley 
25712764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25722764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25732764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25742764a2aaSMatthew G. Knepley   if (u)   {PetscValidPointer(u, 2);   *u   = prob->u;}
25752764a2aaSMatthew G. Knepley   if (u_t) {PetscValidPointer(u_t, 3); *u_t = prob->u_t;}
25762764a2aaSMatthew G. Knepley   if (u_x) {PetscValidPointer(u_x, 4); *u_x = prob->u_x;}
25772764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25782764a2aaSMatthew G. Knepley }
25792764a2aaSMatthew G. Knepley 
25802764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetWeakFormArrays(PetscDS prob, PetscScalar **f0, PetscScalar **f1, PetscScalar **g0, PetscScalar **g1, PetscScalar **g2, PetscScalar **g3)
25812764a2aaSMatthew G. Knepley {
25822764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25832764a2aaSMatthew G. Knepley 
25842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
25852764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
25862764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
25872764a2aaSMatthew G. Knepley   if (f0) {PetscValidPointer(f0, 2); *f0 = prob->f0;}
25882764a2aaSMatthew G. Knepley   if (f1) {PetscValidPointer(f1, 3); *f1 = prob->f1;}
25892764a2aaSMatthew G. Knepley   if (g0) {PetscValidPointer(g0, 4); *g0 = prob->g0;}
25902764a2aaSMatthew G. Knepley   if (g1) {PetscValidPointer(g1, 5); *g1 = prob->g1;}
25912764a2aaSMatthew G. Knepley   if (g2) {PetscValidPointer(g2, 6); *g2 = prob->g2;}
25922764a2aaSMatthew G. Knepley   if (g3) {PetscValidPointer(g3, 7); *g3 = prob->g3;}
25932764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
25942764a2aaSMatthew G. Knepley }
25952764a2aaSMatthew G. Knepley 
25962764a2aaSMatthew G. Knepley PetscErrorCode PetscDSGetRefCoordArrays(PetscDS prob, PetscReal **x, PetscScalar **refSpaceDer)
25972764a2aaSMatthew G. Knepley {
25982764a2aaSMatthew G. Knepley   PetscErrorCode ierr;
25992764a2aaSMatthew G. Knepley 
26002764a2aaSMatthew G. Knepley   PetscFunctionBegin;
26012764a2aaSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
26022764a2aaSMatthew G. Knepley   ierr = PetscDSSetUp(prob);CHKERRQ(ierr);
26032764a2aaSMatthew G. Knepley   if (x)           {PetscValidPointer(x, 2);           *x           = prob->x;}
26042764a2aaSMatthew G. Knepley   if (refSpaceDer) {PetscValidPointer(refSpaceDer, 3); *refSpaceDer = prob->refSpaceDer;}
26052764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
26062764a2aaSMatthew G. Knepley }
26072764a2aaSMatthew G. Knepley 
260858ebd649SToby Isaac /*@C
260958ebd649SToby Isaac   PetscDSAddBoundary - Add a boundary condition to the model
261058ebd649SToby Isaac 
261158ebd649SToby Isaac   Input Parameters:
261258ebd649SToby Isaac + ds          - The PetscDS object
26132d47a189SJulian Andrej . type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
261458ebd649SToby Isaac . name        - The BC name
261558ebd649SToby Isaac . labelname   - The label defining constrained points
261658ebd649SToby Isaac . field       - The field to constrain
261758ebd649SToby Isaac . numcomps    - The number of constrained field components
261858ebd649SToby Isaac . comps       - An array of constrained component numbers
261958ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
262058ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
262158ebd649SToby Isaac . ids         - An array of ids for constrained points
262258ebd649SToby Isaac - ctx         - An optional user context for bcFunc
262358ebd649SToby Isaac 
262458ebd649SToby Isaac   Options Database Keys:
262558ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
262658ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
262758ebd649SToby Isaac 
262858ebd649SToby Isaac   Level: developer
262958ebd649SToby Isaac 
263058ebd649SToby Isaac .seealso: PetscDSGetBoundary()
263158ebd649SToby Isaac @*/
2632a30ec4eaSSatish 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)
263358ebd649SToby Isaac {
263458ebd649SToby Isaac   DSBoundary     b;
263558ebd649SToby Isaac   PetscErrorCode ierr;
263658ebd649SToby Isaac 
263758ebd649SToby Isaac   PetscFunctionBegin;
263858ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
263958ebd649SToby Isaac   ierr = PetscNew(&b);CHKERRQ(ierr);
264058ebd649SToby Isaac   ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr);
264158ebd649SToby Isaac   ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr);
264258ebd649SToby Isaac   ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr);
264358ebd649SToby Isaac   if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);}
264458ebd649SToby Isaac   ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr);
264558ebd649SToby Isaac   if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);}
2646f971fd6bSMatthew G. Knepley   b->type            = type;
264758ebd649SToby Isaac   b->field           = field;
264858ebd649SToby Isaac   b->numcomps        = numcomps;
264958ebd649SToby Isaac   b->func            = bcFunc;
265058ebd649SToby Isaac   b->numids          = numids;
265158ebd649SToby Isaac   b->ctx             = ctx;
265258ebd649SToby Isaac   b->next            = ds->boundary;
265358ebd649SToby Isaac   ds->boundary       = b;
265458ebd649SToby Isaac   PetscFunctionReturn(0);
265558ebd649SToby Isaac }
265658ebd649SToby Isaac 
265758ebd649SToby Isaac /*@
265858ebd649SToby Isaac   PetscDSGetNumBoundary - Get the number of registered BC
265958ebd649SToby Isaac 
266058ebd649SToby Isaac   Input Parameters:
266158ebd649SToby Isaac . ds - The PetscDS object
266258ebd649SToby Isaac 
266358ebd649SToby Isaac   Output Parameters:
266458ebd649SToby Isaac . numBd - The number of BC
266558ebd649SToby Isaac 
266658ebd649SToby Isaac   Level: intermediate
266758ebd649SToby Isaac 
266858ebd649SToby Isaac .seealso: PetscDSAddBoundary(), PetscDSGetBoundary()
266958ebd649SToby Isaac @*/
267058ebd649SToby Isaac PetscErrorCode PetscDSGetNumBoundary(PetscDS ds, PetscInt *numBd)
267158ebd649SToby Isaac {
267258ebd649SToby Isaac   DSBoundary b = ds->boundary;
267358ebd649SToby Isaac 
267458ebd649SToby Isaac   PetscFunctionBegin;
267558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
267658ebd649SToby Isaac   PetscValidPointer(numBd, 2);
267758ebd649SToby Isaac   *numBd = 0;
267858ebd649SToby Isaac   while (b) {++(*numBd); b = b->next;}
267958ebd649SToby Isaac   PetscFunctionReturn(0);
268058ebd649SToby Isaac }
268158ebd649SToby Isaac 
268258ebd649SToby Isaac /*@C
268358ebd649SToby Isaac   PetscDSGetBoundary - Add a boundary condition to the model
268458ebd649SToby Isaac 
268558ebd649SToby Isaac   Input Parameters:
268658ebd649SToby Isaac + ds          - The PetscDS object
268758ebd649SToby Isaac - bd          - The BC number
268858ebd649SToby Isaac 
268958ebd649SToby Isaac   Output Parameters:
26902d47a189SJulian Andrej + type        - The type of condition, e.g. DM_BC_ESSENTIAL/DM_BC_ESSENTIAL_FIELD (Dirichlet), or DM_BC_NATURAL (Neumann)
269158ebd649SToby Isaac . name        - The BC name
269258ebd649SToby Isaac . labelname   - The label defining constrained points
269358ebd649SToby Isaac . field       - The field to constrain
269458ebd649SToby Isaac . numcomps    - The number of constrained field components
269558ebd649SToby Isaac . comps       - An array of constrained component numbers
269658ebd649SToby Isaac . bcFunc      - A pointwise function giving boundary values
269758ebd649SToby Isaac . numids      - The number of DMLabel ids for constrained points
269858ebd649SToby Isaac . ids         - An array of ids for constrained points
269958ebd649SToby Isaac - ctx         - An optional user context for bcFunc
270058ebd649SToby Isaac 
270158ebd649SToby Isaac   Options Database Keys:
270258ebd649SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids
270358ebd649SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components
270458ebd649SToby Isaac 
270558ebd649SToby Isaac   Level: developer
270658ebd649SToby Isaac 
270758ebd649SToby Isaac .seealso: PetscDSAddBoundary()
270858ebd649SToby Isaac @*/
2709a30ec4eaSSatish 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)
271058ebd649SToby Isaac {
271158ebd649SToby Isaac   DSBoundary b    = ds->boundary;
271258ebd649SToby Isaac   PetscInt   n    = 0;
271358ebd649SToby Isaac 
271458ebd649SToby Isaac   PetscFunctionBegin;
271558ebd649SToby Isaac   PetscValidHeaderSpecific(ds, PETSCDS_CLASSID, 1);
271658ebd649SToby Isaac   while (b) {
271758ebd649SToby Isaac     if (n == bd) break;
271858ebd649SToby Isaac     b = b->next;
271958ebd649SToby Isaac     ++n;
272058ebd649SToby Isaac   }
272158ebd649SToby Isaac   if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n);
2722f971fd6bSMatthew G. Knepley   if (type) {
2723f971fd6bSMatthew G. Knepley     PetscValidPointer(type, 3);
2724f971fd6bSMatthew G. Knepley     *type = b->type;
272558ebd649SToby Isaac   }
272658ebd649SToby Isaac   if (name) {
272758ebd649SToby Isaac     PetscValidPointer(name, 4);
272858ebd649SToby Isaac     *name = b->name;
272958ebd649SToby Isaac   }
273058ebd649SToby Isaac   if (labelname) {
273158ebd649SToby Isaac     PetscValidPointer(labelname, 5);
273258ebd649SToby Isaac     *labelname = b->labelname;
273358ebd649SToby Isaac   }
273458ebd649SToby Isaac   if (field) {
273558ebd649SToby Isaac     PetscValidPointer(field, 6);
273658ebd649SToby Isaac     *field = b->field;
273758ebd649SToby Isaac   }
273858ebd649SToby Isaac   if (numcomps) {
273958ebd649SToby Isaac     PetscValidPointer(numcomps, 7);
274058ebd649SToby Isaac     *numcomps = b->numcomps;
274158ebd649SToby Isaac   }
274258ebd649SToby Isaac   if (comps) {
274358ebd649SToby Isaac     PetscValidPointer(comps, 8);
274458ebd649SToby Isaac     *comps = b->comps;
274558ebd649SToby Isaac   }
274658ebd649SToby Isaac   if (func) {
274758ebd649SToby Isaac     PetscValidPointer(func, 9);
274858ebd649SToby Isaac     *func = b->func;
274958ebd649SToby Isaac   }
275058ebd649SToby Isaac   if (numids) {
275158ebd649SToby Isaac     PetscValidPointer(numids, 10);
275258ebd649SToby Isaac     *numids = b->numids;
275358ebd649SToby Isaac   }
275458ebd649SToby Isaac   if (ids) {
275558ebd649SToby Isaac     PetscValidPointer(ids, 11);
275658ebd649SToby Isaac     *ids = b->ids;
275758ebd649SToby Isaac   }
275858ebd649SToby Isaac   if (ctx) {
275958ebd649SToby Isaac     PetscValidPointer(ctx, 12);
276058ebd649SToby Isaac     *ctx = b->ctx;
276158ebd649SToby Isaac   }
276258ebd649SToby Isaac   PetscFunctionReturn(0);
276358ebd649SToby Isaac }
276458ebd649SToby Isaac 
27659252d075SMatthew G. Knepley /*@
27669252d075SMatthew G. Knepley   PetscDSCopyBoundary - Copy all boundary condition objects to the new problem
27679252d075SMatthew G. Knepley 
27689252d075SMatthew G. Knepley   Not collective
27699252d075SMatthew G. Knepley 
27709252d075SMatthew G. Knepley   Input Parameter:
27719252d075SMatthew G. Knepley . prob - The PetscDS object
27729252d075SMatthew G. Knepley 
27739252d075SMatthew G. Knepley   Output Parameter:
27749252d075SMatthew G. Knepley . newprob - The PetscDS copy
27759252d075SMatthew G. Knepley 
27769252d075SMatthew G. Knepley   Level: intermediate
27779252d075SMatthew G. Knepley 
27789252d075SMatthew G. Knepley .seealso: PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
27799252d075SMatthew G. Knepley @*/
2780dff059c6SToby Isaac PetscErrorCode PetscDSCopyBoundary(PetscDS probA, PetscDS probB)
2781dff059c6SToby Isaac {
2782dff059c6SToby Isaac   DSBoundary     b, next, *lastnext;
2783dff059c6SToby Isaac   PetscErrorCode ierr;
2784dff059c6SToby Isaac 
2785dff059c6SToby Isaac   PetscFunctionBegin;
2786dff059c6SToby Isaac   PetscValidHeaderSpecific(probA, PETSCDS_CLASSID, 1);
2787dff059c6SToby Isaac   PetscValidHeaderSpecific(probB, PETSCDS_CLASSID, 2);
2788dff059c6SToby Isaac   if (probA == probB) PetscFunctionReturn(0);
2789dff059c6SToby Isaac   next = probB->boundary;
2790dff059c6SToby Isaac   while (next) {
2791dff059c6SToby Isaac     DSBoundary b = next;
2792dff059c6SToby Isaac 
2793dff059c6SToby Isaac     next = b->next;
2794dff059c6SToby Isaac     ierr = PetscFree(b->comps);CHKERRQ(ierr);
2795dff059c6SToby Isaac     ierr = PetscFree(b->ids);CHKERRQ(ierr);
2796dff059c6SToby Isaac     ierr = PetscFree(b->name);CHKERRQ(ierr);
2797dff059c6SToby Isaac     ierr = PetscFree(b->labelname);CHKERRQ(ierr);
2798dff059c6SToby Isaac     ierr = PetscFree(b);CHKERRQ(ierr);
2799dff059c6SToby Isaac   }
2800dff059c6SToby Isaac   lastnext = &(probB->boundary);
2801dff059c6SToby Isaac   for (b = probA->boundary; b; b = b->next) {
2802dff059c6SToby Isaac     DSBoundary bNew;
2803dff059c6SToby Isaac 
2804459726d8SSatish Balay     ierr = PetscNew(&bNew);CHKERRQ(ierr);
2805dff059c6SToby Isaac     bNew->numcomps = b->numcomps;
2806dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numcomps, &bNew->comps);CHKERRQ(ierr);
2807dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->comps, b->comps, bNew->numcomps*sizeof(PetscInt));CHKERRQ(ierr);
2808dff059c6SToby Isaac     bNew->numids = b->numids;
2809dff059c6SToby Isaac     ierr = PetscMalloc1(bNew->numids, &bNew->ids);CHKERRQ(ierr);
2810dff059c6SToby Isaac     ierr = PetscMemcpy(bNew->ids, b->ids, bNew->numids*sizeof(PetscInt));CHKERRQ(ierr);
2811dff059c6SToby Isaac     ierr = PetscStrallocpy(b->labelname,(char **) &(bNew->labelname));CHKERRQ(ierr);
2812dff059c6SToby Isaac     ierr = PetscStrallocpy(b->name,(char **) &(bNew->name));CHKERRQ(ierr);
2813dff059c6SToby Isaac     bNew->ctx   = b->ctx;
2814f971fd6bSMatthew G. Knepley     bNew->type  = b->type;
2815dff059c6SToby Isaac     bNew->field = b->field;
2816dff059c6SToby Isaac     bNew->func  = b->func;
2817dff059c6SToby Isaac 
2818dff059c6SToby Isaac     *lastnext = bNew;
2819dff059c6SToby Isaac     lastnext = &(bNew->next);
2820dff059c6SToby Isaac   }
2821dff059c6SToby Isaac   PetscFunctionReturn(0);
2822dff059c6SToby Isaac }
2823dff059c6SToby Isaac 
28249252d075SMatthew G. Knepley /*@C
28259252d075SMatthew G. Knepley   PetscDSSelectEquations - Copy pointwise function pointers to the new problem with different field layout
28269252d075SMatthew G. Knepley 
28279252d075SMatthew G. Knepley   Not collective
28289252d075SMatthew G. Knepley 
28299252d075SMatthew G. Knepley   Input Parameter:
28309252d075SMatthew G. Knepley + prob - The PetscDS object
28319252d075SMatthew G. Knepley . numFields - Number of new fields
28329252d075SMatthew G. Knepley - fields - Old field number for each new field
28339252d075SMatthew G. Knepley 
28349252d075SMatthew G. Knepley   Output Parameter:
28359252d075SMatthew G. Knepley . newprob - The PetscDS copy
28369252d075SMatthew G. Knepley 
28379252d075SMatthew G. Knepley   Level: intermediate
28389252d075SMatthew G. Knepley 
28399252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
28409252d075SMatthew G. Knepley @*/
28419252d075SMatthew G. Knepley PetscErrorCode PetscDSSelectEquations(PetscDS prob, PetscInt numFields, const PetscInt fields[], PetscDS newprob)
28429252d075SMatthew G. Knepley {
28439252d075SMatthew G. Knepley   PetscInt       Nf, Nfn, fn, gn;
28449252d075SMatthew G. Knepley   PetscErrorCode ierr;
28459252d075SMatthew G. Knepley 
28469252d075SMatthew G. Knepley   PetscFunctionBegin;
28479252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
28489252d075SMatthew G. Knepley   if (fields) PetscValidPointer(fields, 3);
28499252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 4);
28509252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
28519252d075SMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Nfn);CHKERRQ(ierr);
28529252d075SMatthew G. Knepley   if (numFields > Nfn) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields %D to transfer must not be greater then the total number of fields %D", numFields, Nfn);
28539252d075SMatthew G. Knepley   for (fn = 0; fn < numFields; ++fn) {
28549252d075SMatthew G. Knepley     const PetscInt   f = fields ? fields[fn] : fn;
28559252d075SMatthew G. Knepley     PetscPointFunc   obj;
28569252d075SMatthew G. Knepley     PetscPointFunc   f0, f1;
28579252d075SMatthew G. Knepley     PetscBdPointFunc f0Bd, f1Bd;
28589252d075SMatthew G. Knepley     PetscRiemannFunc r;
28599252d075SMatthew G. Knepley 
28609252d075SMatthew G. Knepley     if (f >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", f, Nf);
28619252d075SMatthew G. Knepley     ierr = PetscDSGetObjective(prob, f, &obj);CHKERRQ(ierr);
28629252d075SMatthew G. Knepley     ierr = PetscDSGetResidual(prob, f, &f0, &f1);CHKERRQ(ierr);
28639252d075SMatthew G. Knepley     ierr = PetscDSGetBdResidual(prob, f, &f0Bd, &f1Bd);CHKERRQ(ierr);
28649252d075SMatthew G. Knepley     ierr = PetscDSGetRiemannSolver(prob, f, &r);CHKERRQ(ierr);
28659252d075SMatthew G. Knepley     ierr = PetscDSSetObjective(newprob, fn, obj);CHKERRQ(ierr);
28669252d075SMatthew G. Knepley     ierr = PetscDSSetResidual(newprob, fn, f0, f1);CHKERRQ(ierr);
28679252d075SMatthew G. Knepley     ierr = PetscDSSetBdResidual(newprob, fn, f0Bd, f1Bd);CHKERRQ(ierr);
28689252d075SMatthew G. Knepley     ierr = PetscDSSetRiemannSolver(newprob, fn, r);CHKERRQ(ierr);
28699252d075SMatthew G. Knepley     for (gn = 0; gn < numFields; ++gn) {
28709252d075SMatthew G. Knepley       const PetscInt  g = fields ? fields[gn] : gn;
28719252d075SMatthew G. Knepley       PetscPointJac   g0, g1, g2, g3;
28729252d075SMatthew G. Knepley       PetscPointJac   g0p, g1p, g2p, g3p;
28739252d075SMatthew G. Knepley       PetscBdPointJac g0Bd, g1Bd, g2Bd, g3Bd;
28749252d075SMatthew G. Knepley 
28759252d075SMatthew G. Knepley       if (g >= Nf) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Field %D must be in [0, %D)", g, Nf);
28769252d075SMatthew G. Knepley       ierr = PetscDSGetJacobian(prob, f, g, &g0, &g1, &g2, &g3);CHKERRQ(ierr);
28779252d075SMatthew G. Knepley       ierr = PetscDSGetJacobianPreconditioner(prob, f, g, &g0p, &g1p, &g2p, &g3p);CHKERRQ(ierr);
28789252d075SMatthew G. Knepley       ierr = PetscDSGetBdJacobian(prob, f, g, &g0Bd, &g1Bd, &g2Bd, &g3Bd);CHKERRQ(ierr);
28799252d075SMatthew G. Knepley       ierr = PetscDSSetJacobian(newprob, fn, gn, g0, g1, g2, g3);CHKERRQ(ierr);
28809252d075SMatthew G. Knepley       ierr = PetscDSSetJacobianPreconditioner(prob, fn, gn, g0p, g1p, g2p, g3p);CHKERRQ(ierr);
28819252d075SMatthew G. Knepley       ierr = PetscDSSetBdJacobian(newprob, fn, gn, g0Bd, g1Bd, g2Bd, g3Bd);CHKERRQ(ierr);
28829252d075SMatthew G. Knepley     }
28839252d075SMatthew G. Knepley   }
28849252d075SMatthew G. Knepley   PetscFunctionReturn(0);
28859252d075SMatthew G. Knepley }
28869252d075SMatthew G. Knepley 
2887da51fcedSMatthew G. Knepley /*@
2888da51fcedSMatthew G. Knepley   PetscDSCopyEquations - Copy all pointwise function pointers to the new problem
2889da51fcedSMatthew G. Knepley 
2890da51fcedSMatthew G. Knepley   Not collective
2891da51fcedSMatthew G. Knepley 
2892da51fcedSMatthew G. Knepley   Input Parameter:
2893da51fcedSMatthew G. Knepley . prob - The PetscDS object
2894da51fcedSMatthew G. Knepley 
2895da51fcedSMatthew G. Knepley   Output Parameter:
2896da51fcedSMatthew G. Knepley . newprob - The PetscDS copy
2897da51fcedSMatthew G. Knepley 
2898da51fcedSMatthew G. Knepley   Level: intermediate
2899da51fcedSMatthew G. Knepley 
29009252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
2901da51fcedSMatthew G. Knepley @*/
2902da51fcedSMatthew G. Knepley PetscErrorCode PetscDSCopyEquations(PetscDS prob, PetscDS newprob)
2903da51fcedSMatthew G. Knepley {
29049252d075SMatthew G. Knepley   PetscInt       Nf, Ng;
2905da51fcedSMatthew G. Knepley   PetscErrorCode ierr;
2906da51fcedSMatthew G. Knepley 
2907da51fcedSMatthew G. Knepley   PetscFunctionBegin;
2908da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2909da51fcedSMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
2910da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
2911da51fcedSMatthew G. Knepley   ierr = PetscDSGetNumFields(newprob, &Ng);CHKERRQ(ierr);
291213903a91SSatish Balay   if (Nf != Ng) SETERRQ2(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_SIZ, "Number of fields must match %D != %D", Nf, Ng);
29139252d075SMatthew G. Knepley   ierr = PetscDSSelectEquations(prob, Nf, NULL, newprob);CHKERRQ(ierr);
29149252d075SMatthew G. Knepley   PetscFunctionReturn(0);
29159252d075SMatthew G. Knepley }
29169252d075SMatthew G. Knepley /*@
29179252d075SMatthew G. Knepley   PetscDSCopyConstants - Copy all constants to the new problem
2918da51fcedSMatthew G. Knepley 
29199252d075SMatthew G. Knepley   Not collective
29209252d075SMatthew G. Knepley 
29219252d075SMatthew G. Knepley   Input Parameter:
29229252d075SMatthew G. Knepley . prob - The PetscDS object
29239252d075SMatthew G. Knepley 
29249252d075SMatthew G. Knepley   Output Parameter:
29259252d075SMatthew G. Knepley . newprob - The PetscDS copy
29269252d075SMatthew G. Knepley 
29279252d075SMatthew G. Knepley   Level: intermediate
29289252d075SMatthew G. Knepley 
29299252d075SMatthew G. Knepley .seealso: PetscDSCopyBoundary(), PetscDSCopyEquations(), PetscDSSetResidual(), PetscDSSetJacobian(), PetscDSSetRiemannSolver(), PetscDSSetBdResidual(), PetscDSSetBdJacobian(), PetscDSCreate()
29309252d075SMatthew G. Knepley @*/
29319252d075SMatthew G. Knepley PetscErrorCode PetscDSCopyConstants(PetscDS prob, PetscDS newprob)
29329252d075SMatthew G. Knepley {
29339252d075SMatthew G. Knepley   PetscInt           Nc;
29349252d075SMatthew G. Knepley   const PetscScalar *constants;
29359252d075SMatthew G. Knepley   PetscErrorCode     ierr;
29369252d075SMatthew G. Knepley 
29379252d075SMatthew G. Knepley   PetscFunctionBegin;
29389252d075SMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
29399252d075SMatthew G. Knepley   PetscValidHeaderSpecific(newprob, PETSCDS_CLASSID, 2);
29409252d075SMatthew G. Knepley   ierr = PetscDSGetConstants(prob, &Nc, &constants);CHKERRQ(ierr);
29419252d075SMatthew G. Knepley   ierr = PetscDSSetConstants(newprob, Nc, (PetscScalar *) constants);CHKERRQ(ierr);
2942da51fcedSMatthew G. Knepley   PetscFunctionReturn(0);
2943da51fcedSMatthew G. Knepley }
2944da51fcedSMatthew G. Knepley 
2945b1353e8eSMatthew G. Knepley PetscErrorCode PetscDSGetHeightSubspace(PetscDS prob, PetscInt height, PetscDS *subprob)
2946b1353e8eSMatthew G. Knepley {
2947df3a45bdSMatthew G. Knepley   PetscInt       dim, Nf, f;
2948b1353e8eSMatthew G. Knepley   PetscErrorCode ierr;
2949b1353e8eSMatthew G. Knepley 
2950b1353e8eSMatthew G. Knepley   PetscFunctionBegin;
2951b1353e8eSMatthew G. Knepley   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
2952b1353e8eSMatthew G. Knepley   PetscValidPointer(subprob, 3);
2953b1353e8eSMatthew G. Knepley   if (height == 0) {*subprob = prob; PetscFunctionReturn(0);}
2954b1353e8eSMatthew G. Knepley   ierr = PetscDSGetNumFields(prob, &Nf);CHKERRQ(ierr);
2955df3a45bdSMatthew G. Knepley   ierr = PetscDSGetSpatialDimension(prob, &dim);CHKERRQ(ierr);
2956df3a45bdSMatthew 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);
2957df3a45bdSMatthew G. Knepley   if (!prob->subprobs) {ierr = PetscCalloc1(dim, &prob->subprobs);CHKERRQ(ierr);}
2958df3a45bdSMatthew G. Knepley   if (!prob->subprobs[height-1]) {
2959b1353e8eSMatthew G. Knepley     PetscInt cdim;
2960b1353e8eSMatthew G. Knepley 
2961df3a45bdSMatthew G. Knepley     ierr = PetscDSCreate(PetscObjectComm((PetscObject) prob), &prob->subprobs[height-1]);CHKERRQ(ierr);
2962b1353e8eSMatthew G. Knepley     ierr = PetscDSGetCoordinateDimension(prob, &cdim);CHKERRQ(ierr);
2963df3a45bdSMatthew G. Knepley     ierr = PetscDSSetCoordinateDimension(prob->subprobs[height-1], cdim);CHKERRQ(ierr);
2964b1353e8eSMatthew G. Knepley     for (f = 0; f < Nf; ++f) {
2965b1353e8eSMatthew G. Knepley       PetscFE      subfe;
2966b1353e8eSMatthew G. Knepley       PetscObject  obj;
2967b1353e8eSMatthew G. Knepley       PetscClassId id;
2968b1353e8eSMatthew G. Knepley 
2969b1353e8eSMatthew G. Knepley       ierr = PetscDSGetDiscretization(prob, f, &obj);CHKERRQ(ierr);
2970b1353e8eSMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
2971b1353e8eSMatthew G. Knepley       if (id == PETSCFE_CLASSID) {ierr = PetscFEGetHeightSubspace((PetscFE) obj, height, &subfe);CHKERRQ(ierr);}
2972b1353e8eSMatthew G. Knepley       else SETERRQ1(PetscObjectComm((PetscObject) prob), PETSC_ERR_ARG_WRONG, "Unsupported discretization type for field %d", f);
2973df3a45bdSMatthew G. Knepley       ierr = PetscDSSetDiscretization(prob->subprobs[height-1], f, (PetscObject) subfe);CHKERRQ(ierr);
2974b1353e8eSMatthew G. Knepley     }
2975b1353e8eSMatthew G. Knepley   }
2976df3a45bdSMatthew G. Knepley   *subprob = prob->subprobs[height-1];
2977b1353e8eSMatthew G. Knepley   PetscFunctionReturn(0);
2978b1353e8eSMatthew G. Knepley }
2979b1353e8eSMatthew G. Knepley 
2980bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSDestroy_Basic(PetscDS prob)
29812764a2aaSMatthew G. Knepley {
2982931fb3b8SToby Isaac   PetscErrorCode      ierr;
2983931fb3b8SToby Isaac 
29842764a2aaSMatthew G. Knepley   PetscFunctionBegin;
2985931fb3b8SToby Isaac   ierr = PetscFree(prob->data);CHKERRQ(ierr);
29862764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29872764a2aaSMatthew G. Knepley }
29882764a2aaSMatthew G. Knepley 
2989bc4ae4beSMatthew G. Knepley static PetscErrorCode PetscDSInitialize_Basic(PetscDS prob)
29902764a2aaSMatthew G. Knepley {
29912764a2aaSMatthew G. Knepley   PetscFunctionBegin;
29922764a2aaSMatthew G. Knepley   prob->ops->setfromoptions = NULL;
29932764a2aaSMatthew G. Knepley   prob->ops->setup          = NULL;
29942764a2aaSMatthew G. Knepley   prob->ops->view           = NULL;
29952764a2aaSMatthew G. Knepley   prob->ops->destroy        = PetscDSDestroy_Basic;
29962764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
29972764a2aaSMatthew G. Knepley }
29982764a2aaSMatthew G. Knepley 
29992764a2aaSMatthew G. Knepley /*MC
30002764a2aaSMatthew G. Knepley   PETSCDSBASIC = "basic" - A discrete system with pointwise residual and boundary residual functions
30012764a2aaSMatthew G. Knepley 
30022764a2aaSMatthew G. Knepley   Level: intermediate
30032764a2aaSMatthew G. Knepley 
30042764a2aaSMatthew G. Knepley .seealso: PetscDSType, PetscDSCreate(), PetscDSSetType()
30052764a2aaSMatthew G. Knepley M*/
30062764a2aaSMatthew G. Knepley 
30072764a2aaSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDSCreate_Basic(PetscDS prob)
30082764a2aaSMatthew G. Knepley {
30092764a2aaSMatthew G. Knepley   PetscDS_Basic *b;
30102764a2aaSMatthew G. Knepley   PetscErrorCode      ierr;
30112764a2aaSMatthew G. Knepley 
30122764a2aaSMatthew G. Knepley   PetscFunctionBegin;
3013931fb3b8SToby Isaac   PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 1);
30142764a2aaSMatthew G. Knepley   ierr       = PetscNewLog(prob, &b);CHKERRQ(ierr);
30152764a2aaSMatthew G. Knepley   prob->data = b;
30162764a2aaSMatthew G. Knepley 
30172764a2aaSMatthew G. Knepley   ierr = PetscDSInitialize_Basic(prob);CHKERRQ(ierr);
30182764a2aaSMatthew G. Knepley   PetscFunctionReturn(0);
30192764a2aaSMatthew G. Knepley }
3020