xref: /petsc/src/dm/impls/shell/dmshell.c (revision 95452b02e12c0ee11232c7ff2b24b568a8e07e43)
1fe1899a2SJed Brown #include <petscdmshell.h>       /*I    "petscdmshell.h"  I*/
207475bc1SBarry Smith #include <petscmat.h>
3af0996ceSBarry Smith #include <petsc/private/dmimpl.h>
4fe1899a2SJed Brown 
5fe1899a2SJed Brown typedef struct  {
6fe1899a2SJed Brown   Vec        Xglobal;
7dc43b69eSJed Brown   Vec        Xlocal;
8fe1899a2SJed Brown   Mat        A;
9a94b16f6SRichard Tran Mills   VecScatter gtol;
10a94b16f6SRichard Tran Mills   VecScatter ltog;
11f089877aSRichard Tran Mills   VecScatter ltol;
12fef3a512SBarry Smith   void       *ctx;
13fe1899a2SJed Brown } DM_Shell;
14fe1899a2SJed Brown 
157a108d1dSBarry Smith /*@
167a108d1dSBarry Smith    DMGlobalToLocalBeginDefaultShell - Uses the GlobalToLocal VecScatter context set by the user to begin a global to local scatter
178d359177SBarry Smith    Collective
188d359177SBarry Smith 
198d359177SBarry Smith    Input Arguments:
208d359177SBarry Smith +  dm - shell DM
218d359177SBarry Smith .  g - global vector
228d359177SBarry Smith .  mode - InsertMode
238d359177SBarry Smith -  l - local vector
248d359177SBarry Smith 
257a108d1dSBarry Smith    Level: advanced
268d359177SBarry Smith 
277a108d1dSBarry Smith    Note:  This is not normally called directly by user code, generally user code calls DMGlobalToLocalBegin() and DMGlobalToLocalEnd(). If the user provides their own custom routines to DMShellSetLocalToGlobal() then those routines might have reason to call this function.
287a108d1dSBarry Smith 
297a108d1dSBarry Smith .seealso: DMGlobalToLocalEndDefaultShell()
308d359177SBarry Smith @*/
317a108d1dSBarry Smith PetscErrorCode DMGlobalToLocalBeginDefaultShell(DM dm,Vec g,InsertMode mode,Vec l)
328d359177SBarry Smith {
338d359177SBarry Smith   PetscErrorCode ierr;
348d359177SBarry Smith   DM_Shell       *shell = (DM_Shell*)dm->data;
358d359177SBarry Smith 
368d359177SBarry Smith   PetscFunctionBegin;
377a108d1dSBarry Smith   if (!shell->gtol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetGlobalToLocalVecScatter()");
38a94b16f6SRichard Tran Mills   ierr = VecScatterBegin(shell->gtol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr);
398d359177SBarry Smith   PetscFunctionReturn(0);
408d359177SBarry Smith }
418d359177SBarry Smith 
427a108d1dSBarry Smith /*@
437a108d1dSBarry Smith    DMGlobalToLocalEndDefaultShell - Uses the GlobalToLocal VecScatter context set by the user to end a global to local scatter
448d359177SBarry Smith    Collective
458d359177SBarry Smith 
468d359177SBarry Smith    Input Arguments:
478d359177SBarry Smith +  dm - shell DM
488d359177SBarry Smith .  g - global vector
498d359177SBarry Smith .  mode - InsertMode
508d359177SBarry Smith -  l - local vector
518d359177SBarry Smith 
527a108d1dSBarry Smith    Level: advanced
538d359177SBarry Smith 
547a108d1dSBarry Smith .seealso: DMGlobalToLocalBeginDefaultShell()
558d359177SBarry Smith @*/
567a108d1dSBarry Smith PetscErrorCode DMGlobalToLocalEndDefaultShell(DM dm,Vec g,InsertMode mode,Vec l)
578d359177SBarry Smith {
588d359177SBarry Smith   PetscErrorCode ierr;
598d359177SBarry Smith   DM_Shell       *shell = (DM_Shell*)dm->data;
608d359177SBarry Smith 
618d359177SBarry Smith   PetscFunctionBegin;
627a108d1dSBarry Smith    if (!shell->gtol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetGlobalToLocalVecScatter()");
63a94b16f6SRichard Tran Mills   ierr = VecScatterEnd(shell->gtol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr);
648d359177SBarry Smith   PetscFunctionReturn(0);
658d359177SBarry Smith }
668d359177SBarry Smith 
67c5076b69SRichard Tran Mills /*@
68c5076b69SRichard Tran Mills    DMLocalToGlobalBeginDefaultShell - Uses the LocalToGlobal VecScatter context set by the user to begin a local to global scatter
69c5076b69SRichard Tran Mills    Collective
70c5076b69SRichard Tran Mills 
71c5076b69SRichard Tran Mills    Input Arguments:
72c5076b69SRichard Tran Mills +  dm - shell DM
73c5076b69SRichard Tran Mills .  l - local vector
74c5076b69SRichard Tran Mills .  mode - InsertMode
75c5076b69SRichard Tran Mills -  g - global vector
76c5076b69SRichard Tran Mills 
77c5076b69SRichard Tran Mills    Level: advanced
78c5076b69SRichard Tran Mills 
79c5076b69SRichard Tran Mills    Note:  This is not normally called directly by user code, generally user code calls DMLocalToGlobalBegin() and DMLocalToGlobalEnd(). If the user provides their own custom routines to DMShellSetLocalToGlobal() then those routines might have reason to call this function.
80c5076b69SRichard Tran Mills 
81c5076b69SRichard Tran Mills .seealso: DMLocalToGlobalEndDefaultShell()
82c5076b69SRichard Tran Mills @*/
83c5076b69SRichard Tran Mills PetscErrorCode DMLocalToGlobalBeginDefaultShell(DM dm,Vec l,InsertMode mode,Vec g)
84c5076b69SRichard Tran Mills {
85c5076b69SRichard Tran Mills   PetscErrorCode ierr;
86c5076b69SRichard Tran Mills   DM_Shell       *shell = (DM_Shell*)dm->data;
87c5076b69SRichard Tran Mills 
88c5076b69SRichard Tran Mills   PetscFunctionBegin;
89c5076b69SRichard Tran Mills   if (!shell->ltog) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetLocalToGlobalVecScatter()");
90a94b16f6SRichard Tran Mills   ierr = VecScatterBegin(shell->ltog,l,g,mode,SCATTER_FORWARD);CHKERRQ(ierr);
91c5076b69SRichard Tran Mills   PetscFunctionReturn(0);
92c5076b69SRichard Tran Mills }
93c5076b69SRichard Tran Mills 
94c5076b69SRichard Tran Mills /*@
95c5076b69SRichard Tran Mills    DMLocalToGlobalEndDefaultShell - Uses the LocalToGlobal VecScatter context set by the user to end a local to global scatter
96c5076b69SRichard Tran Mills    Collective
97c5076b69SRichard Tran Mills 
98c5076b69SRichard Tran Mills    Input Arguments:
99c5076b69SRichard Tran Mills +  dm - shell DM
100c5076b69SRichard Tran Mills .  l - local vector
101c5076b69SRichard Tran Mills .  mode - InsertMode
102c5076b69SRichard Tran Mills -  g - global vector
103c5076b69SRichard Tran Mills 
104c5076b69SRichard Tran Mills    Level: advanced
105c5076b69SRichard Tran Mills 
106c5076b69SRichard Tran Mills .seealso: DMLocalToGlobalBeginDefaultShell()
107c5076b69SRichard Tran Mills @*/
108c5076b69SRichard Tran Mills PetscErrorCode DMLocalToGlobalEndDefaultShell(DM dm,Vec l,InsertMode mode,Vec g)
109c5076b69SRichard Tran Mills {
110c5076b69SRichard Tran Mills   PetscErrorCode ierr;
111c5076b69SRichard Tran Mills   DM_Shell       *shell = (DM_Shell*)dm->data;
112c5076b69SRichard Tran Mills 
113c5076b69SRichard Tran Mills   PetscFunctionBegin;
114c5076b69SRichard Tran Mills    if (!shell->ltog) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetLocalToGlobalVecScatter()");
115a94b16f6SRichard Tran Mills   ierr = VecScatterEnd(shell->ltog,l,g,mode,SCATTER_FORWARD);CHKERRQ(ierr);
116c5076b69SRichard Tran Mills   PetscFunctionReturn(0);
117c5076b69SRichard Tran Mills }
118c5076b69SRichard Tran Mills 
119f3db62a7SRichard Tran Mills /*@
120f3db62a7SRichard Tran Mills    DMLocalToLocalBeginDefaultShell - Uses the LocalToLocal VecScatter context set by the user to begin a local to local scatter
121f3db62a7SRichard Tran Mills    Collective
122f3db62a7SRichard Tran Mills 
123f3db62a7SRichard Tran Mills    Input Arguments:
124f3db62a7SRichard Tran Mills +  dm - shell DM
125f3db62a7SRichard Tran Mills .  g - the original local vector
126f3db62a7SRichard Tran Mills -  mode - InsertMode
127f3db62a7SRichard Tran Mills 
128f3db62a7SRichard Tran Mills    Output Parameter:
129f3db62a7SRichard Tran Mills .  l  - the local vector with correct ghost values
130f3db62a7SRichard Tran Mills 
131f3db62a7SRichard Tran Mills    Level: advanced
132f3db62a7SRichard Tran Mills 
133f3db62a7SRichard Tran Mills    Note:  This is not normally called directly by user code, generally user code calls DMLocalToLocalBegin() and DMLocalToLocalEnd(). If the user provides their own custom routines to DMShellSetLocalToLocal() then those routines might have reason to call this function.
134f3db62a7SRichard Tran Mills 
135f3db62a7SRichard Tran Mills .seealso: DMLocalToLocalEndDefaultShell()
136f3db62a7SRichard Tran Mills @*/
137f3db62a7SRichard Tran Mills PetscErrorCode DMLocalToLocalBeginDefaultShell(DM dm,Vec g,InsertMode mode,Vec l)
138f3db62a7SRichard Tran Mills {
139f3db62a7SRichard Tran Mills   PetscErrorCode ierr;
140f3db62a7SRichard Tran Mills   DM_Shell       *shell = (DM_Shell*)dm->data;
141f3db62a7SRichard Tran Mills 
142f3db62a7SRichard Tran Mills   PetscFunctionBegin;
143f3db62a7SRichard Tran Mills   if (!shell->ltol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetLocalToLocalVecScatter()");
144f3db62a7SRichard Tran Mills   ierr = VecScatterBegin(shell->ltol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr);
145f3db62a7SRichard Tran Mills   PetscFunctionReturn(0);
146f3db62a7SRichard Tran Mills }
147f3db62a7SRichard Tran Mills 
148f3db62a7SRichard Tran Mills /*@
149f3db62a7SRichard Tran Mills    DMLocalToLocalEndDefaultShell - Uses the LocalToLocal VecScatter context set by the user to end a local to local scatter
150f3db62a7SRichard Tran Mills    Collective
151f3db62a7SRichard Tran Mills 
152f3db62a7SRichard Tran Mills    Input Arguments:
153f3db62a7SRichard Tran Mills +  dm - shell DM
154f3db62a7SRichard Tran Mills .  g - the original local vector
155f3db62a7SRichard Tran Mills -  mode - InsertMode
156f3db62a7SRichard Tran Mills 
157f3db62a7SRichard Tran Mills    Output Parameter:
158f3db62a7SRichard Tran Mills .  l  - the local vector with correct ghost values
159f3db62a7SRichard Tran Mills 
160f3db62a7SRichard Tran Mills    Level: advanced
161f3db62a7SRichard Tran Mills 
162f3db62a7SRichard Tran Mills .seealso: DMLocalToLocalBeginDefaultShell()
163f3db62a7SRichard Tran Mills @*/
164f3db62a7SRichard Tran Mills PetscErrorCode DMLocalToLocalEndDefaultShell(DM dm,Vec g,InsertMode mode,Vec l)
165f3db62a7SRichard Tran Mills {
166f3db62a7SRichard Tran Mills   PetscErrorCode ierr;
167f3db62a7SRichard Tran Mills   DM_Shell       *shell = (DM_Shell*)dm->data;
168f3db62a7SRichard Tran Mills 
169f3db62a7SRichard Tran Mills   PetscFunctionBegin;
170f3db62a7SRichard Tran Mills    if (!shell->ltol) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE, "Cannot be used without first setting the scatter context via DMShellSetGlobalToLocalVecScatter()");
171f3db62a7SRichard Tran Mills   ierr = VecScatterEnd(shell->ltol,g,l,mode,SCATTER_FORWARD);CHKERRQ(ierr);
172f3db62a7SRichard Tran Mills   PetscFunctionReturn(0);
173f3db62a7SRichard Tran Mills }
174c5076b69SRichard Tran Mills 
175b412c318SBarry Smith static PetscErrorCode DMCreateMatrix_Shell(DM dm,Mat *J)
176fe1899a2SJed Brown {
177fe1899a2SJed Brown   PetscErrorCode ierr;
178fe1899a2SJed Brown   DM_Shell       *shell = (DM_Shell*)dm->data;
179fe1899a2SJed Brown   Mat            A;
180fe1899a2SJed Brown 
181fe1899a2SJed Brown   PetscFunctionBegin;
182fe1899a2SJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
183fe1899a2SJed Brown   PetscValidPointer(J,3);
1847bde9f88SJed Brown   if (!shell->A) {
1857bde9f88SJed Brown     if (shell->Xglobal) {
1867bde9f88SJed Brown       PetscInt m,M;
187955c1f14SBarry Smith       ierr = PetscInfo(dm,"Naively creating matrix using global vector distribution without preallocation\n");CHKERRQ(ierr);
1887bde9f88SJed Brown       ierr = VecGetSize(shell->Xglobal,&M);CHKERRQ(ierr);
1897bde9f88SJed Brown       ierr = VecGetLocalSize(shell->Xglobal,&m);CHKERRQ(ierr);
190ce94432eSBarry Smith       ierr = MatCreate(PetscObjectComm((PetscObject)dm),&shell->A);CHKERRQ(ierr);
1917bde9f88SJed Brown       ierr = MatSetSizes(shell->A,m,m,M,M);CHKERRQ(ierr);
192b412c318SBarry Smith       ierr = MatSetType(shell->A,dm->mattype);CHKERRQ(ierr);
1937bde9f88SJed Brown       ierr = MatSetUp(shell->A);CHKERRQ(ierr);
194ce94432eSBarry Smith     } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetMatrix(), DMShellSetCreateMatrix(), or provide a vector");
1957bde9f88SJed Brown   }
196fe1899a2SJed Brown   A = shell->A;
197ad6bc421SBarry Smith   /* the check below is tacky and incomplete */
198b412c318SBarry Smith   if (dm->mattype) {
199ad6bc421SBarry Smith     PetscBool flg,aij,seqaij,mpiaij;
200b412c318SBarry Smith     ierr = PetscObjectTypeCompare((PetscObject)A,dm->mattype,&flg);CHKERRQ(ierr);
201ad6bc421SBarry Smith     ierr = PetscObjectTypeCompare((PetscObject)A,MATSEQAIJ,&seqaij);CHKERRQ(ierr);
202ad6bc421SBarry Smith     ierr = PetscObjectTypeCompare((PetscObject)A,MATMPIAIJ,&mpiaij);CHKERRQ(ierr);
203b412c318SBarry Smith     ierr = PetscStrcmp(dm->mattype,MATAIJ,&aij);CHKERRQ(ierr);
204ad6bc421SBarry Smith     if (!flg) {
205b412c318SBarry Smith       if (!(aij && (seqaij || mpiaij))) SETERRQ2(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_NOTSAMETYPE,"Requested matrix of type %s, but only %s available",dm->mattype,((PetscObject)A)->type_name);
206ad6bc421SBarry Smith     }
207fe1899a2SJed Brown   }
208fe1899a2SJed Brown   if (((PetscObject)A)->refct < 2) { /* We have an exclusive reference so we can give it out */
209fe1899a2SJed Brown     ierr = PetscObjectReference((PetscObject)A);CHKERRQ(ierr);
210fe1899a2SJed Brown     ierr = MatZeroEntries(A);CHKERRQ(ierr);
211fe1899a2SJed Brown     *J   = A;
212fe1899a2SJed Brown   } else {                      /* Need to create a copy, could use MAT_SHARE_NONZERO_PATTERN in most cases */
213fe1899a2SJed Brown     ierr = MatDuplicate(A,MAT_DO_NOT_COPY_VALUES,J);CHKERRQ(ierr);
214fe1899a2SJed Brown     ierr = MatZeroEntries(*J);CHKERRQ(ierr);
215fe1899a2SJed Brown   }
216fe1899a2SJed Brown   PetscFunctionReturn(0);
217fe1899a2SJed Brown }
218fe1899a2SJed Brown 
219fe1899a2SJed Brown PetscErrorCode DMCreateGlobalVector_Shell(DM dm,Vec *gvec)
220fe1899a2SJed Brown {
221fe1899a2SJed Brown   PetscErrorCode ierr;
222fe1899a2SJed Brown   DM_Shell       *shell = (DM_Shell*)dm->data;
223fe1899a2SJed Brown   Vec            X;
224fe1899a2SJed Brown 
225fe1899a2SJed Brown   PetscFunctionBegin;
226fe1899a2SJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
227fe1899a2SJed Brown   PetscValidPointer(gvec,2);
228fe1899a2SJed Brown   *gvec = 0;
229fe1899a2SJed Brown   X     = shell->Xglobal;
230ce94432eSBarry Smith   if (!X) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetGlobalVector() or DMShellSetCreateGlobalVector()");
231fe1899a2SJed Brown   if (((PetscObject)X)->refct < 2) { /* We have an exclusive reference so we can give it out */
232fe1899a2SJed Brown     ierr  = PetscObjectReference((PetscObject)X);CHKERRQ(ierr);
233fe1899a2SJed Brown     ierr  = VecZeroEntries(X);CHKERRQ(ierr);
234fe1899a2SJed Brown     *gvec = X;
235fe1899a2SJed Brown   } else {                      /* Need to create a copy, could use MAT_SHARE_NONZERO_PATTERN in most cases */
236fe1899a2SJed Brown     ierr = VecDuplicate(X,gvec);CHKERRQ(ierr);
237fe1899a2SJed Brown     ierr = VecZeroEntries(*gvec);CHKERRQ(ierr);
238fe1899a2SJed Brown   }
239c688c046SMatthew G Knepley   ierr = VecSetDM(*gvec,dm);CHKERRQ(ierr);
240fe1899a2SJed Brown   PetscFunctionReturn(0);
241fe1899a2SJed Brown }
242fe1899a2SJed Brown 
243dc43b69eSJed Brown PetscErrorCode DMCreateLocalVector_Shell(DM dm,Vec *gvec)
244dc43b69eSJed Brown {
245dc43b69eSJed Brown   PetscErrorCode ierr;
246dc43b69eSJed Brown   DM_Shell       *shell = (DM_Shell*)dm->data;
247dc43b69eSJed Brown   Vec            X;
248dc43b69eSJed Brown 
249dc43b69eSJed Brown   PetscFunctionBegin;
250dc43b69eSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
251dc43b69eSJed Brown   PetscValidPointer(gvec,2);
252dc43b69eSJed Brown   *gvec = 0;
253dc43b69eSJed Brown   X     = shell->Xlocal;
254ce94432eSBarry Smith   if (!X) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_USER,"Must call DMShellSetLocalVector() or DMShellSetCreateLocalVector()");
255dc43b69eSJed Brown   if (((PetscObject)X)->refct < 2) { /* We have an exclusive reference so we can give it out */
256dc43b69eSJed Brown     ierr  = PetscObjectReference((PetscObject)X);CHKERRQ(ierr);
257dc43b69eSJed Brown     ierr  = VecZeroEntries(X);CHKERRQ(ierr);
258dc43b69eSJed Brown     *gvec = X;
259dc43b69eSJed Brown   } else {                      /* Need to create a copy, could use MAT_SHARE_NONZERO_PATTERN in most cases */
260dc43b69eSJed Brown     ierr = VecDuplicate(X,gvec);CHKERRQ(ierr);
261dc43b69eSJed Brown     ierr = VecZeroEntries(*gvec);CHKERRQ(ierr);
262dc43b69eSJed Brown   }
2636e4cbd8bSMark F. Adams   ierr = VecSetDM(*gvec,dm);CHKERRQ(ierr);
264dc43b69eSJed Brown   PetscFunctionReturn(0);
265dc43b69eSJed Brown }
266dc43b69eSJed Brown 
267fef3a512SBarry Smith /*@
268fef3a512SBarry Smith    DMShellSetContext - set some data to be usable by this DM
269fef3a512SBarry Smith 
270fef3a512SBarry Smith    Collective
271fef3a512SBarry Smith 
272fef3a512SBarry Smith    Input Arguments:
273fef3a512SBarry Smith +  dm - shell DM
274fef3a512SBarry Smith -  ctx - the context
275fef3a512SBarry Smith 
276fef3a512SBarry Smith    Level: advanced
277fef3a512SBarry Smith 
278fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellGetContext()
279fef3a512SBarry Smith @*/
280fef3a512SBarry Smith PetscErrorCode DMShellSetContext(DM dm,void *ctx)
281fef3a512SBarry Smith {
282fef3a512SBarry Smith   DM_Shell       *shell = (DM_Shell*)dm->data;
283fef3a512SBarry Smith   PetscErrorCode ierr;
284fef3a512SBarry Smith   PetscBool      isshell;
285fef3a512SBarry Smith 
286fef3a512SBarry Smith   PetscFunctionBegin;
287fef3a512SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
288fef3a512SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
289fef3a512SBarry Smith   if (!isshell) PetscFunctionReturn(0);
290fef3a512SBarry Smith   shell->ctx = ctx;
291fef3a512SBarry Smith   PetscFunctionReturn(0);
292fef3a512SBarry Smith }
293fef3a512SBarry Smith 
294fef3a512SBarry Smith /*@
295fef3a512SBarry Smith    DMShellGetContext - set some data to be usable by this DM
296fef3a512SBarry Smith 
297fef3a512SBarry Smith    Collective
298fef3a512SBarry Smith 
299fef3a512SBarry Smith    Input Argument:
300fef3a512SBarry Smith .  dm - shell DM
301fef3a512SBarry Smith 
302fef3a512SBarry Smith    Output Argument:
303fef3a512SBarry Smith .  ctx - the context
304fef3a512SBarry Smith 
305fef3a512SBarry Smith    Level: advanced
306fef3a512SBarry Smith 
307fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetContext()
308fef3a512SBarry Smith @*/
309fef3a512SBarry Smith PetscErrorCode DMShellGetContext(DM dm,void **ctx)
310fef3a512SBarry Smith {
311fef3a512SBarry Smith   DM_Shell       *shell = (DM_Shell*)dm->data;
312fef3a512SBarry Smith   PetscErrorCode ierr;
313fef3a512SBarry Smith   PetscBool      isshell;
314fef3a512SBarry Smith 
315fef3a512SBarry Smith   PetscFunctionBegin;
316fef3a512SBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
317fef3a512SBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
318fef3a512SBarry Smith   if (!isshell) PetscFunctionReturn(0);
319fef3a512SBarry Smith   *ctx = shell->ctx;
320fef3a512SBarry Smith   PetscFunctionReturn(0);
321fef3a512SBarry Smith }
322fef3a512SBarry Smith 
323fe1899a2SJed Brown /*@
324fe1899a2SJed Brown    DMShellSetMatrix - sets a template matrix associated with the DMShell
325fe1899a2SJed Brown 
326fe1899a2SJed Brown    Collective
327fe1899a2SJed Brown 
328fe1899a2SJed Brown    Input Arguments:
329fe1899a2SJed Brown +  dm - shell DM
330fe1899a2SJed Brown -  J - template matrix
331fe1899a2SJed Brown 
332fe1899a2SJed Brown    Level: advanced
333fe1899a2SJed Brown 
334fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext()
335fe1899a2SJed Brown @*/
336fe1899a2SJed Brown PetscErrorCode DMShellSetMatrix(DM dm,Mat J)
337fe1899a2SJed Brown {
338fe1899a2SJed Brown   DM_Shell       *shell = (DM_Shell*)dm->data;
339fe1899a2SJed Brown   PetscErrorCode ierr;
3408c87107bSJed Brown   PetscBool      isshell;
341fe1899a2SJed Brown 
342fe1899a2SJed Brown   PetscFunctionBegin;
3438c87107bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
3448c87107bSJed Brown   PetscValidHeaderSpecific(J,MAT_CLASSID,2);
345251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
3468c87107bSJed Brown   if (!isshell) PetscFunctionReturn(0);
347fe1899a2SJed Brown   ierr     = PetscObjectReference((PetscObject)J);CHKERRQ(ierr);
348fe1899a2SJed Brown   ierr     = MatDestroy(&shell->A);CHKERRQ(ierr);
349fe1899a2SJed Brown   shell->A = J;
350fe1899a2SJed Brown   PetscFunctionReturn(0);
351fe1899a2SJed Brown }
352fe1899a2SJed Brown 
353fe1899a2SJed Brown /*@C
354fe1899a2SJed Brown    DMShellSetCreateMatrix - sets the routine to create a matrix associated with the shell DM
355fe1899a2SJed Brown 
356fe1899a2SJed Brown    Logically Collective on DM
357fe1899a2SJed Brown 
358fe1899a2SJed Brown    Input Arguments:
359fe1899a2SJed Brown +  dm - the shell DM
360fe1899a2SJed Brown -  func - the function to create a matrix
361fe1899a2SJed Brown 
362fe1899a2SJed Brown    Level: advanced
363fe1899a2SJed Brown 
364fef3a512SBarry Smith .seealso: DMCreateMatrix(), DMShellSetMatrix(), DMShellSetContext(), DMShellGetContext()
365fe1899a2SJed Brown @*/
366b412c318SBarry Smith PetscErrorCode DMShellSetCreateMatrix(DM dm,PetscErrorCode (*func)(DM,Mat*))
367fe1899a2SJed Brown {
368fe1899a2SJed Brown 
369fe1899a2SJed Brown   PetscFunctionBegin;
370fe1899a2SJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
371fe1899a2SJed Brown   dm->ops->creatematrix = func;
372fe1899a2SJed Brown   PetscFunctionReturn(0);
373fe1899a2SJed Brown }
374fe1899a2SJed Brown 
375fe1899a2SJed Brown /*@
376fe1899a2SJed Brown    DMShellSetGlobalVector - sets a template global vector associated with the DMShell
377fe1899a2SJed Brown 
378fe1899a2SJed Brown    Logically Collective on DM
379fe1899a2SJed Brown 
380fe1899a2SJed Brown    Input Arguments:
381fe1899a2SJed Brown +  dm - shell DM
382fe1899a2SJed Brown -  X - template vector
383fe1899a2SJed Brown 
384fe1899a2SJed Brown    Level: advanced
385fe1899a2SJed Brown 
386fe1899a2SJed Brown .seealso: DMCreateGlobalVector(), DMShellSetMatrix(), DMShellSetCreateGlobalVector()
387fe1899a2SJed Brown @*/
388fe1899a2SJed Brown PetscErrorCode DMShellSetGlobalVector(DM dm,Vec X)
389fe1899a2SJed Brown {
390fe1899a2SJed Brown   DM_Shell       *shell = (DM_Shell*)dm->data;
391fe1899a2SJed Brown   PetscErrorCode ierr;
3928c87107bSJed Brown   PetscBool      isshell;
393cca7ec1eSBarry Smith   DM             vdm;
394fe1899a2SJed Brown 
395fe1899a2SJed Brown   PetscFunctionBegin;
3968c87107bSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
3978c87107bSJed Brown   PetscValidHeaderSpecific(X,VEC_CLASSID,2);
398251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
3998c87107bSJed Brown   if (!isshell) PetscFunctionReturn(0);
400cca7ec1eSBarry Smith   ierr = VecGetDM(X,&vdm);CHKERRQ(ierr);
401cca7ec1eSBarry Smith   /*
402cca7ec1eSBarry Smith       if the vector proposed as the new base global vector for the DM is a DM vector associated
403cca7ec1eSBarry Smith       with the same DM then the current base global vector for the DM is ok and if we replace it with the new one
404cca7ec1eSBarry Smith       we get a circular dependency that prevents the DM from being destroy when it should be.
405cca7ec1eSBarry Smith       This occurs when SNESSet/GetNPC() is used with a SNES that does not have a user provided
406cca7ec1eSBarry Smith       DM attached to it since the inner SNES (which shares the DM with the outer SNES) tries
407cca7ec1eSBarry Smith       to set its input vector (which is associated with the DM) as the base global vector.
408cca7ec1eSBarry Smith       Thanks to Juan P. Mendez Granado Re: [petsc-maint] Nonlinear conjugate gradien
409cca7ec1eSBarry Smith       for pointing out the problem.
410cca7ec1eSBarry Smith    */
411cca7ec1eSBarry Smith   if (vdm == dm) PetscFunctionReturn(0);
412fe1899a2SJed Brown   ierr           = PetscObjectReference((PetscObject)X);CHKERRQ(ierr);
413fe1899a2SJed Brown   ierr           = VecDestroy(&shell->Xglobal);CHKERRQ(ierr);
414fe1899a2SJed Brown   shell->Xglobal = X;
415fe1899a2SJed Brown   PetscFunctionReturn(0);
416fe1899a2SJed Brown }
417fe1899a2SJed Brown 
418fe1899a2SJed Brown /*@C
419fe1899a2SJed Brown    DMShellSetCreateGlobalVector - sets the routine to create a global vector associated with the shell DM
420fe1899a2SJed Brown 
421fe1899a2SJed Brown    Logically Collective
422fe1899a2SJed Brown 
423fe1899a2SJed Brown    Input Arguments:
424fe1899a2SJed Brown +  dm - the shell DM
425fe1899a2SJed Brown -  func - the creation routine
426fe1899a2SJed Brown 
427fe1899a2SJed Brown    Level: advanced
428fe1899a2SJed Brown 
429fef3a512SBarry Smith .seealso: DMShellSetGlobalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext()
430fe1899a2SJed Brown @*/
431fe1899a2SJed Brown PetscErrorCode DMShellSetCreateGlobalVector(DM dm,PetscErrorCode (*func)(DM,Vec*))
432fe1899a2SJed Brown {
433fe1899a2SJed Brown 
434fe1899a2SJed Brown   PetscFunctionBegin;
435fe1899a2SJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
436fe1899a2SJed Brown   dm->ops->createglobalvector = func;
437fe1899a2SJed Brown   PetscFunctionReturn(0);
438fe1899a2SJed Brown }
439fe1899a2SJed Brown 
440dc43b69eSJed Brown /*@
441dc43b69eSJed Brown    DMShellSetLocalVector - sets a template local vector associated with the DMShell
442dc43b69eSJed Brown 
443dc43b69eSJed Brown    Logically Collective on DM
444dc43b69eSJed Brown 
445dc43b69eSJed Brown    Input Arguments:
446dc43b69eSJed Brown +  dm - shell DM
447dc43b69eSJed Brown -  X - template vector
448dc43b69eSJed Brown 
449dc43b69eSJed Brown    Level: advanced
450dc43b69eSJed Brown 
451dc43b69eSJed Brown .seealso: DMCreateLocalVector(), DMShellSetMatrix(), DMShellSetCreateLocalVector()
452dc43b69eSJed Brown @*/
453dc43b69eSJed Brown PetscErrorCode DMShellSetLocalVector(DM dm,Vec X)
454dc43b69eSJed Brown {
455dc43b69eSJed Brown   DM_Shell       *shell = (DM_Shell*)dm->data;
456dc43b69eSJed Brown   PetscErrorCode ierr;
457dc43b69eSJed Brown   PetscBool      isshell;
458cca7ec1eSBarry Smith   DM             vdm;
459dc43b69eSJed Brown 
460dc43b69eSJed Brown   PetscFunctionBegin;
461dc43b69eSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
462dc43b69eSJed Brown   PetscValidHeaderSpecific(X,VEC_CLASSID,2);
463dc43b69eSJed Brown   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
464dc43b69eSJed Brown   if (!isshell) PetscFunctionReturn(0);
465cca7ec1eSBarry Smith   ierr           = VecGetDM(X,&vdm);CHKERRQ(ierr);
466cca7ec1eSBarry Smith   /*
467cca7ec1eSBarry Smith       if the vector proposed as the new base global vector for the DM is a DM vector associated
468cca7ec1eSBarry Smith       with the same DM then the current base global vector for the DM is ok and if we replace it with the new one
469cca7ec1eSBarry Smith       we get a circular dependency that prevents the DM from being destroy when it should be.
470cca7ec1eSBarry Smith       This occurs when SNESSet/GetNPC() is used with a SNES that does not have a user provided
471cca7ec1eSBarry Smith       DM attached to it since the inner SNES (which shares the DM with the outer SNES) tries
472cca7ec1eSBarry Smith       to set its input vector (which is associated with the DM) as the base global vector.
473cca7ec1eSBarry Smith       Thanks to Juan P. Mendez Granado Re: [petsc-maint] Nonlinear conjugate gradien
474cca7ec1eSBarry Smith       for pointing out the problem.
475cca7ec1eSBarry Smith    */
476cca7ec1eSBarry Smith   if (vdm == dm) PetscFunctionReturn(0);
477dc43b69eSJed Brown   ierr = PetscObjectReference((PetscObject)X);CHKERRQ(ierr);
478dc43b69eSJed Brown   ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr);
479dc43b69eSJed Brown   shell->Xlocal = X;
480dc43b69eSJed Brown   PetscFunctionReturn(0);
481dc43b69eSJed Brown }
482dc43b69eSJed Brown 
483dc43b69eSJed Brown /*@C
484dc43b69eSJed Brown    DMShellSetCreateLocalVector - sets the routine to create a local vector associated with the shell DM
485dc43b69eSJed Brown 
486dc43b69eSJed Brown    Logically Collective
487dc43b69eSJed Brown 
488dc43b69eSJed Brown    Input Arguments:
489dc43b69eSJed Brown +  dm - the shell DM
490dc43b69eSJed Brown -  func - the creation routine
491dc43b69eSJed Brown 
492dc43b69eSJed Brown    Level: advanced
493dc43b69eSJed Brown 
494fef3a512SBarry Smith .seealso: DMShellSetLocalVector(), DMShellSetCreateMatrix(), DMShellSetContext(), DMShellGetContext()
495dc43b69eSJed Brown @*/
496dc43b69eSJed Brown PetscErrorCode DMShellSetCreateLocalVector(DM dm,PetscErrorCode (*func)(DM,Vec*))
497dc43b69eSJed Brown {
498dc43b69eSJed Brown 
499dc43b69eSJed Brown   PetscFunctionBegin;
500dc43b69eSJed Brown   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
501dc43b69eSJed Brown   dm->ops->createlocalvector = func;
502dc43b69eSJed Brown   PetscFunctionReturn(0);
503dc43b69eSJed Brown }
504dc43b69eSJed Brown 
5058339e6d0SRichard Tran Mills /*@C
5068339e6d0SRichard Tran Mills    DMShellSetGlobalToLocal - Sets the routines used to perform a global to local scatter
5078339e6d0SRichard Tran Mills 
5088339e6d0SRichard Tran Mills    Logically Collective on DM
5098339e6d0SRichard Tran Mills 
5108339e6d0SRichard Tran Mills    Input Arguments
5118339e6d0SRichard Tran Mills +  dm - the shell DM
5128339e6d0SRichard Tran Mills .  begin - the routine that begins the global to local scatter
5138339e6d0SRichard Tran Mills -  end - the routine that ends the global to local scatter
5148339e6d0SRichard Tran Mills 
515*95452b02SPatrick Sanan    Notes:
516*95452b02SPatrick Sanan     If these functions are not provided but DMShellSetGlobalToLocalVecScatter() is called then
517f3db62a7SRichard Tran Mills    DMGlobalToLocalBeginDefaultShell()/DMGlobalToLocalEndDefaultShell() are used to to perform the transfers
5187a108d1dSBarry Smith 
5198339e6d0SRichard Tran Mills    Level: advanced
5208339e6d0SRichard Tran Mills 
5217a108d1dSBarry Smith .seealso: DMShellSetLocalToGlobal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell()
5228339e6d0SRichard Tran Mills @*/
5238339e6d0SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) {
5248339e6d0SRichard Tran Mills   PetscFunctionBegin;
5258339e6d0SRichard Tran Mills   dm->ops->globaltolocalbegin = begin;
5268339e6d0SRichard Tran Mills   dm->ops->globaltolocalend = end;
5278339e6d0SRichard Tran Mills   PetscFunctionReturn(0);
5288339e6d0SRichard Tran Mills }
5298339e6d0SRichard Tran Mills 
5308339e6d0SRichard Tran Mills /*@C
5318339e6d0SRichard Tran Mills    DMShellSetLocalToGlobal - Sets the routines used to perform a local to global scatter
5328339e6d0SRichard Tran Mills 
5338339e6d0SRichard Tran Mills    Logically Collective on DM
5348339e6d0SRichard Tran Mills 
5358339e6d0SRichard Tran Mills    Input Arguments
5368339e6d0SRichard Tran Mills +  dm - the shell DM
5378339e6d0SRichard Tran Mills .  begin - the routine that begins the local to global scatter
5388339e6d0SRichard Tran Mills -  end - the routine that ends the local to global scatter
5398339e6d0SRichard Tran Mills 
540*95452b02SPatrick Sanan    Notes:
541*95452b02SPatrick Sanan     If these functions are not provided but DMShellSetLocalToGlobalVecScatter() is called then
542f3db62a7SRichard Tran Mills    DMLocalToGlobalBeginDefaultShell()/DMLocalToGlobalEndDefaultShell() are used to to perform the transfers
543f3db62a7SRichard Tran Mills 
5448339e6d0SRichard Tran Mills    Level: advanced
5458339e6d0SRichard Tran Mills 
5468339e6d0SRichard Tran Mills .seealso: DMShellSetGlobalToLocal()
5478339e6d0SRichard Tran Mills @*/
5488339e6d0SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) {
5498339e6d0SRichard Tran Mills   PetscFunctionBegin;
5508339e6d0SRichard Tran Mills   dm->ops->localtoglobalbegin = begin;
5518339e6d0SRichard Tran Mills   dm->ops->localtoglobalend = end;
5528339e6d0SRichard Tran Mills   PetscFunctionReturn(0);
5538339e6d0SRichard Tran Mills }
5548339e6d0SRichard Tran Mills 
555f3db62a7SRichard Tran Mills /*@C
556f3db62a7SRichard Tran Mills    DMShellSetLocalToLocal - Sets the routines used to perform a local to local scatter
557f3db62a7SRichard Tran Mills 
558f3db62a7SRichard Tran Mills    Logically Collective on DM
559f3db62a7SRichard Tran Mills 
560f3db62a7SRichard Tran Mills    Input Arguments
561f3db62a7SRichard Tran Mills +  dm - the shell DM
562f3db62a7SRichard Tran Mills .  begin - the routine that begins the local to local scatter
563f3db62a7SRichard Tran Mills -  end - the routine that ends the local to local scatter
564f3db62a7SRichard Tran Mills 
565*95452b02SPatrick Sanan    Notes:
566*95452b02SPatrick Sanan     If these functions are not provided but DMShellSetLocalToLocalVecScatter() is called then
567f3db62a7SRichard Tran Mills    DMLocalToLocalBeginDefaultShell()/DMLocalToLocalEndDefaultShell() are used to to perform the transfers
568f3db62a7SRichard Tran Mills 
569f3db62a7SRichard Tran Mills    Level: advanced
570f3db62a7SRichard Tran Mills 
571f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell()
572f3db62a7SRichard Tran Mills @*/
573f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocal(DM dm,PetscErrorCode (*begin)(DM,Vec,InsertMode,Vec),PetscErrorCode (*end)(DM,Vec,InsertMode,Vec)) {
574f3db62a7SRichard Tran Mills   PetscFunctionBegin;
575f3db62a7SRichard Tran Mills   dm->ops->localtolocalbegin = begin;
576f3db62a7SRichard Tran Mills   dm->ops->localtolocalend = end;
577f3db62a7SRichard Tran Mills   PetscFunctionReturn(0);
578f3db62a7SRichard Tran Mills }
579f3db62a7SRichard Tran Mills 
58081634712SRichard Tran Mills /*@
58181634712SRichard Tran Mills    DMShellSetGlobalToLocalVecScatter - Sets a VecScatter context for global to local communication
58281634712SRichard Tran Mills 
58381634712SRichard Tran Mills    Logically Collective on DM
58481634712SRichard Tran Mills 
58581634712SRichard Tran Mills    Input Arguments
58681634712SRichard Tran Mills +  dm - the shell DM
58781634712SRichard Tran Mills -  gtol - the global to local VecScatter context
58881634712SRichard Tran Mills 
58981634712SRichard Tran Mills    Level: advanced
59081634712SRichard Tran Mills 
591f3db62a7SRichard Tran Mills .seealso: DMShellSetGlobalToLocal(), DMGlobalToLocalBeginDefaultShell(), DMGlobalToLocalEndDefaultShell()
59281634712SRichard Tran Mills @*/
593a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetGlobalToLocalVecScatter(DM dm, VecScatter gtol)
59481634712SRichard Tran Mills {
59581634712SRichard Tran Mills   DM_Shell       *shell = (DM_Shell*)dm->data;
596d885d199SRichard Tran Mills   PetscErrorCode ierr;
59781634712SRichard Tran Mills 
598b300e4a8SRichard Tran Mills   PetscFunctionBegin;
599d885d199SRichard Tran Mills   ierr = PetscObjectReference((PetscObject)gtol);CHKERRQ(ierr);
600d885d199SRichard Tran Mills   /* Call VecScatterDestroy() to avoid a memory leak in case of re-setting. */
601d885d199SRichard Tran Mills   ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr);
60281634712SRichard Tran Mills   shell->gtol = gtol;
60381634712SRichard Tran Mills   PetscFunctionReturn(0);
60481634712SRichard Tran Mills }
60581634712SRichard Tran Mills 
606988ea7d6SRichard Tran Mills /*@
607988ea7d6SRichard Tran Mills    DMShellSetLocalToGlobalVecScatter - Sets a VecScatter context for local to global communication
608988ea7d6SRichard Tran Mills 
609988ea7d6SRichard Tran Mills    Logically Collective on DM
610988ea7d6SRichard Tran Mills 
611988ea7d6SRichard Tran Mills    Input Arguments
612988ea7d6SRichard Tran Mills +  dm - the shell DM
613988ea7d6SRichard Tran Mills -  ltog - the local to global VecScatter context
614988ea7d6SRichard Tran Mills 
615988ea7d6SRichard Tran Mills    Level: advanced
616988ea7d6SRichard Tran Mills 
617f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToGlobal(), DMLocalToGlobalBeginDefaultShell(), DMLocalToGlobalEndDefaultShell()
618988ea7d6SRichard Tran Mills @*/
619a94b16f6SRichard Tran Mills PetscErrorCode DMShellSetLocalToGlobalVecScatter(DM dm, VecScatter ltog)
620988ea7d6SRichard Tran Mills {
621988ea7d6SRichard Tran Mills   DM_Shell       *shell = (DM_Shell*)dm->data;
622d885d199SRichard Tran Mills   PetscErrorCode ierr;
623988ea7d6SRichard Tran Mills 
624988ea7d6SRichard Tran Mills   PetscFunctionBegin;
625d885d199SRichard Tran Mills   ierr = PetscObjectReference((PetscObject)ltog);CHKERRQ(ierr);
626d885d199SRichard Tran Mills   /* Call VecScatterDestroy() to avoid a memory leak in case of re-setting. */
627d885d199SRichard Tran Mills   ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr);
628988ea7d6SRichard Tran Mills   shell->ltog = ltog;
629988ea7d6SRichard Tran Mills   PetscFunctionReturn(0);
630988ea7d6SRichard Tran Mills }
631988ea7d6SRichard Tran Mills 
632f3db62a7SRichard Tran Mills /*@
633f3db62a7SRichard Tran Mills    DMShellSetLocalToLocalVecScatter - Sets a VecScatter context for local to local communication
634f3db62a7SRichard Tran Mills 
635f3db62a7SRichard Tran Mills    Logically Collective on DM
636f3db62a7SRichard Tran Mills 
637f3db62a7SRichard Tran Mills    Input Arguments
638f3db62a7SRichard Tran Mills +  dm - the shell DM
639f3db62a7SRichard Tran Mills -  ltol - the local to local VecScatter context
640f3db62a7SRichard Tran Mills 
641f3db62a7SRichard Tran Mills    Level: advanced
642f3db62a7SRichard Tran Mills 
643f3db62a7SRichard Tran Mills .seealso: DMShellSetLocalToLocal(), DMLocalToLocalBeginDefaultShell(), DMLocalToLocalEndDefaultShell()
644f3db62a7SRichard Tran Mills @*/
645f3db62a7SRichard Tran Mills PetscErrorCode DMShellSetLocalToLocalVecScatter(DM dm, VecScatter ltol)
646f3db62a7SRichard Tran Mills {
647f3db62a7SRichard Tran Mills   DM_Shell       *shell = (DM_Shell*)dm->data;
648f3db62a7SRichard Tran Mills   PetscErrorCode ierr;
649f3db62a7SRichard Tran Mills 
650f3db62a7SRichard Tran Mills   PetscFunctionBegin;
651f3db62a7SRichard Tran Mills   ierr = PetscObjectReference((PetscObject)ltol);CHKERRQ(ierr);
652f3db62a7SRichard Tran Mills   /* Call VecScatterDestroy() to avoid a memory leak in case of re-setting. */
653f3db62a7SRichard Tran Mills   ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr);
654f3db62a7SRichard Tran Mills   shell->ltol = ltol;
655f3db62a7SRichard Tran Mills   PetscFunctionReturn(0);
656f3db62a7SRichard Tran Mills }
657f3db62a7SRichard Tran Mills 
6589bf9660cSLawrence Mitchell /*@C
6599bf9660cSLawrence Mitchell    DMShellSetCoarsen - Set the routine used to coarsen the shell DM
6609bf9660cSLawrence Mitchell 
6619bf9660cSLawrence Mitchell    Logically Collective on DM
6629bf9660cSLawrence Mitchell 
6639bf9660cSLawrence Mitchell    Input Arguments
6649bf9660cSLawrence Mitchell +  dm - the shell DM
6659bf9660cSLawrence Mitchell -  coarsen - the routine that coarsens the DM
6669bf9660cSLawrence Mitchell 
6679bf9660cSLawrence Mitchell    Level: advanced
6689bf9660cSLawrence Mitchell 
669fef3a512SBarry Smith .seealso: DMShellSetRefine(), DMCoarsen(), DMShellSetContext(), DMShellGetContext()
6709bf9660cSLawrence Mitchell @*/
671f572501eSLawrence Mitchell PetscErrorCode DMShellSetCoarsen(DM dm, PetscErrorCode (*coarsen)(DM,MPI_Comm,DM*))
672f572501eSLawrence Mitchell {
673f572501eSLawrence Mitchell   PetscErrorCode ierr;
674f572501eSLawrence Mitchell   PetscBool      isshell;
675f572501eSLawrence Mitchell 
676f572501eSLawrence Mitchell   PetscFunctionBegin;
677f572501eSLawrence Mitchell   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
678f572501eSLawrence Mitchell   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
679f572501eSLawrence Mitchell   if (!isshell) PetscFunctionReturn(0);
680f572501eSLawrence Mitchell   dm->ops->coarsen = coarsen;
681f572501eSLawrence Mitchell   PetscFunctionReturn(0);
682f572501eSLawrence Mitchell }
683f572501eSLawrence Mitchell 
6849bf9660cSLawrence Mitchell /*@C
6859bf9660cSLawrence Mitchell    DMShellSetRefine - Set the routine used to refine the shell DM
6869bf9660cSLawrence Mitchell 
6879bf9660cSLawrence Mitchell    Logically Collective on DM
6889bf9660cSLawrence Mitchell 
6899bf9660cSLawrence Mitchell    Input Arguments
6909bf9660cSLawrence Mitchell +  dm - the shell DM
6919bf9660cSLawrence Mitchell -  refine - the routine that refines the DM
6929bf9660cSLawrence Mitchell 
6939bf9660cSLawrence Mitchell    Level: advanced
6949bf9660cSLawrence Mitchell 
695fef3a512SBarry Smith .seealso: DMShellSetCoarsen(), DMRefine(), DMShellSetContext(), DMShellGetContext()
6969bf9660cSLawrence Mitchell @*/
697f572501eSLawrence Mitchell PetscErrorCode DMShellSetRefine(DM dm, PetscErrorCode (*refine)(DM,MPI_Comm,DM*))
698f572501eSLawrence Mitchell {
699f572501eSLawrence Mitchell   PetscErrorCode ierr;
700f572501eSLawrence Mitchell   PetscBool      isshell;
701f572501eSLawrence Mitchell 
702f572501eSLawrence Mitchell   PetscFunctionBegin;
703f572501eSLawrence Mitchell   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
704f572501eSLawrence Mitchell   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
705f572501eSLawrence Mitchell   if (!isshell) PetscFunctionReturn(0);
706f572501eSLawrence Mitchell   dm->ops->refine = refine;
707f572501eSLawrence Mitchell   PetscFunctionReturn(0);
708f572501eSLawrence Mitchell }
709f572501eSLawrence Mitchell 
7109bf9660cSLawrence Mitchell /*@C
7119bf9660cSLawrence Mitchell    DMShellSetCreateInterpolation - Set the routine used to create the interpolation operator
7129bf9660cSLawrence Mitchell 
7139bf9660cSLawrence Mitchell    Logically Collective on DM
7149bf9660cSLawrence Mitchell 
7159bf9660cSLawrence Mitchell    Input Arguments
7169bf9660cSLawrence Mitchell +  dm - the shell DM
7179bf9660cSLawrence Mitchell -  interp - the routine to create the interpolation
7189bf9660cSLawrence Mitchell 
7199bf9660cSLawrence Mitchell    Level: advanced
7209bf9660cSLawrence Mitchell 
721fef3a512SBarry Smith .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellSetCreateRestriction(), DMShellSetContext(), DMShellGetContext()
7229bf9660cSLawrence Mitchell @*/
723f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInterpolation(DM dm, PetscErrorCode (*interp)(DM,DM,Mat*,Vec*))
724f572501eSLawrence Mitchell {
725f572501eSLawrence Mitchell   PetscErrorCode ierr;
726f572501eSLawrence Mitchell   PetscBool      isshell;
727f572501eSLawrence Mitchell 
728f572501eSLawrence Mitchell   PetscFunctionBegin;
729f572501eSLawrence Mitchell   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
730f572501eSLawrence Mitchell   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
731f572501eSLawrence Mitchell   if (!isshell) PetscFunctionReturn(0);
732f572501eSLawrence Mitchell   dm->ops->createinterpolation = interp;
733f572501eSLawrence Mitchell   PetscFunctionReturn(0);
734f572501eSLawrence Mitchell }
735f572501eSLawrence Mitchell 
7363ad4599aSBarry Smith /*@C
7373ad4599aSBarry Smith    DMShellSetCreateRestriction - Set the routine used to create the restriction operator
7383ad4599aSBarry Smith 
7393ad4599aSBarry Smith    Logically Collective on DM
7403ad4599aSBarry Smith 
7413ad4599aSBarry Smith    Input Arguments
7423ad4599aSBarry Smith +  dm - the shell DM
7433ad4599aSBarry Smith -  striction- the routine to create the restriction
7443ad4599aSBarry Smith 
7453ad4599aSBarry Smith    Level: advanced
7463ad4599aSBarry Smith 
747fef3a512SBarry Smith .seealso: DMShellSetCreateInjection(), DMCreateInterpolation(), DMShellSetContext(), DMShellGetContext()
7483ad4599aSBarry Smith @*/
7493ad4599aSBarry Smith PetscErrorCode DMShellSetCreateRestriction(DM dm, PetscErrorCode (*restriction)(DM,DM,Mat*))
7503ad4599aSBarry Smith {
7513ad4599aSBarry Smith   PetscErrorCode ierr;
7523ad4599aSBarry Smith   PetscBool      isshell;
7533ad4599aSBarry Smith 
7543ad4599aSBarry Smith   PetscFunctionBegin;
7553ad4599aSBarry Smith   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
7563ad4599aSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
7573ad4599aSBarry Smith   if (!isshell) PetscFunctionReturn(0);
7583ad4599aSBarry Smith   dm->ops->createrestriction = restriction;
7593ad4599aSBarry Smith   PetscFunctionReturn(0);
7603ad4599aSBarry Smith }
7613ad4599aSBarry Smith 
7629bf9660cSLawrence Mitchell /*@C
7639bf9660cSLawrence Mitchell    DMShellSetCreateInjection - Set the routine used to create the injection operator
7649bf9660cSLawrence Mitchell 
7659bf9660cSLawrence Mitchell    Logically Collective on DM
7669bf9660cSLawrence Mitchell 
7679bf9660cSLawrence Mitchell    Input Arguments
7689bf9660cSLawrence Mitchell +  dm - the shell DM
7699bf9660cSLawrence Mitchell -  inject - the routine to create the injection
7709bf9660cSLawrence Mitchell 
7719bf9660cSLawrence Mitchell    Level: advanced
7729bf9660cSLawrence Mitchell 
773fef3a512SBarry Smith .seealso: DMShellSetCreateInterpolation(), DMCreateInjection(), DMShellSetContext(), DMShellGetContext()
7749bf9660cSLawrence Mitchell @*/
775f572501eSLawrence Mitchell PetscErrorCode DMShellSetCreateInjection(DM dm, PetscErrorCode (*inject)(DM,DM,Mat*))
776f572501eSLawrence Mitchell {
777f572501eSLawrence Mitchell   PetscErrorCode ierr;
778f572501eSLawrence Mitchell   PetscBool      isshell;
779f572501eSLawrence Mitchell 
780f572501eSLawrence Mitchell   PetscFunctionBegin;
781f572501eSLawrence Mitchell   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
782f572501eSLawrence Mitchell   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
783f572501eSLawrence Mitchell   if (!isshell) PetscFunctionReturn(0);
784f572501eSLawrence Mitchell   dm->ops->getinjection = inject;
785f572501eSLawrence Mitchell   PetscFunctionReturn(0);
786f572501eSLawrence Mitchell }
787f572501eSLawrence Mitchell 
788bf483bb6SLawrence Mitchell static PetscErrorCode DMHasCreateInjection_Shell(DM dm, PetscBool *flg)
789bf483bb6SLawrence Mitchell {
790bf483bb6SLawrence Mitchell   PetscErrorCode ierr;
791bf483bb6SLawrence Mitchell   PetscBool      isshell;
792bf483bb6SLawrence Mitchell 
793bf483bb6SLawrence Mitchell   PetscFunctionBegin;
794bf483bb6SLawrence Mitchell   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
795bf483bb6SLawrence Mitchell   PetscValidPointer(flg,2);
796bf483bb6SLawrence Mitchell   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
797bf483bb6SLawrence Mitchell   if (!isshell) {
798bf483bb6SLawrence Mitchell     *flg = PETSC_FALSE;
799bf483bb6SLawrence Mitchell   } else {
800bf483bb6SLawrence Mitchell     *flg = dm->ops->getinjection ? PETSC_TRUE : PETSC_FALSE;
801bf483bb6SLawrence Mitchell   }
802bf483bb6SLawrence Mitchell   PetscFunctionReturn(0);
803bf483bb6SLawrence Mitchell }
8049bf9660cSLawrence Mitchell /*@C
8059bf9660cSLawrence Mitchell    DMShellSetCreateFieldDecomposition - Set the routine used to create a decomposition of fields for the shell DM
8069bf9660cSLawrence Mitchell 
8079bf9660cSLawrence Mitchell    Logically Collective on DM
8089bf9660cSLawrence Mitchell 
8099bf9660cSLawrence Mitchell    Input Arguments
8109bf9660cSLawrence Mitchell +  dm - the shell DM
8119bf9660cSLawrence Mitchell -  decomp - the routine to create the decomposition
8129bf9660cSLawrence Mitchell 
8139bf9660cSLawrence Mitchell    Level: advanced
8149bf9660cSLawrence Mitchell 
815fef3a512SBarry Smith .seealso: DMCreateFieldDecomposition(), DMShellSetContext(), DMShellGetContext()
8169bf9660cSLawrence Mitchell @*/
8175e2259d5SLawrence Mitchell PetscErrorCode DMShellSetCreateFieldDecomposition(DM dm, PetscErrorCode (*decomp)(DM,PetscInt*,char***, IS**,DM**))
8185e2259d5SLawrence Mitchell {
8195e2259d5SLawrence Mitchell   PetscErrorCode ierr;
8205e2259d5SLawrence Mitchell   PetscBool      isshell;
8215e2259d5SLawrence Mitchell 
8225e2259d5SLawrence Mitchell   PetscFunctionBegin;
8235e2259d5SLawrence Mitchell   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
8245e2259d5SLawrence Mitchell   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
8255e2259d5SLawrence Mitchell   if (!isshell) PetscFunctionReturn(0);
8265e2259d5SLawrence Mitchell   dm->ops->createfielddecomposition = decomp;
8275e2259d5SLawrence Mitchell   PetscFunctionReturn(0);
8285e2259d5SLawrence Mitchell }
8295e2259d5SLawrence Mitchell 
830c00061e5SLawrence Mitchell /*@C
831e734121bSPatrick Farrell    DMShellSetCreateDomainDecomposition - Set the routine used to create a domain decomposition for the shell DM
832e734121bSPatrick Farrell 
833e734121bSPatrick Farrell    Logically Collective on DM
834e734121bSPatrick Farrell 
835e734121bSPatrick Farrell    Input Arguments
836e734121bSPatrick Farrell +  dm - the shell DM
837e734121bSPatrick Farrell -  decomp - the routine to create the decomposition
838e734121bSPatrick Farrell 
839e734121bSPatrick Farrell    Level: advanced
840e734121bSPatrick Farrell 
841e734121bSPatrick Farrell .seealso: DMCreateDomainDecomposition(), DMShellSetContext(), DMShellGetContext()
842e734121bSPatrick Farrell @*/
843e734121bSPatrick Farrell PetscErrorCode DMShellSetCreateDomainDecomposition(DM dm, PetscErrorCode (*decomp)(DM,PetscInt*,char***, IS**,IS**,DM**))
844e734121bSPatrick Farrell {
845e734121bSPatrick Farrell   PetscErrorCode ierr;
846e734121bSPatrick Farrell   PetscBool      isshell;
847e734121bSPatrick Farrell 
848e734121bSPatrick Farrell   PetscFunctionBegin;
849e734121bSPatrick Farrell   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
850e734121bSPatrick Farrell   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
851e734121bSPatrick Farrell   if (!isshell) PetscFunctionReturn(0);
852e734121bSPatrick Farrell   dm->ops->createdomaindecomposition = decomp;
853e734121bSPatrick Farrell   PetscFunctionReturn(0);
854e734121bSPatrick Farrell }
855e734121bSPatrick Farrell 
856e734121bSPatrick Farrell /*@C
857eef9d6cdSPatrick Farrell    DMShellSetCreateDomainDecompositionScatters - Set the routine used to create the scatter contexts for domain decomposition with a shell DM
858eef9d6cdSPatrick Farrell 
859eef9d6cdSPatrick Farrell    Logically Collective on DM
860eef9d6cdSPatrick Farrell 
861eef9d6cdSPatrick Farrell    Input Arguments
862eef9d6cdSPatrick Farrell +  dm - the shell DM
863eef9d6cdSPatrick Farrell -  scatter - the routine to create the scatters
864eef9d6cdSPatrick Farrell 
865eef9d6cdSPatrick Farrell    Level: advanced
866eef9d6cdSPatrick Farrell 
867448b6425SPatrick Farrell .seealso: DMCreateDomainDecompositionScatters(), DMShellSetContext(), DMShellGetContext()
868eef9d6cdSPatrick Farrell @*/
869eef9d6cdSPatrick Farrell PetscErrorCode DMShellSetCreateDomainDecompositionScatters(DM dm, PetscErrorCode (*scatter)(DM,PetscInt,DM*,VecScatter**,VecScatter**,VecScatter**))
870eef9d6cdSPatrick Farrell {
871eef9d6cdSPatrick Farrell   PetscErrorCode ierr;
872eef9d6cdSPatrick Farrell   PetscBool      isshell;
873eef9d6cdSPatrick Farrell 
874eef9d6cdSPatrick Farrell   PetscFunctionBegin;
875eef9d6cdSPatrick Farrell   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
876eef9d6cdSPatrick Farrell   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
877eef9d6cdSPatrick Farrell   if (!isshell) PetscFunctionReturn(0);
878eef9d6cdSPatrick Farrell   dm->ops->createddscatters = scatter;
879eef9d6cdSPatrick Farrell   PetscFunctionReturn(0);
880eef9d6cdSPatrick Farrell }
881eef9d6cdSPatrick Farrell 
882eef9d6cdSPatrick Farrell /*@C
883c00061e5SLawrence Mitchell    DMShellSetCreateSubDM - Set the routine used to create a sub DM from the shell DM
884c00061e5SLawrence Mitchell 
885c00061e5SLawrence Mitchell    Logically Collective on DM
886c00061e5SLawrence Mitchell 
887c00061e5SLawrence Mitchell    Input Arguments
888c00061e5SLawrence Mitchell +  dm - the shell DM
889c00061e5SLawrence Mitchell -  subdm - the routine to create the decomposition
890c00061e5SLawrence Mitchell 
891c00061e5SLawrence Mitchell    Level: advanced
892c00061e5SLawrence Mitchell 
893fef3a512SBarry Smith .seealso: DMCreateSubDM(), DMShellSetContext(), DMShellGetContext()
894c00061e5SLawrence Mitchell @*/
895276c5506SMatthew G. Knepley PetscErrorCode DMShellSetCreateSubDM(DM dm, PetscErrorCode (*subdm)(DM,PetscInt,const PetscInt[],IS*,DM*))
896c00061e5SLawrence Mitchell {
897c00061e5SLawrence Mitchell   PetscErrorCode ierr;
898c00061e5SLawrence Mitchell   PetscBool      isshell;
899c00061e5SLawrence Mitchell 
900c00061e5SLawrence Mitchell   PetscFunctionBegin;
901c00061e5SLawrence Mitchell   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
902c00061e5SLawrence Mitchell   ierr = PetscObjectTypeCompare((PetscObject)dm,DMSHELL,&isshell);CHKERRQ(ierr);
903c00061e5SLawrence Mitchell   if (!isshell) PetscFunctionReturn(0);
904c00061e5SLawrence Mitchell   dm->ops->createsubdm = subdm;
905c00061e5SLawrence Mitchell   PetscFunctionReturn(0);
906c00061e5SLawrence Mitchell }
907c00061e5SLawrence Mitchell 
908fe1899a2SJed Brown static PetscErrorCode DMDestroy_Shell(DM dm)
909fe1899a2SJed Brown {
910fe1899a2SJed Brown   PetscErrorCode ierr;
911fe1899a2SJed Brown   DM_Shell       *shell = (DM_Shell*)dm->data;
912fe1899a2SJed Brown 
913fe1899a2SJed Brown   PetscFunctionBegin;
914fe1899a2SJed Brown   ierr = MatDestroy(&shell->A);CHKERRQ(ierr);
915fe1899a2SJed Brown   ierr = VecDestroy(&shell->Xglobal);CHKERRQ(ierr);
916dc43b69eSJed Brown   ierr = VecDestroy(&shell->Xlocal);CHKERRQ(ierr);
917a94b16f6SRichard Tran Mills   ierr = VecScatterDestroy(&shell->gtol);CHKERRQ(ierr);
918a94b16f6SRichard Tran Mills   ierr = VecScatterDestroy(&shell->ltog);CHKERRQ(ierr);
919294a6417SLawrence Mitchell   ierr = VecScatterDestroy(&shell->ltol);CHKERRQ(ierr);
9207b6ad80cSMatthew G Knepley   /* This was originally freed in DMDestroy(), but that prevents reference counting of backend objects */
9217b6ad80cSMatthew G Knepley   ierr = PetscFree(shell);CHKERRQ(ierr);
922fe1899a2SJed Brown   PetscFunctionReturn(0);
923fe1899a2SJed Brown }
924fe1899a2SJed Brown 
9252d53ad75SBarry Smith static PetscErrorCode DMView_Shell(DM dm,PetscViewer v)
9262d53ad75SBarry Smith {
9272d53ad75SBarry Smith   PetscErrorCode ierr;
9282d53ad75SBarry Smith   DM_Shell       *shell = (DM_Shell*)dm->data;
9292d53ad75SBarry Smith 
9302d53ad75SBarry Smith   PetscFunctionBegin;
9312d53ad75SBarry Smith   ierr = VecView(shell->Xglobal,v);CHKERRQ(ierr);
9322d53ad75SBarry Smith   PetscFunctionReturn(0);
9332d53ad75SBarry Smith }
9342d53ad75SBarry Smith 
9352d53ad75SBarry Smith static PetscErrorCode DMLoad_Shell(DM dm,PetscViewer v)
9362d53ad75SBarry Smith {
9372d53ad75SBarry Smith   PetscErrorCode ierr;
9382d53ad75SBarry Smith   DM_Shell       *shell = (DM_Shell*)dm->data;
9392d53ad75SBarry Smith 
9402d53ad75SBarry Smith   PetscFunctionBegin;
941ce94432eSBarry Smith   ierr = VecCreate(PetscObjectComm((PetscObject)dm),&shell->Xglobal);CHKERRQ(ierr);
9422d53ad75SBarry Smith   ierr = VecLoad(shell->Xglobal,v);CHKERRQ(ierr);
9432d53ad75SBarry Smith   PetscFunctionReturn(0);
9442d53ad75SBarry Smith }
945fe1899a2SJed Brown 
946276c5506SMatthew G. Knepley PetscErrorCode DMCreateSubDM_Shell(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm)
9476e44b4cfSMatthew G. Knepley {
9486e44b4cfSMatthew G. Knepley   PetscErrorCode ierr;
9496e44b4cfSMatthew G. Knepley 
9506e44b4cfSMatthew G. Knepley   PetscFunctionBegin;
9516e44b4cfSMatthew G. Knepley   if (subdm) {ierr = DMShellCreate(PetscObjectComm((PetscObject) dm), subdm);CHKERRQ(ierr);}
9526e44b4cfSMatthew G. Knepley   ierr = DMCreateSubDM_Section_Private(dm, numFields, fields, is, subdm);CHKERRQ(ierr);
9536e44b4cfSMatthew G. Knepley   PetscFunctionReturn(0);
9546e44b4cfSMatthew G. Knepley }
9556e44b4cfSMatthew G. Knepley 
9568cc058d9SJed Brown PETSC_EXTERN PetscErrorCode DMCreate_Shell(DM dm)
957fe1899a2SJed Brown {
958fe1899a2SJed Brown   PetscErrorCode ierr;
959fe1899a2SJed Brown   DM_Shell       *shell;
960fe1899a2SJed Brown 
961fe1899a2SJed Brown   PetscFunctionBegin;
962b00a9115SJed Brown   ierr     = PetscNewLog(dm,&shell);CHKERRQ(ierr);
9638c87107bSJed Brown   dm->data = shell;
964fe1899a2SJed Brown 
9658c87107bSJed Brown   ierr = PetscObjectChangeTypeName((PetscObject)dm,DMSHELL);CHKERRQ(ierr);
9668865f1eaSKarl Rupp 
9678c87107bSJed Brown   dm->ops->destroy            = DMDestroy_Shell;
9688c87107bSJed Brown   dm->ops->createglobalvector = DMCreateGlobalVector_Shell;
969dc43b69eSJed Brown   dm->ops->createlocalvector  = DMCreateLocalVector_Shell;
9708c87107bSJed Brown   dm->ops->creatematrix       = DMCreateMatrix_Shell;
9712d53ad75SBarry Smith   dm->ops->view               = DMView_Shell;
9722d53ad75SBarry Smith   dm->ops->load               = DMLoad_Shell;
9737a108d1dSBarry Smith   dm->ops->globaltolocalbegin = DMGlobalToLocalBeginDefaultShell;
9747a108d1dSBarry Smith   dm->ops->globaltolocalend   = DMGlobalToLocalEndDefaultShell;
97555daaa54SRichard Tran Mills   dm->ops->localtoglobalbegin = DMLocalToGlobalBeginDefaultShell;
97655daaa54SRichard Tran Mills   dm->ops->localtoglobalend   = DMLocalToGlobalEndDefaultShell;
97763731094SRichard Tran Mills   dm->ops->localtolocalbegin  = DMLocalToLocalBeginDefaultShell;
97863731094SRichard Tran Mills   dm->ops->localtolocalend    = DMLocalToLocalEndDefaultShell;
9796e44b4cfSMatthew G. Knepley   dm->ops->createsubdm        = DMCreateSubDM_Shell;
980bf483bb6SLawrence Mitchell   dm->ops->hascreateinjection = DMHasCreateInjection_Shell;
981fe1899a2SJed Brown   PetscFunctionReturn(0);
982fe1899a2SJed Brown }
983fe1899a2SJed Brown 
984fe1899a2SJed Brown /*@
985fe1899a2SJed Brown     DMShellCreate - Creates a shell DM object, used to manage user-defined problem data
986fe1899a2SJed Brown 
987fe1899a2SJed Brown     Collective on MPI_Comm
988fe1899a2SJed Brown 
989fe1899a2SJed Brown     Input Parameter:
990fe1899a2SJed Brown .   comm - the processors that will share the global vector
991fe1899a2SJed Brown 
992fe1899a2SJed Brown     Output Parameters:
993fe1899a2SJed Brown .   shell - the shell DM
994fe1899a2SJed Brown 
995fe1899a2SJed Brown     Level: advanced
996fe1899a2SJed Brown 
997fef3a512SBarry Smith .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateLocalVector(), DMShellSetContext(), DMShellGetContext()
998fe1899a2SJed Brown @*/
999fe1899a2SJed Brown PetscErrorCode  DMShellCreate(MPI_Comm comm,DM *dm)
1000fe1899a2SJed Brown {
1001fe1899a2SJed Brown   PetscErrorCode ierr;
1002fe1899a2SJed Brown 
1003fe1899a2SJed Brown   PetscFunctionBegin;
1004fe1899a2SJed Brown   PetscValidPointer(dm,2);
1005fe1899a2SJed Brown   ierr = DMCreate(comm,dm);CHKERRQ(ierr);
1006fe1899a2SJed Brown   ierr = DMSetType(*dm,DMSHELL);CHKERRQ(ierr);
100781a566bfSMatthew G. Knepley   ierr = DMSetUp(*dm);CHKERRQ(ierr);
1008fe1899a2SJed Brown   PetscFunctionReturn(0);
1009fe1899a2SJed Brown }
101081634712SRichard Tran Mills 
1011