<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Dear Petsc developer:</div><div>Hi,</div><div>Recently, I am very interested in the ex19 example in SNES, which uses NGS method to solve the non-linear equations, which may be the method I need to use in the future. I have some doubts about the program. <br></div><div>1.</div></div></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><div><div><div>82: typedef struct {</div></div></div></div></div></div><div><div><div><div><div><div>83:   PetscScalar u,v,omega,temp;</div></div></div></div></div></div><div><div><div><div><div><div>84: } Field</div></div></div></div></div></div><div><div><div><div><div><div>86: PetscErrorCode FormFunctionLocal(DMDALocalInfo*,Field**,Field**,void*);</div></div></div></div></div></div><div><div><div><div><div><div>…</div></div></div></div></div></div><div><div><div><div><div><div>150:   DMDASNESSetFunctionLocal(da,INSERT_VALUES,(PetscErrorCode (*)(DMDALocalInfo*,void*,void*,void*))FormFunctionLocal,&user);</div></div></div></div></div></div></blockquote><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><br></div><div>I looked at PETSc manualpage: <br></div></div></div></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div><div><div><div><div>For PetscErrorCode (*func)(DMDALocalInfo *info,void *x, void *f, void *ctx),</div></div></div></div></div></div></div><div><div><div><div><div><div>info<span style="white-space:pre">    </span>- DMDALocalInfo defining the subdomain to evaluate the residual on</div></div></div></div></div></div><div><div><div><div><div><div>x<span style="white-space:pre">        </span>- dimensional pointer to state at which to evaluate residual (e.g. PetscScalar *x or **x or ***x)</div></div></div></div></div></div><div><div><div><div><div><div>f<span style="white-space:pre"> </span>- dimensional pointer to residual, write the residual here (e.g. PetscScalar *f or **f or ***f)</div></div></div></div></div></div><div><div><div><div><div><div>ctx<span style="white-space:pre"> </span>- optional context passed above</div></div></div></div></div></div></blockquote>In the function FormFunctionLocal, the second and third parameters should be pointers to PetscScalar, where pointers are directly used to point to Field. Why can we use them here?            Although I know that there are four degrees of freedom in DM objects, how can I ensure that the program correctly corresponds to variables in Field? <br></div><div dir="ltr"><br></div><div dir="ltr">2.</div><div dir="ltr">In the NGS subroutine, <br></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div dir="ltr"><div dir="ltr"><div>530: dfudu = 2.0* (hydhx + hxdhy);            </div></div></div></blockquote><div dir="ltr"><div dir="ltr"><div dir="ltr">But in the residual function:            </div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><div>526: u = x[j][i].u;            </div></div></div><div><div><div>527: uxx = (2.0*u - x[j][i-1].u - x[j][i+1].u) *hydhx;            </div></div></div><div><div><div>528: uyy = (2.0*u - x[j-1][i].u - x[j+1][i].u) *hxdhy;            </div></div></div><div><div><div>529: Fu = uxx + uyy -.5* (x[j+1][i].omega-x[j-1][i].omega) *hx - bjiu;            </div></div></div><div><div><div>/ * invert the system:           </div></div></div><div><div>572:              [ dfu / du     0        0        0    ][yu] = [fu]</div><div>573:              [     0    dfv / dv     0        0    ][yv]   [fv]</div><div>574:              [ dfo / du dfo / dv dfo / do     0    ][yo]   [fo]</div><div>575:              [ dft / du dft / dv     0    dft / dt ][yt]   [ft]</div><div>576:              by simple back-substitution         </div></div><div><div><div>577: * / </div></div></div></blockquote>It is known that the residual function fu [j] [i] is a function of five variables (x [j] [i].u, x [j] [i-1].u, x [j] [i+1].u, x [j-1] [i].u, x [j+1] [i] [i].u) (it is same for analytic Jacobian matrix). But in this program, only the central grid is used to solve the partial derivatives. Why do we choose to do so?            In my understanding, the sub-matrix 'dfudu' is a five-diagonal matrix, but it is processed into a diagonal matrix in the program. Will this affect the accuracy of the solution? <br></div><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr">Thanks for your continuous help,</div><div dir="ltr">Yingjie</div></div></div></div></div>