1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
<center><a href="snesimpl.h">Actual source code: snesimpl.h</a></center><br>
<html>
<head>
<title></title>
<meta name="generator" content="c2html 0.9.5">
<meta name="date" content="2010-04-08T19:42:27+00:00">
</head>
<body bgcolor="#FFFFFF">
<pre width="80">
<a name="line2"> 2: </a><font color="#A020F0">#ifndef __SNESIMPL_H</font>
<a name="line5"> 5: </a> #include <A href="../../include/petscsnes.h.html">petscsnes.h</A>
<a name="line7"> 7: </a><font color="#4169E1">typedef struct _SNESOps *SNESOps;</font>
<a name="line9"> 9: </a><font color="#4169E1"><a name="_SNESOps"></a>struct _SNESOps </font>{
<a name="line10"> 10: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*computefunction)(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>,<A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A>,<A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A>,void*);
<a name="line11"> 11: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*computejacobian)(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>,<A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A>,<A href="../docs/manualpages/Mat/Mat.html#Mat">Mat</A>*,<A href="../docs/manualpages/Mat/Mat.html#Mat">Mat</A>*,<A href="../docs/manualpages/Mat/MatStructure.html#MatStructure">MatStructure</A>*,void*);
<a name="line12"> 12: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*computescaling)(<A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A>,<A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A>,void*);
<a name="line13"> 13: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*update)(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>, <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A>); <font color="#B22222">/* General purpose function for update */</font>
<a name="line14"> 14: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*converged)(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>,<A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A>,<A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A>,<A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A>,<A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A>,<A href="../docs/manualpages/SNES/SNESConvergedReason.html#SNESConvergedReason">SNESConvergedReason</A>*,void*);
<a name="line15"> 15: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*convergeddestroy)(void*);
<a name="line16"> 16: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*setup)(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>); <font color="#B22222">/* routine to set up the nonlinear solver */</font>
<a name="line17"> 17: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*solve)(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>); <font color="#B22222">/* actual nonlinear solver */</font>
<a name="line18"> 18: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*view)(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>,<A href="../docs/manualpages/Viewer/PetscViewer.html#PetscViewer">PetscViewer</A>);
<a name="line19"> 19: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*setfromoptions)(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>); <font color="#B22222">/* sets options from database */</font>
<a name="line20"> 20: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*destroy)(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>);
<a name="line21"> 21: </a>};
<a name="line23"> 23: </a><font color="#B22222">/*</font>
<a name="line24"> 24: </a><font color="#B22222"> Nonlinear solver context</font>
<a name="line25"> 25: </a><font color="#B22222"> */</font>
<a name="line26"> 26: </a><strong><font color="#228B22">#define MAXSNESMONITORS 5</font></strong>
<a name="line28"> 28: </a><font color="#4169E1"><a name="_p_SNES"></a>struct _p_SNES </font>{
<a name="line29"> 29: </a> PETSCHEADER(<font color="#4169E1">struct _SNESOps</font>);
<a name="line31"> 31: </a> <font color="#B22222">/* ------------------------ User-provided stuff -------------------------------*/</font>
<a name="line32"> 32: </a> void *user; <font color="#B22222">/* user-defined context */</font>
<a name="line34"> 34: </a> <A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A> vec_rhs; <font color="#B22222">/* If non-null, solve F(x) = rhs */</font>
<a name="line35"> 35: </a> <A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A> vec_sol; <font color="#B22222">/* pointer to solution */</font>
<a name="line37"> 37: </a> <A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A> vec_func; <font color="#B22222">/* pointer to function */</font>
<a name="line38"> 38: </a> void *funP; <font color="#B22222">/* user-defined function context */</font>
<a name="line39"> 39: </a>
<a name="line40"> 40: </a> <A href="../docs/manualpages/Mat/Mat.html#Mat">Mat</A> jacobian; <font color="#B22222">/* Jacobian matrix */</font>
<a name="line41"> 41: </a> <A href="../docs/manualpages/Mat/Mat.html#Mat">Mat</A> jacobian_pre; <font color="#B22222">/* preconditioner matrix */</font>
<a name="line42"> 42: </a> void *jacP; <font color="#B22222">/* user-defined Jacobian context */</font>
<a name="line43"> 43: </a> <A href="../docs/manualpages/KSP/KSP.html#KSP">KSP</A> ksp; <font color="#B22222">/* linear solver context */</font>
<a name="line45"> 45: </a> <A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A> vec_sol_update; <font color="#B22222">/* pointer to solution update */</font>
<a name="line46"> 46: </a>
<a name="line47"> 47: </a> <A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A> scaling; <font color="#B22222">/* scaling vector */</font>
<a name="line48"> 48: </a> void *scaP; <font color="#B22222">/* scaling context */</font>
<a name="line50"> 50: </a> <font color="#B22222">/* ------------------------Time stepping hooks-----------------------------------*/</font>
<a name="line52"> 52: </a> <font color="#B22222">/* ---------------- PETSc-provided (or user-provided) stuff ---------------------*/</font>
<a name="line54"> 54: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*monitor[MAXSNESMONITORS])(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>,<A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A>,<A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A>,void*); <font color="#B22222">/* monitor routine */</font>
<a name="line55"> 55: </a> <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> (*monitordestroy[MAXSNESMONITORS])(void*); <font color="#B22222">/* monitor context destroy routine */</font>
<a name="line56"> 56: </a> void *monitorcontext[MAXSNESMONITORS]; <font color="#B22222">/* monitor context */</font>
<a name="line57"> 57: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> numbermonitors; <font color="#B22222">/* number of monitors */</font>
<a name="line58"> 58: </a> void *cnvP; <font color="#B22222">/* convergence context */</font>
<a name="line59"> 59: </a> <A href="../docs/manualpages/SNES/SNESConvergedReason.html#SNESConvergedReason">SNESConvergedReason</A> reason;
<a name="line61"> 61: </a> <font color="#B22222">/* --- Routines and data that are unique to each particular solver --- */</font>
<a name="line63"> 63: </a> <A href="../docs/manualpages/Sys/PetscTruth.html#PetscTruth">PetscTruth</A> setupcalled; <font color="#B22222">/* true if setup has been called */</font>
<a name="line64"> 64: </a> void *data; <font color="#B22222">/* implementation-specific data */</font>
<a name="line66"> 66: </a> <font color="#B22222">/* -------------------------- Parameters -------------------------------------- */</font>
<a name="line68"> 68: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> max_its; <font color="#B22222">/* max number of iterations */</font>
<a name="line69"> 69: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> max_funcs; <font color="#B22222">/* max number of function evals */</font>
<a name="line70"> 70: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> nfuncs; <font color="#B22222">/* number of function evaluations */</font>
<a name="line71"> 71: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> iter; <font color="#B22222">/* global iteration number */</font>
<a name="line72"> 72: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> linear_its; <font color="#B22222">/* total number of linear solver iterations */</font>
<a name="line73"> 73: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> norm; <font color="#B22222">/* residual norm of current iterate */</font>
<a name="line74"> 74: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> rtol; <font color="#B22222">/* relative tolerance */</font>
<a name="line75"> 75: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> abstol; <font color="#B22222">/* absolute tolerance */</font>
<a name="line76"> 76: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> xtol; <font color="#B22222">/* relative tolerance in solution */</font>
<a name="line77"> 77: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> deltatol; <font color="#B22222">/* trust region convergence tolerance */</font>
<a name="line78"> 78: </a> <A href="../docs/manualpages/Sys/PetscTruth.html#PetscTruth">PetscTruth</A> printreason; <font color="#B22222">/* print reason for convergence/divergence after each solve */</font>
<a name="line79"> 79: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> lagpreconditioner; <font color="#B22222">/* <A href="../docs/manualpages/SNES/SNESSetLagPreconditioner.html#SNESSetLagPreconditioner">SNESSetLagPreconditioner</A>() */</font>
<a name="line80"> 80: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> lagjacobian; <font color="#B22222">/* <A href="../docs/manualpages/SNES/SNESSetLagJacobian.html#SNESSetLagJacobian">SNESSetLagJacobian</A>() */</font>
<a name="line81"> 81: </a> <font color="#B22222">/* ------------------------ Default work-area management ---------------------- */</font>
<a name="line83"> 83: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> nwork;
<a name="line84"> 84: </a> <A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A> *work;
<a name="line86"> 86: </a> <font color="#B22222">/* ------------------------- Miscellaneous Information ------------------------ */</font>
<a name="line88"> 88: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> *conv_hist; <font color="#B22222">/* If !0, stores function norm (or</font>
<a name="line89"> 89: </a><font color="#B22222"> gradient norm) at each iteration */</font>
<a name="line90"> 90: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> *conv_hist_its; <font color="#B22222">/* linear iterations for each Newton step */</font>
<a name="line91"> 91: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> conv_hist_len; <font color="#B22222">/* size of convergence history array */</font>
<a name="line92"> 92: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> conv_hist_max; <font color="#B22222">/* actual amount of data in conv_history */</font>
<a name="line93"> 93: </a> <A href="../docs/manualpages/Sys/PetscTruth.html#PetscTruth">PetscTruth</A> conv_hist_reset; <font color="#B22222">/* reset counter for each new <A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A> solve */</font>
<a name="line95"> 95: </a> <font color="#B22222">/* the next two are used for failures in the line search; they should be put into the LS struct */</font>
<a name="line96"> 96: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> numFailures; <font color="#B22222">/* number of unsuccessful step attempts */</font>
<a name="line97"> 97: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> maxFailures; <font color="#B22222">/* maximum number of unsuccessful step attempts */</font>
<a name="line99"> 99: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> numLinearSolveFailures;
<a name="line100">100: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> maxLinearSolveFailures;
<a name="line102">102: </a> <A href="../docs/manualpages/Sys/PetscTruth.html#PetscTruth">PetscTruth</A> domainerror; <font color="#B22222">/* set with <A href="../docs/manualpages/SNES/SNESSetFunctionDomainError.html#SNESSetFunctionDomainError">SNESSetFunctionDomainError</A>() */</font>
<a name="line104">104: </a> <A href="../docs/manualpages/Sys/PetscTruth.html#PetscTruth">PetscTruth</A> ksp_ewconv; <font color="#B22222">/* flag indicating use of Eisenstat-Walker <A href="../docs/manualpages/KSP/KSP.html#KSP">KSP</A> convergence criteria */</font>
<a name="line105">105: </a> void *kspconvctx; <font color="#B22222">/* Eisenstat-Walker <A href="../docs/manualpages/KSP/KSP.html#KSP">KSP</A> convergence context */</font>
<a name="line107">107: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> ttol; <font color="#B22222">/* used by default convergence test routine */</font>
<a name="line109">109: </a> <A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A> *vwork; <font color="#B22222">/* more work vectors for Jacobian approx */</font>
<a name="line110">110: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> nvwork;
<a name="line111">111: </a>};
<a name="line113">113: </a><font color="#B22222">/* Context for Eisenstat-Walker convergence criteria for <A href="../docs/manualpages/KSP/KSP.html#KSP">KSP</A> solvers */</font>
<a name="line114">114: </a><font color="#4169E1">typedef</font> <font color="#4169E1">struct</font> {
<a name="line115">115: </a> <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> version; <font color="#B22222">/* flag indicating version 1 or 2 of test */</font>
<a name="line116">116: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> rtol_0; <font color="#B22222">/* initial rtol */</font>
<a name="line117">117: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> rtol_last; <font color="#B22222">/* last rtol */</font>
<a name="line118">118: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> rtol_max; <font color="#B22222">/* maximum rtol */</font>
<a name="line119">119: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> gamma; <font color="#B22222">/* mult. factor for version 2 rtol computation */</font>
<a name="line120">120: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> alpha; <font color="#B22222">/* power for version 2 rtol computation */</font>
<a name="line121">121: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> alpha2; <font color="#B22222">/* power for safeguard */</font>
<a name="line122">122: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> threshold; <font color="#B22222">/* threshold for imposing safeguard */</font>
<a name="line123">123: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> lresid_last; <font color="#B22222">/* linear residual from last iteration */</font>
<a name="line124">124: </a> <A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A> norm_last; <font color="#B22222">/* function norm from last iteration */</font>
<a name="line125">125: </a>} SNESKSPEW;
<a name="line127">127: </a><strong><font color="#228B22">#define SNESLogConvHistory(snes,res,its) \</font></strong>
<a name="line128">128: </a><strong><font color="#228B22"> { if (snes->conv_hist && snes->conv_hist_max > snes->conv_hist_len) \</font></strong>
<a name="line129">129: </a><strong><font color="#228B22"> { if (snes->conv_hist) snes->conv_hist[snes->conv_hist_len] = res; \</font></strong>
<a name="line130">130: </a><strong><font color="#228B22"> if (snes->conv_hist_its) snes->conv_hist_its[snes->conv_hist_len] = its; \</font></strong>
<a name="line131">131: </a><strong><font color="#228B22"> snes->conv_hist_len++;\</font></strong>
<a name="line132">132: </a><strong><font color="#228B22"> }}</font></strong>
<a name="line134">134: </a><strong><font color="#228B22">#define SNESMonitor(snes,it,rnorm) \</font></strong>
<a name="line135">135: </a><strong><font color="#228B22"> { <A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> _ierr; <A href="../docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</A> _i,_im = snes->numbermonitors; \</font></strong>
<a name="line136">136: </a><strong><font color="#228B22"> for (_i=0; _i<_im; _i++) {\</font></strong>
<a name="line137">137: </a><strong><font color="#228B22"> _(*snes->monitor[_i])(snes,it,rnorm,snes->monitorcontext[_i]);<A href="../docs/manualpages/Sys/CHKERRQ.html#CHKERRQ">CHKERRQ</A>(_ierr); \</font></strong>
<a name="line138">138: </a><strong><font color="#228B22"> } \</font></strong>
<a name="line139">139: </a><strong><font color="#228B22"> }</font></strong>
<a name="line141">141: </a><strong><font color="#4169E1"><A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> SNES_KSPSolve(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>,<A href="../docs/manualpages/KSP/KSP.html#KSP">KSP</A>,<A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A>,<A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A>)</font></strong>;
<a name="line142">142: </a><strong><font color="#4169E1"><A href="../docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</A> SNESScaleStep_Private(<A href="../docs/manualpages/SNES/SNES.html#SNES">SNES</A>,<A href="../docs/manualpages/Vec/Vec.html#Vec">Vec</A>,<A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A>*,<A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A>*,<A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A>*,<A href="../docs/manualpages/Sys/PetscReal.html#PetscReal">PetscReal</A>*)</font></strong>;
<a name="line149">149: </a><font color="#A020F0">#endif</font>
</pre>
</body>
</html>
|