~ubuntu-branches/ubuntu/warty/petsc/warty

« back to all changes in this revision

Viewing changes to src/gsolver/interface/gsles.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2004-06-07 13:41:43 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040607134143-92p586zrauvie0le
Tags: 2.2.0-2
* Upstream patch level 2.
* New PETSC_BOPT_EXTRA option for different BOPT and lib names, with _c++
  symlinks only for plain and single (closes: #249617).
* New DEBIAN_DIST=contrib option to link with hypre, parmetis (closes:
  #249619).
* Combined petsc-c and petsc-fortran substvars into petsc-compilers.
* Extra quote in -dev prerm eliminates "too many arguments" problem.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef PETSC_RCS_HEADER
2
 
static char vcid[] = "$Id: gsles.c,v 1.5 2000/01/10 03:54:18 knepley Exp $";
3
 
#endif
4
 
 
5
 
#include "petscsles.h"            /*I "petscsles.h" I*/
6
 
#include "gsolver.h"              /*I "gsolver.h" I*/
7
 
 
8
 
#undef  __FUNCT__
9
 
#define __FUNCT__ "GVecSolutionKSPMonitor"
10
 
/*@
11
 
  GVecSolutionKSPMonitor - Monitors solution at each KSP iteration.
12
 
 
13
 
  Collective on KSP
14
 
 
15
 
  Input Parameters:
16
 
. ksp   - The Krylov subspace context
17
 
. it    - The number of iterations so far
18
 
. rnorm - The current (approximate) residual norm
19
 
. ctx   - A viewer
20
 
 
21
 
  Level: advanced
22
 
 
23
 
.keywords: grid vector, ksp, monitor, solution
24
 
.seealso: KSPDefaultMonitor(),KSPSetMonitor(),GVecResidualKSPMonitor(),
25
 
          GVecRhsKSPMonitor(), GVecErrorKSPMonitor()
26
 
@*/
27
 
int GVecSolutionKSPMonitor(KSP ksp, int it, PetscReal rnorm, void *ctx)
28
 
{
29
 
  PetscViewer viewer = (PetscViewer) ctx;
30
 
  Vec         x;
31
 
  int         ierr;
32
 
 
33
 
  PetscFunctionBegin;
34
 
  PetscValidHeaderSpecific(ksp,    KSP_COOKIE);
35
 
  PetscValidHeaderSpecific(viewer, PETSC_VIEWER_COOKIE);
36
 
  ierr = KSPBuildSolution(ksp, PETSC_NULL, &x);                                                           CHKERRQ(ierr);
37
 
  ierr = VecView(x, viewer);                                                                              CHKERRQ(ierr);
38
 
  PetscFunctionReturn(0);
39
 
}
40
 
 
41
 
#undef  __FUNCT__
42
 
#define __FUNCT__ "GVecResidualKSPMonitor"
43
 
/*@
44
 
  GVecResidualKSPMonitor - Monitors residual at each KSP iteration.
45
 
 
46
 
  Collective on KSP
47
 
 
48
 
  Input Parameters:
49
 
. ksp   - The Krylov subspace context
50
 
. it    - The number of iterations so far
51
 
. rnorm - The current (approximate) residual norm
52
 
. ctx   - A viewer
53
 
 
54
 
  Level: advanced
55
 
 
56
 
.keywords: grid vector, ksp, monitor, residual
57
 
.seealso: KSPDefaultMonitor(),KSPSetMonitor(),GVecSolutionKSPMonitor(),
58
 
          GVecRhsKSPMonitor(), GVecErrorKSPMonitor()
59
 
@*/
60
 
int GVecResidualKSPMonitor(KSP ksp, int it, PetscReal rnorm, void *ctx)
61
 
{
62
 
  PetscViewer viewer = (PetscViewer) ctx;
63
 
  Vec         r;
64
 
  int         ierr;
65
 
 
66
 
  PetscFunctionBegin;
67
 
  PetscValidHeaderSpecific(ksp,    KSP_COOKIE);
68
 
  PetscValidHeaderSpecific(viewer, PETSC_VIEWER_COOKIE);
69
 
  ierr = KSPBuildResidual(ksp, PETSC_NULL, PETSC_NULL, &r);                                               CHKERRQ(ierr);
70
 
  ierr = VecView(r, viewer);                                                                              CHKERRQ(ierr);
71
 
  PetscFunctionReturn(0);
72
 
}
73
 
 
74
 
#undef  __FUNCT__
75
 
#define __FUNCT__ "GVecRhsKSPMonitor"
76
 
/*@
77
 
  GVecRhsKSPMonitor - Displays the right hand side for the linear system at the first iteration.
78
 
 
79
 
  Collective on KSP
80
 
 
81
 
  Input Parameters:
82
 
. ksp   - The Krylov subspace context
83
 
. it    - The number of iterations so far
84
 
. rnorm - The current (approximate) residual norm
85
 
. ctx   - A viewer
86
 
 
87
 
  Level: advanced
88
 
 
89
 
.keywords: grid vector, ksp, monitor, rhs
90
 
.seealso: KSPDefaultMonitor(),KSPSetMonitor(),GVecSolutionKSPMonitor(),
91
 
          GVecResidualKSPMonitor(), GVecErrorKSPMonitor()
92
 
@*/
93
 
int GVecRhsKSPMonitor(KSP ksp, int it, PetscReal rnorm, void *ctx)
94
 
{
95
 
  PetscViewer viewer = (PetscViewer) ctx;
96
 
  Vec         b;
97
 
  int         ierr;
98
 
 
99
 
  PetscFunctionBegin;
100
 
  PetscValidHeaderSpecific(ksp,    KSP_COOKIE);
101
 
  PetscValidHeaderSpecific(viewer, PETSC_VIEWER_COOKIE);
102
 
  if (!it) {
103
 
    ierr = KSPGetRhs(ksp, &b);                                                                            CHKERRQ(ierr);
104
 
    ierr = VecView(b, viewer);                                                                            CHKERRQ(ierr);
105
 
  }
106
 
  PetscFunctionReturn(0);
107
 
}
108
 
 
109
 
#undef  __FUNCT__
110
 
#define __FUNCT__ "GVecErrorKSPMonitor"
111
 
/*@
112
 
  GVecErrorKSPMonitor - Displays the error at each iteration.
113
 
 
114
 
  Collective on KSP
115
 
 
116
 
  Input Parameters:
117
 
. ksp      - The Krylov subspace context
118
 
. it       - The number of iterations so far
119
 
. rnorm    - The current (approximate) residual norm
120
 
. errorCtx - A GVecErrorKSPMonitorCtx
121
 
 
122
 
  Notes: 
123
 
  The final argument to KSPSetMonitor() with this routine must be
124
 
  a pointer to a GVecErrorKSPMonitorCtx.
125
 
 
126
 
  Level: advanced
127
 
 
128
 
.keywords: grid vector, ksp, monitor, error
129
 
.seealso: KSPDefaultMonitor(),KSPSetMonitor(),,GVecSolutionKSPMonitor(),
130
 
          GVecResidualKSPMonitor(), GVecRhsKSPMonitor()
131
 
@*/
132
 
int GVecErrorKSPMonitor(KSP ksp, int it, PetscReal rnorm, void *errorCtx)
133
 
{
134
 
  GVecErrorKSPMonitorCtx *ctx  = (GVecErrorKSPMonitorCtx *) errorCtx;
135
 
  PetscScalar             mone = -1.0;
136
 
  GVec                    x, e;
137
 
  PetscReal               norm_2, norm_max;
138
 
  int                     ierr;
139
 
 
140
 
  PetscFunctionBegin;
141
 
  PetscValidHeaderSpecific(ksp, KSP_COOKIE);
142
 
  ierr = KSPBuildSolution(ksp, PETSC_NULL, &x);                                                           CHKERRQ(ierr);
143
 
  ierr = GVecGetWorkGVec(ctx->solution, &e);                                                              CHKERRQ(ierr);
144
 
  ierr = VecWAXPY(&mone, x, ctx->solution, e);                                                            CHKERRQ(ierr);
145
 
  ierr = VecView(e, ctx->error_viewer);                                                                   CHKERRQ(ierr);
146
 
 
147
 
  /* Compute 2-norm and max-norm of error */
148
 
  if (ctx->norm_error_viewer) {
149
 
    ierr = VecNorm(e, NORM_2, &norm_2);                                                                   CHKERRQ(ierr);
150
 
    ierr = VecNorm(e, NORM_MAX, &norm_max);                                                               CHKERRQ(ierr);
151
 
    if (ctx->isInner == PETSC_FALSE) {
152
 
      PetscViewerASCIIPrintf(ctx->norm_error_viewer, "Iteration %d residual norm %g error 2-norm %g error max-norm %g\n",
153
 
                             it, rnorm, norm_2, norm_max);
154
 
    } else {
155
 
      PetscViewerASCIIPrintf(ctx->norm_error_viewer, "  Inner iteration %d residual norm %g error 2-norm %g error max-norm %g\n",
156
 
                             it, rnorm, norm_2, norm_max);
157
 
    }
158
 
  }
159
 
 
160
 
  ierr = GVecRestoreWorkGVec(ctx->solution, &e);                                                          CHKERRQ(ierr);
161
 
  PetscFunctionReturn(0);
162
 
}
163
 
 
164
 
#include "petscmg.h"
165
 
#undef  __FUNCT__
166
 
#define __FUNCT__ "GVecPCMGSetMonitor"
167
 
/* ------------------------------------------------------------------------------*/
168
 
/*
169
 
  GVecPCMGSetMonitor - Sets GVec KSP monitors for each level of multigrid.
170
 
 
171
 
   Input Parameters:
172
 
.    pc - preconditioner context for multigrid
173
 
*/
174
 
int GVecPCMGSetMonitor(PC pc, int views)
175
 
{
176
 
  char         name[25];
177
 
  int          levels, i,ierr, solution,rhs,residual,all;
178
 
  SLES         subsles;
179
 
  KSP          ksp;
180
 
  PetscViewer *viewers;
181
 
  PetscTruth   match;
182
 
 
183
 
  PetscFunctionBegin;
184
 
  PetscValidHeaderSpecific(pc, PC_COOKIE);
185
 
  ierr = PetscTypeCompare((PetscObject) pc, PCMG, &match);                                                CHKERRQ(ierr);
186
 
  if (match == PETSC_FALSE) PetscFunctionReturn(0);
187
 
 
188
 
  solution = (views & GVECPCMGMONITOR_SOLUTION);
189
 
  residual = (views & GVECPCMGMONITOR_RESIDUAL);
190
 
  rhs      = (views & GVECPCMGMONITOR_RHS);
191
 
  all      = (solution != 0) + (residual != 0) + (rhs != 0);
192
 
 
193
 
  ierr = MGGetLevels(pc, &levels);                                                                        CHKERRQ(ierr);
194
 
 
195
 
  ierr = PetscMalloc(all*levels * sizeof(PetscViewer), &viewers);                                         CHKERRQ(ierr);
196
 
 
197
 
  for(i = 0; i < levels; i++) {
198
 
    ierr = MGGetSmoother(pc, i, &subsles);                                                                CHKERRQ(ierr);
199
 
    ierr = SLESGetKSP(subsles, &ksp);                                                                     CHKERRQ(ierr);
200
 
    if (rhs) {
201
 
      sprintf(name, "Right hand side %d",i);
202
 
      ierr = PetscViewerDrawOpen(PETSC_COMM_WORLD, 0, name, PETSC_DECIDE, PETSC_DECIDE, 200, 200, viewers); CHKERRQ(ierr);
203
 
      ierr = KSPSetMonitor(ksp, GVecRhsKSPMonitor, *viewers++, PETSC_NULL);                               CHKERRQ(ierr);
204
 
    }
205
 
    if (solution) {
206
 
      sprintf(name, "Solution %d",i);
207
 
      ierr = PetscViewerDrawOpen(PETSC_COMM_WORLD, 0, name, PETSC_DECIDE, PETSC_DECIDE, 200, 200, viewers); CHKERRQ(ierr);
208
 
      ierr = KSPSetMonitor(ksp, GVecSolutionKSPMonitor, *viewers++, PETSC_NULL);                          CHKERRQ(ierr);
209
 
    }
210
 
    if (residual) {
211
 
      sprintf(name, "Residual %d",i);
212
 
      ierr = PetscViewerDrawOpen(PETSC_COMM_WORLD, 0, name, PETSC_DECIDE, PETSC_DECIDE, 200, 200, viewers); CHKERRQ(ierr);
213
 
      ierr = KSPSetMonitor(ksp, GVecResidualKSPMonitor, *viewers++, PETSC_NULL);                          CHKERRQ(ierr);
214
 
    }
215
 
  }
216
 
 
217
 
  PetscFunctionReturn(0);
218
 
}
219
 
 
220
 
EXTERN_C_BEGIN
221
 
#undef  __FUNCT__
222
 
#define __FUNCT__ "GVecKSPOptionsChecker_Private"
223
 
int GVecKSPOptionsChecker_Private(KSP ksp)
224
 
{
225
 
  char       *prefix, string[64], *p;
226
 
  int         ierr, loc[4], nmax;
227
 
  MPI_Comm    comm;
228
 
  PetscViewer viewer;
229
 
  PetscDraw   draw;
230
 
  PetscTruth  opt;
231
 
 
232
 
 
233
 
  PetscFunctionBegin;
234
 
  PetscValidHeaderSpecific(ksp, KSP_COOKIE);
235
 
  ierr = KSPGetOptionsPrefix(ksp, &prefix);                                                               CHKERRQ(ierr);
236
 
  ierr = PetscObjectGetComm((PetscObject) ksp, &comm);                                                    CHKERRQ(ierr);
237
 
 
238
 
  nmax = 4;
239
 
  loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300;
240
 
  ierr = PetscOptionsGetIntArray(prefix, "-gvec_ksp_solutionmonitor", loc, &nmax, &opt);                  CHKERRQ(ierr);
241
 
  if (opt) {
242
 
    ierr = PetscViewerDrawOpen(comm, 0, 0, loc[0], loc[1], loc[2], loc[3], &viewer);                      CHKERRQ(ierr);
243
 
    ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);                                                      CHKERRQ(ierr);
244
 
    ierr = PetscDrawSetTitle(draw, "Approx. Solution");                                                   CHKERRQ(ierr);
245
 
    PetscLogObjectParent(ksp, (PetscObject) viewer);
246
 
    ierr = KSPSetMonitor(ksp, GVecSolutionKSPMonitor, (void *) viewer, PETSC_NULL);                       CHKERRQ(ierr);
247
 
  }
248
 
  nmax = 4;
249
 
  loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300;
250
 
  ierr = PetscOptionsGetIntArray(prefix, "-gvec_ksp_residualmonitor", loc, &nmax, &opt);                  CHKERRQ(ierr);
251
 
  if (opt) {
252
 
    ierr = PetscViewerDrawOpen(comm, 0, 0, loc[0], loc[1], loc[2], loc[3], &viewer);                      CHKERRQ(ierr);
253
 
    ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);                                                      CHKERRQ(ierr);
254
 
    ierr = PetscDrawSetTitle(draw, "Residual");                                                           CHKERRQ(ierr);
255
 
    PetscLogObjectParent(ksp, (PetscObject) viewer);
256
 
    ierr = KSPSetMonitor(ksp, GVecResidualKSPMonitor, (void *) viewer, PETSC_NULL);                       CHKERRQ(ierr);
257
 
  }
258
 
  nmax = 4;
259
 
  loc[0] = PETSC_DECIDE; loc[1] = PETSC_DECIDE; loc[2] = 300; loc[3] = 300;
260
 
  ierr = PetscOptionsGetIntArray(prefix, "-gvec_ksp_rhsmonitor", loc, &nmax, &opt);                       CHKERRQ(ierr);
261
 
  if (opt) {
262
 
    ierr = PetscViewerDrawOpen(comm, 0, 0, loc[0], loc[1], loc[2], loc[3], &viewer);                      CHKERRQ(ierr);
263
 
    ierr = PetscViewerDrawGetDraw(viewer, 0, &draw);                                                      CHKERRQ(ierr);
264
 
    ierr = PetscDrawSetTitle(draw, "Rhs");                                                                CHKERRQ(ierr);
265
 
    PetscLogObjectParent(ksp, (PetscObject) viewer);
266
 
    ierr = KSPSetMonitor(ksp, GVecRhsKSPMonitor, (void *) viewer, PETSC_NULL);                            CHKERRQ(ierr);
267
 
  }
268
 
  ierr = PetscOptionsGetString(prefix, "-gvec_mg_monitor", string, 64, &opt);                             CHKERRQ(ierr);
269
 
  if (opt) {
270
 
    PC  pc;
271
 
    int all = 0;
272
 
 
273
 
    ierr = PetscStrstr(string, "nosolution", &p);                                                         CHKERRQ(ierr);
274
 
    if (!p) all |= GVECPCMGMONITOR_SOLUTION;
275
 
    ierr = PetscStrstr(string, "noresidual", &p);                                                         CHKERRQ(ierr);
276
 
    if (!p) all |= GVECPCMGMONITOR_RESIDUAL;
277
 
    ierr = PetscStrstr(string, "norhs",      &p);                                                         CHKERRQ(ierr);
278
 
    if (!p) all |= GVECPCMGMONITOR_RHS;
279
 
    ierr = KSPGetPC(ksp, &pc);                                                                            CHKERRQ(ierr);
280
 
    ierr = GVecPCMGSetMonitor(pc, all);                                                                   CHKERRQ(ierr);
281
 
  }
282
 
  ierr = PetscOptionsHasName(PETSC_NULL, "-help", &opt);                                                  CHKERRQ(ierr);
283
 
  if (opt) {
284
 
    char *pprefix;
285
 
    int   len = 2;
286
 
 
287
 
    if (prefix != PETSC_NULL) {
288
 
      ierr = PetscStrlen(prefix, &len);                                                                   CHKERRQ(ierr);
289
 
    }
290
 
    ierr = PetscMalloc((len+2) * sizeof(char), &pprefix);                                                 CHKERRQ(ierr);
291
 
    PetscStrcpy(pprefix, "-");
292
 
    if (prefix != PETSC_NULL)
293
 
      PetscStrcat(pprefix, prefix);
294
 
    PetscPrintf(comm," Additional KSP Monitor options for grid vectors\n");
295
 
    PetscPrintf(comm,"   %sgvec_ksp_solutionmonitor\n", pprefix);
296
 
    PetscPrintf(comm,"   %sgvec_ksp_residualmonitor\n", pprefix);
297
 
    PetscPrintf(comm,"   %sgvec_ksp_rhsmonitor\n", pprefix);
298
 
    PetscPrintf(comm,"   %sgvec_mg_monitor [nosolution,norhs,noresidual]\n", pprefix);
299
 
    ierr = PetscFree(pprefix);                                                                            CHKERRQ(ierr);
300
 
  }
301
 
  PetscFunctionReturn(0);
302
 
}
303
 
