xref: /petsc/src/ts/utils/dmplexts.c (revision 9586001c52809aaa950a028b61e525a6df19f5d6)
1af0996ceSBarry Smith #include <petsc/private/dmpleximpl.h> /*I "petscdmplex.h" I*/
2af0996ceSBarry Smith #include <petsc/private/tsimpl.h>     /*I "petscts.h" I*/
337c2070cSMatthew G. Knepley #include <petsc/private/snesimpl.h>
4924a1b8fSMatthew G. Knepley #include <petscds.h>
56dbbd306SMatthew G. Knepley #include <petscfv.h>
66dbbd306SMatthew G. Knepley 
7254c1ad2SMatthew G. Knepley #undef __FUNCT__
86da023fcSToby Isaac #define __FUNCT__ "DMTSConvertPlex"
96da023fcSToby Isaac static PetscErrorCode DMTSConvertPlex(DM dm, DM *plex, PetscBool copy)
106da023fcSToby Isaac {
116da023fcSToby Isaac   PetscBool      isPlex;
126da023fcSToby Isaac   PetscErrorCode ierr;
136da023fcSToby Isaac 
146da023fcSToby Isaac   PetscFunctionBegin;
156da023fcSToby Isaac   ierr = PetscObjectTypeCompare((PetscObject)dm,DMPLEX,&isPlex);CHKERRQ(ierr);
166da023fcSToby Isaac   if (isPlex) {
176da023fcSToby Isaac     *plex = dm;
186da023fcSToby Isaac     ierr = PetscObjectReference((PetscObject)dm);CHKERRQ(ierr);
196da023fcSToby Isaac   }
206da023fcSToby Isaac   else {
216da023fcSToby Isaac     ierr = DMConvert(dm,DMPLEX,plex);CHKERRQ(ierr);
226da023fcSToby Isaac     if (copy) {
236da023fcSToby Isaac       PetscInt    i;
246da023fcSToby Isaac       PetscObject obj;
256da023fcSToby Isaac       const char *comps[3] = {"A","dmAux","dmCh"};
266da023fcSToby Isaac 
276da023fcSToby Isaac       ierr = DMCopyDMTS(dm,*plex);CHKERRQ(ierr);
286da023fcSToby Isaac       ierr = DMCopyDMSNES(dm,*plex);CHKERRQ(ierr);
296da023fcSToby Isaac       for (i = 0; i < 3; i++) {
306da023fcSToby Isaac         ierr = PetscObjectQuery((PetscObject)dm,comps[i],&obj);CHKERRQ(ierr);
316da023fcSToby Isaac         ierr = PetscObjectCompose((PetscObject)*plex,comps[i],obj);CHKERRQ(ierr);
326da023fcSToby Isaac       }
336da023fcSToby Isaac     }
346da023fcSToby Isaac   }
356da023fcSToby Isaac   PetscFunctionReturn(0);
366da023fcSToby Isaac }
376da023fcSToby Isaac 
386da023fcSToby Isaac 
396da023fcSToby Isaac #undef __FUNCT__
40b6aca0f9SMatthew G. Knepley #define __FUNCT__ "DMPlexTSGetGeometryFVM"
41c510411aSMatthew G. Knepley /*@
42b6aca0f9SMatthew G. Knepley   DMPlexTSGetGeometryFVM - Return precomputed geometric data
43c510411aSMatthew G. Knepley 
44c510411aSMatthew G. Knepley   Input Parameter:
45c510411aSMatthew G. Knepley . dm - The DM
46c510411aSMatthew G. Knepley 
47c510411aSMatthew G. Knepley   Output Parameters:
48c510411aSMatthew G. Knepley + facegeom - The values precomputed from face geometry
49c510411aSMatthew G. Knepley . cellgeom - The values precomputed from cell geometry
50c510411aSMatthew G. Knepley - minRadius - The minimum radius over the mesh of an inscribed sphere in a cell
51c510411aSMatthew G. Knepley 
52c510411aSMatthew G. Knepley   Level: developer
53c510411aSMatthew G. Knepley 
54c510411aSMatthew G. Knepley .seealso: DMPlexTSSetRHSFunctionLocal()
55c510411aSMatthew G. Knepley @*/
56b6aca0f9SMatthew G. Knepley PetscErrorCode DMPlexTSGetGeometryFVM(DM dm, Vec *facegeom, Vec *cellgeom, PetscReal *minRadius)
57a0ac79e7SMatthew G. Knepley {
58a0ac79e7SMatthew G. Knepley   DMTS           dmts;
591faf85eaSMatthew G. Knepley   PetscObject    obj;
606da023fcSToby Isaac   DM             plex;
61a0ac79e7SMatthew G. Knepley   PetscErrorCode ierr;
62a0ac79e7SMatthew G. Knepley 
63a0ac79e7SMatthew G. Knepley   PetscFunctionBegin;
64924a1b8fSMatthew G. Knepley   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
656da023fcSToby Isaac   ierr = DMTSConvertPlex(dm,&plex,PETSC_TRUE);CHKERRQ(ierr);
666da023fcSToby Isaac   ierr = DMGetDMTS(plex, &dmts);CHKERRQ(ierr);
67b6aca0f9SMatthew G. Knepley   ierr = PetscObjectQuery((PetscObject) dmts, "DMPlexTS_facegeom_fvm", &obj);CHKERRQ(ierr);
681faf85eaSMatthew G. Knepley   if (!obj) {
691faf85eaSMatthew G. Knepley     Vec cellgeom, facegeom;
701faf85eaSMatthew G. Knepley 
716da023fcSToby Isaac     ierr = DMPlexComputeGeometryFVM(plex, &cellgeom, &facegeom);CHKERRQ(ierr);
72b6aca0f9SMatthew G. Knepley     ierr = PetscObjectCompose((PetscObject) dmts, "DMPlexTS_facegeom_fvm", (PetscObject) facegeom);CHKERRQ(ierr);
73b6aca0f9SMatthew G. Knepley     ierr = PetscObjectCompose((PetscObject) dmts, "DMPlexTS_cellgeom_fvm", (PetscObject) cellgeom);CHKERRQ(ierr);
741faf85eaSMatthew G. Knepley     ierr = VecDestroy(&facegeom);CHKERRQ(ierr);
751faf85eaSMatthew G. Knepley     ierr = VecDestroy(&cellgeom);CHKERRQ(ierr);
761faf85eaSMatthew G. Knepley   }
77b6aca0f9SMatthew G. Knepley   if (facegeom) {PetscValidPointer(facegeom, 2); ierr = PetscObjectQuery((PetscObject) dmts, "DMPlexTS_facegeom_fvm", (PetscObject *) facegeom);CHKERRQ(ierr);}
78b6aca0f9SMatthew G. Knepley   if (cellgeom) {PetscValidPointer(cellgeom, 3); ierr = PetscObjectQuery((PetscObject) dmts, "DMPlexTS_cellgeom_fvm", (PetscObject *) cellgeom);CHKERRQ(ierr);}
796da023fcSToby Isaac   if (minRadius) {ierr = DMPlexGetMinRadius(plex, minRadius);CHKERRQ(ierr);}
80b2338dbcSToby Isaac   ierr = DMDestroy(&plex);CHKERRQ(ierr);
81924a1b8fSMatthew G. Knepley   PetscFunctionReturn(0);
82924a1b8fSMatthew G. Knepley }
83924a1b8fSMatthew G. Knepley 
84924a1b8fSMatthew G. Knepley #undef __FUNCT__
85c49ccbb3SMatthew G. Knepley #define __FUNCT__ "DMPlexTSGetGradientDM"
86c49ccbb3SMatthew G. Knepley /*@C
87c49ccbb3SMatthew G. Knepley   DMPlexTSGetGradientDM - Return gradient data layout
88c49ccbb3SMatthew G. Knepley 
89c49ccbb3SMatthew G. Knepley   Input Parameters:
90c49ccbb3SMatthew G. Knepley + dm - The DM
91c49ccbb3SMatthew G. Knepley - fv - The PetscFV
92c49ccbb3SMatthew G. Knepley 
93c49ccbb3SMatthew G. Knepley   Output Parameter:
94c49ccbb3SMatthew G. Knepley . dmGrad - The layout for gradient values
95c49ccbb3SMatthew G. Knepley 
96c49ccbb3SMatthew G. Knepley   Level: developer
97c49ccbb3SMatthew G. Knepley 
98c49ccbb3SMatthew G. Knepley .seealso: DMPlexTSGetGeometryFVM(), DMPlexTSSetRHSFunctionLocal()
99c49ccbb3SMatthew G. Knepley @*/
100c49ccbb3SMatthew G. Knepley PetscErrorCode DMPlexTSGetGradientDM(DM dm, PetscFV fv, DM *dmGrad)
101c49ccbb3SMatthew G. Knepley {
102c49ccbb3SMatthew G. Knepley   DMTS           dmts;
103c49ccbb3SMatthew G. Knepley   PetscObject    obj;
104c49ccbb3SMatthew G. Knepley   PetscBool      computeGradients;
1056da023fcSToby Isaac   DM             plex;
106c49ccbb3SMatthew G. Knepley   PetscErrorCode ierr;
107c49ccbb3SMatthew G. Knepley 
108c49ccbb3SMatthew G. Knepley   PetscFunctionBegin;
109c49ccbb3SMatthew G. Knepley   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
110c49ccbb3SMatthew G. Knepley   PetscValidHeaderSpecific(fv,PETSCFV_CLASSID,2);
111c49ccbb3SMatthew G. Knepley   PetscValidPointer(dmGrad,3);
112c49ccbb3SMatthew G. Knepley   ierr = PetscFVGetComputeGradients(fv, &computeGradients);CHKERRQ(ierr);
113c49ccbb3SMatthew G. Knepley   if (!computeGradients) {*dmGrad = NULL; PetscFunctionReturn(0);}
1146da023fcSToby Isaac   ierr = DMTSConvertPlex(dm,&plex,PETSC_TRUE);CHKERRQ(ierr);
1156da023fcSToby Isaac   ierr = DMGetDMTS(plex, &dmts);CHKERRQ(ierr);
116c49ccbb3SMatthew G. Knepley   ierr = PetscObjectQuery((PetscObject) dmts, "DMPlexTS_dmgrad_fvm", &obj);CHKERRQ(ierr);
117c49ccbb3SMatthew G. Knepley   if (!obj) {
118c49ccbb3SMatthew G. Knepley     DM  dmGrad;
11908449791SMatthew G. Knepley     Vec faceGeometry, cellGeometry;
120c49ccbb3SMatthew G. Knepley 
1216da023fcSToby Isaac     ierr = DMPlexTSGetGeometryFVM(plex, &faceGeometry, &cellGeometry, NULL);CHKERRQ(ierr);
1226da023fcSToby Isaac     ierr = DMPlexComputeGradientFVM(plex, fv, faceGeometry, cellGeometry, &dmGrad);CHKERRQ(ierr);
123c49ccbb3SMatthew G. Knepley     ierr = PetscObjectCompose((PetscObject) dmts, "DMPlexTS_dmgrad_fvm", (PetscObject) dmGrad);CHKERRQ(ierr);
124924a1b8fSMatthew G. Knepley     ierr = DMDestroy(&dmGrad);CHKERRQ(ierr);
125c49ccbb3SMatthew G. Knepley   }
126c49ccbb3SMatthew G. Knepley   ierr = PetscObjectQuery((PetscObject) dmts, "DMPlexTS_dmgrad_fvm", (PetscObject *) dmGrad);CHKERRQ(ierr);
127b2338dbcSToby Isaac   ierr = DMDestroy(&plex);CHKERRQ(ierr);
128254c1ad2SMatthew G. Knepley   PetscFunctionReturn(0);
129254c1ad2SMatthew G. Knepley }
130254c1ad2SMatthew G. Knepley 
131254c1ad2SMatthew G. Knepley #undef __FUNCT__
132924a1b8fSMatthew G. Knepley #define __FUNCT__ "DMPlexTSComputeRHSFunctionFVM"
13308449791SMatthew G. Knepley /*@
13408449791SMatthew G. Knepley   DMPlexTSComputeRHSFunctionFVM - Form the local forcing F from the local input X using pointwise functions specified by the user
13508449791SMatthew G. Knepley 
13608449791SMatthew G. Knepley   Input Parameters:
13708449791SMatthew G. Knepley + dm - The mesh
13808449791SMatthew G. Knepley . t - The time
13908449791SMatthew G. Knepley . locX  - Local solution
14008449791SMatthew G. Knepley - user - The user context
14108449791SMatthew G. Knepley 
14208449791SMatthew G. Knepley   Output Parameter:
1433b16df42SMatthew G. Knepley . F  - Global output vector
14408449791SMatthew G. Knepley 
14508449791SMatthew G. Knepley   Level: developer
14608449791SMatthew G. Knepley 
14708449791SMatthew G. Knepley .seealso: DMPlexComputeJacobianActionFEM()
14808449791SMatthew G. Knepley @*/
1493b16df42SMatthew G. Knepley PetscErrorCode DMPlexTSComputeRHSFunctionFVM(DM dm, PetscReal time, Vec locX, Vec F, void *user)
150254c1ad2SMatthew G. Knepley {
1513b16df42SMatthew G. Knepley   Vec            locF;
152c4d4a4f8SMatthew G. Knepley   PetscInt       cStart, cEnd, cEndInterior;
1536da023fcSToby Isaac   DM             plex;
154254c1ad2SMatthew G. Knepley   PetscErrorCode ierr;
155254c1ad2SMatthew G. Knepley 
156254c1ad2SMatthew G. Knepley   PetscFunctionBegin;
1576da023fcSToby Isaac   ierr = DMTSConvertPlex(dm,&plex,PETSC_TRUE);CHKERRQ(ierr);
1586da023fcSToby Isaac   ierr = DMPlexGetHeightStratum(plex, 0, &cStart, &cEnd);CHKERRQ(ierr);
1596da023fcSToby Isaac   ierr = DMPlexGetHybridBounds(plex, &cEndInterior, NULL, NULL, NULL);CHKERRQ(ierr);
160c4d4a4f8SMatthew G. Knepley   cEnd = cEndInterior < 0 ? cEnd : cEndInterior;
1616da023fcSToby Isaac   ierr = DMGetLocalVector(plex, &locF);CHKERRQ(ierr);
1623b16df42SMatthew G. Knepley   ierr = VecZeroEntries(locF);CHKERRQ(ierr);
1636da023fcSToby Isaac   ierr = DMPlexComputeResidual_Internal(plex, cStart, cEnd, time, locX, NULL, locF, user);CHKERRQ(ierr);
1646da023fcSToby Isaac   ierr = DMLocalToGlobalBegin(plex, locF, INSERT_VALUES, F);CHKERRQ(ierr);
1656da023fcSToby Isaac   ierr = DMLocalToGlobalEnd(plex, locF, INSERT_VALUES, F);CHKERRQ(ierr);
1666da023fcSToby Isaac   ierr = DMRestoreLocalVector(plex, &locF);CHKERRQ(ierr);
167b2338dbcSToby Isaac   ierr = DMDestroy(&plex);CHKERRQ(ierr);
168254c1ad2SMatthew G. Knepley   PetscFunctionReturn(0);
169254c1ad2SMatthew G. Knepley }
170254c1ad2SMatthew G. Knepley 
171254c1ad2SMatthew G. Knepley #undef __FUNCT__
172ef68eab9SMatthew G. Knepley #define __FUNCT__ "DMPlexTSComputeBoundary"
173c5d70e09SMatthew G. Knepley /*@
174ef68eab9SMatthew G. Knepley   DMPlexTSComputeBoundary - Insert the essential boundary values for the local input X and/or its time derivative X_t using pointwise functions specified by the user
175c5d70e09SMatthew G. Knepley 
176c5d70e09SMatthew G. Knepley   Input Parameters:
177c5d70e09SMatthew G. Knepley + dm - The mesh
178a40652d4SToby Isaac . t - The time
179a40652d4SToby Isaac . locX  - Local solution
180a40652d4SToby Isaac . locX_t - Local solution time derivative, or NULL
181c5d70e09SMatthew G. Knepley - user - The user context
182c5d70e09SMatthew G. Knepley 
183c5d70e09SMatthew G. Knepley   Level: developer
184c5d70e09SMatthew G. Knepley 
185a40652d4SToby Isaac .seealso: DMPlexComputeJacobianActionFEM()
186c5d70e09SMatthew G. Knepley @*/
187ef68eab9SMatthew G. Knepley PetscErrorCode DMPlexTSComputeBoundary(DM dm, PetscReal time, Vec locX, Vec locX_t, void *user)
188c5d70e09SMatthew G. Knepley {
189c5d70e09SMatthew G. Knepley   DM             plex;
190ef68eab9SMatthew G. Knepley   Vec            faceGeometryFVM = NULL;
191ef68eab9SMatthew G. Knepley   PetscInt       Nf, f;
192c5d70e09SMatthew G. Knepley   PetscErrorCode ierr;
193c5d70e09SMatthew G. Knepley 
194c5d70e09SMatthew G. Knepley   PetscFunctionBegin;
195c5d70e09SMatthew G. Knepley   ierr = DMTSConvertPlex(dm, &plex, PETSC_TRUE);CHKERRQ(ierr);
196ef68eab9SMatthew G. Knepley   ierr = DMGetNumFields(plex, &Nf);CHKERRQ(ierr);
197*9586001cSMatthew G. Knepley   if (!locX_t) {
198*9586001cSMatthew G. Knepley     /* This is the RHS part */
199ef68eab9SMatthew G. Knepley     for (f = 0; f < Nf; f++) {
200ef68eab9SMatthew G. Knepley       PetscObject  obj;
201ef68eab9SMatthew G. Knepley       PetscClassId id;
202ef68eab9SMatthew G. Knepley 
203ef68eab9SMatthew G. Knepley       ierr = DMGetField(plex, f, &obj);CHKERRQ(ierr);
204ef68eab9SMatthew G. Knepley       ierr = PetscObjectGetClassId(obj, &id);CHKERRQ(ierr);
205ef68eab9SMatthew G. Knepley       if (id == PETSCFV_CLASSID) {
206ef68eab9SMatthew G. Knepley         ierr = DMPlexSNESGetGeometryFVM(plex, &faceGeometryFVM, NULL, NULL);CHKERRQ(ierr);
207ef68eab9SMatthew G. Knepley         break;
208ef68eab9SMatthew G. Knepley       }
209ef68eab9SMatthew G. Knepley     }
210*9586001cSMatthew G. Knepley   }
211*9586001cSMatthew G. Knepley   ierr = DMPlexInsertBoundaryValues(plex, PETSC_TRUE, locX, time, faceGeometryFVM, NULL, NULL);CHKERRQ(ierr);
212a40652d4SToby Isaac   /* TODO: locX_t */
213c5d70e09SMatthew G. Knepley   ierr = DMDestroy(&plex);CHKERRQ(ierr);
214c5d70e09SMatthew G. Knepley   PetscFunctionReturn(0);
215c5d70e09SMatthew G. Knepley }
216c5d70e09SMatthew G. Knepley 
217c5d70e09SMatthew G. Knepley #undef __FUNCT__
21824cdb843SMatthew G. Knepley #define __FUNCT__ "DMPlexTSComputeIFunctionFEM"
21924cdb843SMatthew G. Knepley /*@
22024cdb843SMatthew G. Knepley   DMPlexTSComputeIFunctionFEM - Form the local residual F from the local input X using pointwise functions specified by the user
22124cdb843SMatthew G. Knepley 
22224cdb843SMatthew G. Knepley   Input Parameters:
22324cdb843SMatthew G. Knepley + dm - The mesh
22424cdb843SMatthew G. Knepley . t - The time
22508449791SMatthew G. Knepley . locX  - Local solution
22608449791SMatthew G. Knepley . locX_t - Local solution time derivative, or NULL
22724cdb843SMatthew G. Knepley - user - The user context
22824cdb843SMatthew G. Knepley 
22924cdb843SMatthew G. Knepley   Output Parameter:
23008449791SMatthew G. Knepley . locF  - Local output vector
23124cdb843SMatthew G. Knepley 
23224cdb843SMatthew G. Knepley   Level: developer
23324cdb843SMatthew G. Knepley 
23424cdb843SMatthew G. Knepley .seealso: DMPlexComputeJacobianActionFEM()
23524cdb843SMatthew G. Knepley @*/
23608449791SMatthew G. Knepley PetscErrorCode DMPlexTSComputeIFunctionFEM(DM dm, PetscReal time, Vec locX, Vec locX_t, Vec locF, void *user)
23724cdb843SMatthew G. Knepley {
238c4d4a4f8SMatthew G. Knepley   PetscInt       cStart, cEnd, cEndInterior;
2396da023fcSToby Isaac   DM             plex;
24024cdb843SMatthew G. Knepley   PetscErrorCode ierr;
24124cdb843SMatthew G. Knepley 
24224cdb843SMatthew G. Knepley   PetscFunctionBegin;
2436da023fcSToby Isaac   ierr = DMTSConvertPlex(dm,&plex,PETSC_TRUE);CHKERRQ(ierr);
2446da023fcSToby Isaac   ierr = DMPlexGetHeightStratum(plex, 0, &cStart, &cEnd);CHKERRQ(ierr);
2456da023fcSToby Isaac   ierr = DMPlexGetHybridBounds(plex, &cEndInterior, NULL, NULL, NULL);CHKERRQ(ierr);
246c4d4a4f8SMatthew G. Knepley   cEnd = cEndInterior < 0 ? cEnd : cEndInterior;
2476da023fcSToby Isaac   ierr = DMPlexComputeResidual_Internal(plex, cStart, cEnd, time, locX, locX_t, locF, user);CHKERRQ(ierr);
248b2338dbcSToby Isaac   ierr = DMDestroy(&plex);CHKERRQ(ierr);
24924cdb843SMatthew G. Knepley   PetscFunctionReturn(0);
25024cdb843SMatthew G. Knepley }
2517cdb2a12SMatthew G. Knepley 
2527cdb2a12SMatthew G. Knepley #undef __FUNCT__
253756a1f44SMatthew G. Knepley #define __FUNCT__ "DMPlexTSComputeIJacobianFEM"
254756a1f44SMatthew G. Knepley /*@
255756a1f44SMatthew G. Knepley   DMPlexTSComputeIJacobianFEM - Form the local Jacobian J from the local input X using pointwise functions specified by the user
256756a1f44SMatthew G. Knepley 
257756a1f44SMatthew G. Knepley   Input Parameters:
258756a1f44SMatthew G. Knepley + dm - The mesh
259756a1f44SMatthew G. Knepley . t - The time
260756a1f44SMatthew G. Knepley . locX  - Local solution
261756a1f44SMatthew G. Knepley . locX_t - Local solution time derivative, or NULL
262756a1f44SMatthew G. Knepley . X_tshift - The multiplicative parameter for dF/du_t
263756a1f44SMatthew G. Knepley - user - The user context
264756a1f44SMatthew G. Knepley 
265756a1f44SMatthew G. Knepley   Output Parameter:
266756a1f44SMatthew G. Knepley . locF  - Local output vector
267756a1f44SMatthew G. Knepley 
268756a1f44SMatthew G. Knepley   Level: developer
269756a1f44SMatthew G. Knepley 
270756a1f44SMatthew G. Knepley .seealso: DMPlexComputeJacobianActionFEM()
271756a1f44SMatthew G. Knepley @*/
272756a1f44SMatthew G. Knepley PetscErrorCode DMPlexTSComputeIJacobianFEM(DM dm, PetscReal time, Vec locX, Vec locX_t, PetscReal X_tShift, Mat Jac, Mat JacP, void *user)
273756a1f44SMatthew G. Knepley {
274756a1f44SMatthew G. Knepley   PetscInt       cStart, cEnd, cEndInterior;
275756a1f44SMatthew G. Knepley   DM             plex;
276756a1f44SMatthew G. Knepley   PetscErrorCode ierr;
277756a1f44SMatthew G. Knepley 
278756a1f44SMatthew G. Knepley   PetscFunctionBegin;
279756a1f44SMatthew G. Knepley   ierr = DMTSConvertPlex(dm,&plex,PETSC_TRUE);CHKERRQ(ierr);
280756a1f44SMatthew G. Knepley   ierr = DMPlexGetHeightStratum(plex, 0, &cStart, &cEnd);CHKERRQ(ierr);
281756a1f44SMatthew G. Knepley   ierr = DMPlexGetHybridBounds(plex, &cEndInterior, NULL, NULL, NULL);CHKERRQ(ierr);
282756a1f44SMatthew G. Knepley   cEnd = cEndInterior < 0 ? cEnd : cEndInterior;
283756a1f44SMatthew G. Knepley   ierr = DMPlexComputeJacobian_Internal(plex, cStart, cEnd, time, X_tShift, locX, locX_t, Jac, JacP, user);CHKERRQ(ierr);
284756a1f44SMatthew G. Knepley   ierr = DMDestroy(&plex);CHKERRQ(ierr);
285756a1f44SMatthew G. Knepley   PetscFunctionReturn(0);
286756a1f44SMatthew G. Knepley }
287756a1f44SMatthew G. Knepley 
288756a1f44SMatthew G. Knepley #undef __FUNCT__
2897cdb2a12SMatthew G. Knepley #define __FUNCT__ "DMTSCheckFromOptions"
2900163fd50SMatthew G. Knepley PetscErrorCode DMTSCheckFromOptions(TS ts, Vec u, PetscErrorCode (**exactFuncs)(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nf, PetscScalar *u, void *ctx), void **ctxs)
2917cdb2a12SMatthew G. Knepley {
2927cdb2a12SMatthew G. Knepley   DM             dm;
2937cdb2a12SMatthew G. Knepley   SNES           snes;
2941878804aSMatthew G. Knepley   Vec            sol;
2957cdb2a12SMatthew G. Knepley   PetscBool      check;
2967cdb2a12SMatthew G. Knepley   PetscErrorCode ierr;
2977cdb2a12SMatthew G. Knepley 
2987cdb2a12SMatthew G. Knepley   PetscFunctionBegin;
299c5929fdfSBarry Smith   ierr = PetscOptionsHasName(((PetscObject)ts)->options,((PetscObject)ts)->prefix, "-dmts_check", &check);CHKERRQ(ierr);
3007cdb2a12SMatthew G. Knepley   if (!check) PetscFunctionReturn(0);
30172fd7fc8SMatthew G. Knepley   ierr = VecDuplicate(u, &sol);CHKERRQ(ierr);
30272fd7fc8SMatthew G. Knepley   ierr = TSSetSolution(ts, sol);CHKERRQ(ierr);
3037cdb2a12SMatthew G. Knepley   ierr = TSGetDM(ts, &dm);CHKERRQ(ierr);
3047cdb2a12SMatthew G. Knepley   ierr = TSSetUp(ts);CHKERRQ(ierr);
3057cdb2a12SMatthew G. Knepley   ierr = TSGetSNES(ts, &snes);CHKERRQ(ierr);
3067cdb2a12SMatthew G. Knepley   ierr = SNESSetSolution(snes, sol);CHKERRQ(ierr);
3071878804aSMatthew G. Knepley   ierr = DMSNESCheckFromOptions_Internal(snes, dm, u, sol, exactFuncs, ctxs);CHKERRQ(ierr);
30872fd7fc8SMatthew G. Knepley   ierr = VecDestroy(&sol);CHKERRQ(ierr);
3097cdb2a12SMatthew G. Knepley   PetscFunctionReturn(0);
3107cdb2a12SMatthew G. Knepley }
311