EXTERN_C_END
304
 
 
305
 
/*--------------------------------------------------- Uzawa Methods --------------------------------------------------*/
306
 
#undef  __FUNCT__
307
 
#define __FUNCT__ "GMatCreateUzawa"
308
 
/*@
309
 
   GMatCreateUzawa - Creates a container matrix for the Uzawa system matrix B^T A^{-1} B.
310
 
 
311
 
   Input Parameter:
312
 
+  A    - The square (0,0) block of the original saddle-point matrix
313
 
.  B    - The rectangular (0,1) block of the original saddle-point matrix
314
 
-  sles - The solver used to invert A
315
 
 
316
 
   Output Parameter:
317
 
.  gmat - The discrete operator
318
 
 
319
 
  Level: advanced
320
 
 
321
 
.seealso: GVecCreate()
322
 
@*/
323
 
int GMatCreateUzawa(GMat A, GMat B, SLES sles, GMat *gmat)
324
 
{
325
 
  UzawaContext *uCtx;
326
 
  MPI_Comm      comm;
327
 
  Grid          grid, grid2;
328
 
  int           M, m, N, n;
329
 
  int           O, o, P, p;
330
 
  int           ierr;
331
 
 
332
 
  PetscFunctionBegin;
333
 
  PetscValidHeaderSpecific(A,    MAT_COOKIE);
334
 
  PetscValidHeaderSpecific(B,    MAT_COOKIE);
335
 
  PetscValidHeaderSpecific(sles, SLES_COOKIE);
336
 
  PetscValidPointer(gmat);
337
 
  ierr = GMatGetGrid(A, &grid);                                                                           CHKERRQ(ierr);
338
 
  ierr = GMatGetGrid(B, &grid2);                                                                          CHKERRQ(ierr);
339
 
  PetscValidHeaderSpecific(grid,  GRID_COOKIE);
340
 
  PetscValidHeaderSpecific(grid2, GRID_COOKIE);
341
 
  if (grid != grid2) SETERRQ(PETSC_ERR_ARG_INCOMP, "Matrices must all have the same underlying grid.");
342
 
  ierr = PetscNew(UzawaContext, &uCtx);                                                                   CHKERRQ(ierr);
343
 
  uCtx->A    = A;
344
 
  uCtx->B    = B;
345
 
  uCtx->sles = sles;
346
 
  ierr = MatGetSize(A, &M, &N);                                                                           CHKERRQ(ierr);
347
 
  ierr = MatGetLocalSize(A, &m, &n);                                                                      CHKERRQ(ierr);
348
 
  ierr = MatGetSize(B, &O, &P);                                                                           CHKERRQ(ierr);
349
 
  ierr = MatGetLocalSize(B, &o, &p);                                                                      CHKERRQ(ierr);
350
 
  if ((m != o) || (n != o) || (M != O) || (N != O)) {
351
 
    SETERRQ(PETSC_ERR_ARG_INCOMP, "Incommensurate sizes, B^T A B must be a legal matrix");
352
 
  }
353
 
  ierr = PetscObjectGetComm((PetscObject) grid, &comm);                                                   CHKERRQ(ierr);
354
 
  ierr = MatCreateShell(comm, p, p, P, P, uCtx, gmat);                                                    CHKERRQ(ierr);
355
 
  ierr = MatShellSetOperation(*gmat, MATOP_MULT, (void (*)(void)) GMatMatMultUzawa);                      CHKERRQ(ierr);
356
 
  ierr = VecCreateMPI(comm, m, M, &uCtx->work);                                                           CHKERRQ(ierr);
357
 
  ierr = VecDuplicate(uCtx->work, &uCtx->work2);                                                          CHKERRQ(ierr);
358
 
  PetscFunctionReturn(0);
359
 
}
360
 
 
361
 
#undef __FUNCT__  
362
 
#define __FUNCT__ "GMatMatMultUzawa"
363
 
/*@
364
 
  GMatMatMultUzawa - This function applies B^T A^{-1} B to a vector,
365
 
  which is the Schur complement matrix.
366
 
 
367
 
  Input Parameters:
368
 
+ mat - The grid matrix
369
 
- x   - The input grid vector
370
 
 
371
 
  Output Parameter:
372
 
. y - The output grid vector B^T A^{-1} B x
373
 
 
374
 
  Level: advanced
375
 
 
376
 
.seealso: GMatEvaluateOperatorGalerkin
377
 
@*/
378
 
int GMatMatMultUzawa(GMat mat, GVec x, GVec y)
379
 
{
380
 
  UzawaContext *ctx;
381
 
  int           its;
382
 
  int           ierr;
383
 
 
384
 
  PetscFunctionBegin;
385
 
  PetscValidHeaderSpecific(mat, MAT_COOKIE);
386
 
  PetscValidHeaderSpecific(x,   VEC_COOKIE);
387
 
  PetscValidHeaderSpecific(y,   VEC_COOKIE);
388
 
  ierr = MatShellGetContext(mat, (void **) &ctx);                                                         CHKERRQ(ierr);
389
 
  ierr = MatMult(ctx->B, x, ctx->work);                                                                   CHKERRQ(ierr);
390
 
  ierr = SLESSolve(ctx->sles, ctx->work, ctx->work2, &its);                                               CHKERRQ(ierr);
391
 
  ierr = MatMultTranspose(ctx->B, ctx->work2, y);                                                         CHKERRQ(ierr);
392
 
  PetscFunctionReturn(0);
393
 
}
394
 
 
395
 
#undef  __FUNCT__
396
 
#define __FUNCT__ "GMatDestroyUzawa"
397
 
/*@
398
 
   GMatDestroyUzawa - Destroys a container matrix for the Uzawa
399
 
   system matrix B^T A B.
400
 
 
401
 
   Input Parameter:
402
 
.  gmat - The container matrix from GMatCreateUzawa()
403
 
 
404
 
  Level: advanced
405
 
 
406
 
.seealso: GVecCreate()
407
 
@*/
408
 
int GMatDestroyUzawa(GMat gmat)
409
 
{
410
 
  UzawaContext *ctx;
411
 
  int           ierr;
412
 
 
413
 
  PetscFunctionBegin;
414
 
  PetscValidHeaderSpecific(gmat, MAT_COOKIE);
415
 
 
416
 
  ierr = MatShellGetContext(gmat, (void **) &ctx);                                                        CHKERRQ(ierr);
417
 
  if (ctx != PETSC_NULL) {
418
 
    ierr = VecDestroy(ctx->work);                                                                         CHKERRQ(ierr);
419
 
    ierr = VecDestroy(ctx->work2);                                                                        CHKERRQ(ierr);
420
 
    ierr = PetscFree(ctx);                                                                                CHKERRQ(ierr);
421
 
  }
422
 
  ierr = MatDestroy(gmat);                                                                                CHKERRQ(ierr);
423
 
  PetscFunctionReturn(0);
424
 
}