<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi,<br>
    <br>
    Thanks for pointing out my mistake. I'm still learning about the
    code. I corrected but I still get the error:<br>
    <br>
    [0]PETSC ERROR: --------------------- Error Message
    ----------------------------<br>
    --------<br>
    [0]PETSC ERROR: Argument out of range!<br>
    [0]PETSC ERROR: New nonzero at (2,4) caused a malloc!<br>
    [0]PETSC ERROR:
    ----------------------------------------------------------------<br>
    <br>
    boundary condition region:<br>
    <br>
    num = 1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (j/=0) then<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = -rho*HxdHy<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,num) = i<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,num) = j-1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end if<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (i/=0) then<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = -rho*HydHx<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,num) = i-1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,num) = j<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end if<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (i/=mx-1) then<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = -rho*HydHx<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,num) = i+1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,num) = j<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end if<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (j/=my-1) then<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = -rho*HxdHy<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,num) = i<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,num) = j+1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end if<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = (num/2.0)*rho*(HxdHy + HydHx)<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,num) = i<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,num) = j+1<br>
    <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; call
    MatSetValuesStencil(jac,i1,row,num,col,v,INSERT_VALUES,ierr)<br>
    <pre class="moz-signature" cols="72">Yours sincerely,

TAY wee-beng</pre>
    <br>
    On 26/4/2012 2:45 PM, Matthew Knepley wrote:
    <blockquote
cite="mid:CAMYG4GnHyb1VKSY3gwpTxyU=xe1ZcEhitKCu5+CpK9a1v0ymuA@mail.gmail.com"
      type="cite">
      <div class="gmail_extra">On Thu, Apr 26, 2012 at 8:27 AM, TAY
        wee-beng <span dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:zonexo@gmail.com" target="_blank">zonexo@gmail.com</a>&gt;</span>
        wrote:<br>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000"> Hi,<br>
              <br>
              Is there an answer to the question below?<br>
              &nbsp;I still can't get it working.<br>
              <br>
              Thanks.<br>
              <br>
              <br>
              Hi,<br>
              <br>
              There's no error now but I didn't get the same ans as
              ex29. I believe the error lies in the boundary evaluation
              of v.<br>
              <br>
              In c, the code is :<br>
              <br>
              else if (user-&gt;bcType == NEUMANN) {<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; num = 0;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (j!=0) {<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v[num] = -rho*HxdHy;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col[num].i =
              i;&nbsp;&nbsp; col[num].j = j-1;<br>
            </div>
          </blockquote>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; ^^^ See this?&nbsp;</div>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; num++;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (i!=0) {<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v[num] = -rho*HydHx;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col[num].i =
              i-1; col[num].j = j;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; num++;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (i!=mx-1) {<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v[num] = -rho*HydHx;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col[num].i =
              i+1; col[num].j = j;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; num++;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (j!=my-1) {<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v[num] = -rho*HxdHy;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col[num].i =
              i;&nbsp;&nbsp; col[num].j = j+1;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; num++;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v[num]&nbsp;&nbsp; = (num/2.0)*rho*(HxdHy + HydHx);
              col[num].i = i;&nbsp;&nbsp; col[num].j = j;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; num++;<br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ierr =
MatSetValuesStencil(jac,1,&amp;row,num,col,v,INSERT_VALUES);CHKERRQ(ierr);<br>
              <br>
              In fortran, I have changed to :<br>
              <br>
              else if (bc_cond == 2) then<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = 1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (j/=0) then<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = -rho*HxdHy<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,1) = i<br>
            </div>
          </blockquote>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^^ Why is
            this 1 in stead of 'num'?&nbsp;</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp;Matt</div>
          <div><br>
          </div>
          <div><br>
          </div>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000"> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
              col(MatStencil_j,2) = j-1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end if<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (i/=0) then<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = -rho*HydHx<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,1) = i-1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,2) = j<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end if<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (i/=mx-1) then<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = -rho*HydHx<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,1) = i+1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,2) = j<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end if<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (j/=my-1) then<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = -rho*HxdHy<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,1) = i<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,2) = j+1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end if<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(num) = (num/2.0)*rho*(HxdHy + HydHx)<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,1) = i<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,2) = j+1<br>
              <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num = num + 1<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; call
              MatSetValuesStencil(jac,i1,row,num,col,v,INSERT_VALUES,ierr)<br>
              <br>
              However, I got the error: <br>
              <br>
              [0]PETSC ERROR: --------------------- Error Message
              ---------------------------<br>
              --------<br>
              [0]PETSC ERROR: Argument out of range!<br>
              [0]PETSC ERROR: New nonzero at (1,3) caused a malloc!<br>
              [0]PETSC ERROR:
              ---------------------------------------------------------------<br>
              <br>
              How such is be defined in Fortran?<br>
              <br>
              Thank you<br>
              <pre cols="72">Yours sincerely,

TAY wee-beng</pre>
              <br>
              On 25/4/2012 12:06 AM, Matthew Knepley wrote:
              <blockquote type="cite">
                <div class="gmail_extra">On Tue, Apr 24, 2012 at 4:57
                  PM, TAY wee-beng <span dir="ltr">&lt;<a
                      moz-do-not-send="true"
                      href="mailto:zonexo@gmail.com" target="_blank">zonexo@gmail.com</a>&gt;</span>
                  wrote:<br>
                  <div class="gmail_quote">
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div bgcolor="#FFFFFF" text="#000000"> Hi,<br>
                        <br>
                        I still got the same error the moment this
                        subroutine is called, after changing to :<br>
                        <br>
                        call
MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_TRUE,PETSC_NULL_INTEGER,PETSC_NULL_OBJECT,nullspace,ierr)<br>
                      </div>
                    </blockquote>
                    <div><br>
                    </div>
                    <div>Argument 3 should be 0.</div>
                    <div><br>
                    </div>
                    <div>&nbsp; Matt</div>
                    <div>&nbsp;</div>
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div bgcolor="#FFFFFF" text="#000000"> [0]PETSC
                        ERROR: Null argument, when expecting valid
                        pointer!<br>
                        [0]PETSC ERROR: Null Object: Parameter # 4!<br>
                        [0]PETSC ERROR:
                        ----------------------------------------------------------------<br>
                        --------<br>
                        [0]PETSC ERROR: Petsc Development HG revision:
                        fc934c1d84bc6ba8e2686702a8a99539d<br>
                        50af122&nbsp; HG Date: Mon Apr 23 11:39:32 2012 -0500<br>
                        [0]PETSC ERROR: See docs/changes/index.html for
                        recent updates.<br>
                        [0]PETSC ERROR: See docs/faq.html for hints
                        about trouble shooting.<br>
                        [0]PETSC ERROR: See docs/index.html for manual
                        pages.<br>
                        [0]PETSC ERROR:
                        ----------------------------------------------------------------<br>
                        --------<br>
                        [0]PETSC ERROR: c:\obj_tmp\ex29f\Debug\ex29f.exe
                        on a petsc-3.2 named USER-PC by<br>
                        &nbsp;User Tue Apr 24 22:54:50 2012<br>
                        [0]PETSC ERROR: Libraries linked from
                        /cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
                        /lib<br>
                        [0]PETSC ERROR: Configure run at Mon Apr 23
                        21:45:20 2012<br>
                        [0]PETSC ERROR: Configure options
                        --with-cc="win32fe cl" --with-fc="win32fe ifor<br>
                        t" --with-cxx="win32fe cl"
                        --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
                        --download-f-b<br>
                        las-lapack=1
                        --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
                        --with-debuggin<br>
                        g=1 --useThreads=0<br>
                        [0]PETSC ERROR:
                        ----------------------------------------------------------------<br>
                        --------<br>
                        [0]PETSC ERROR: MatNullSpaceCreate() line 250 in
                        src/mat/interface/C:\temp\PETSC<br>
                        -~1\src\mat\INTERF~1\matnull.c<br>
                        <pre cols="72">Yours sincerely,

TAY wee-beng</pre>
                        <br>
                        On 24/4/2012 10:37 PM, Matthew Knepley wrote:
                        <blockquote type="cite">
                          <div class="gmail_extra">On Tue, Apr 24, 2012
                            at 4:32 PM, TAY wee-beng <span dir="ltr">&lt;<a
                                moz-do-not-send="true"
                                href="mailto:zonexo@gmail.com"
                                target="_blank">zonexo@gmail.com</a>&gt;</span>
                            wrote:<br>
                            <div class="gmail_quote">
                              <blockquote class="gmail_quote"
                                style="margin:0 0 0 .8ex;border-left:1px
                                #ccc solid;padding-left:1ex">
                                <div bgcolor="#FFFFFF" text="#000000">
                                  Hi,<br>
                                  <br>
                                  I'm trying to rewrite ex29
                                  (KSP^Laplacian, 2d) from c to fortran
                                  version. The fortran version is based
                                  on the template of ex22f, which is in
                                  3d.<br>
                                  <br>
                                  I have attached the code below. I have
                                  2 problems.<br>
                                  <br>
                                  1. When i3 = -3, in dirichlet BC, I
                                  got the same answer as ex29 in c
                                  version.<br>
                                  <br>
                                  However, when I change i3 to -4, I got
                                  the following error:<br>
                                  <br>
                                  [0]PETSC ERROR: ---------------------
                                  Error Message
                                  ----------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Argument out of range!<br>
                                  [0]PETSC ERROR: New nonzero at (9,1)
                                  caused a malloc!<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Petsc Development HG
                                  revision:
                                  fc934c1d84bc6ba8e2686702a8a99539d<br>
                                  50af122&nbsp; HG Date: Mon Apr 23 11:39:32
                                  2012 -0500<br>
                                  [0]PETSC ERROR: See
                                  docs/changes/index.html for recent
                                  updates.<br>
                                  [0]PETSC ERROR: See docs/faq.html for
                                  hints about trouble shooting.<br>
                                  [0]PETSC ERROR: See docs/index.html
                                  for manual pages.<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR:
                                  c:\obj_tmp\ex29f\Debug\ex29f.exe on a
                                  petsc-3.2 named USER-PC by<br>
                                  &nbsp;User Tue Apr 24 22:08:46 2012<br>
                                  [0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
                                  /lib<br>
                                  [0]PETSC ERROR: Configure run at Mon
                                  Apr 23 21:45:20 2012<br>
                                  [0]PETSC ERROR: Configure options
                                  --with-cc="win32fe cl"
                                  --with-fc="win32fe ifor<br>
                                  t" --with-cxx="win32fe cl"
                                  --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
                                  --download-f-b<br>
                                  las-lapack=1
                                  --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
                                  --with-debuggin<br>
                                  g=1 --useThreads=0<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: MatSetValues_SeqAIJ()
                                  line 331 in
                                  src/mat/impls/aij/seq/C:\temp\<br>
                                  PETSC-~1\src\mat\impls\aij\seq\aij.c<br>
                                  [0]PETSC ERROR: MatSetValues() line
                                  1148 in
                                  src/mat/interface/C:\temp\PETSC-~1\s<br>
                                  rc\mat\INTERF~1\matrix.c<br>
                                  [0]PETSC ERROR: MatSetValuesLocal()
                                  line 2003 in
                                  src/mat/interface/C:\temp\PETSC<br>
                                  -~1\src\mat\INTERF~1\matrix.c<br>
                                  [0]PETSC ERROR: MatSetValuesStencil()
                                  line 1379 in
                                  src/mat/interface/C:\temp\PET<br>
                                  SC-~1\src\mat\INTERF~1\matrix.c<br>
                                  [0]PETSC ERROR: ---------------------
                                  Error Message
                                  ----------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Argument out of range!<br>
                                  [0]PETSC ERROR: New nonzero at (10,2)
                                  caused a malloc!<br>
                                  <br>
                                  ...<br>
                                  <br>
                                  What did I do wrong?<br>
                                  <br>
                                  <br>
                                  2. When I wanted to use the neumann
                                  BC, following ex29, I added :<br>
                                  <br>
                                  In subroutine ComputeRHS<br>
                                  <br>
                                  call
MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_TRUE,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,nullspace,ierr)<br>
                                  <br>
                                  call
                                  MatNullSpaceRemove(nullspace,b,PETSC_NULL,ierr)<br>
                                  <br>
                                  call
                                  MatNullSpaceDestroy(nullspace,ierr)<br>
                                  <br>
                                  and in subroutine ComputeMatrix<br>
                                  <br>
                                  call
MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_TRUE,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,nullspace,ierr)<br>
                                  <br>
                                  call
                                  MatSetNullSpace(jac,nullspace,ierr)<br>
                                  <br>
                                  call
                                  MatNullSpaceDestroy(nullspace,ierr)<br>
                                  <br>
                                  When I compile, it says unresolved
                                  external symbol MatNullSpaceRemove.
                                  Removing MatNullSpaceRemove, I can
                                  compile but running gives the error:<br>
                                  <br>
                                  [0]PETSC ERROR: ---------------------
                                  Error Message
                                  ----------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Corrupt argument:<br>
                                  see <a moz-do-not-send="true"
                                    href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind"
                                    target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a>!<br>
                                  [0]PETSC ERROR: Invalid Pointer to
                                  Object: Parameter # 4!<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Petsc Development HG
                                  revision:
                                  fc934c1d84bc6ba8e2686702a8a99539d<br>
                                  50af122&nbsp; HG Date: Mon Apr 23 11:39:32
                                  2012 -0500<br>
                                  [0]PETSC ERROR: See
                                  docs/changes/index.html for recent
                                  updates.<br>
                                  [0]PETSC ERROR: See docs/faq.html for
                                  hints about trouble shooting.<br>
                                  [0]PETSC ERROR: See docs/index.html
                                  for manual pages.<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR:
                                  c:\obj_tmp\ex29f\Debug\ex29f.exe on a
                                  petsc-3.2 named USER-PC by<br>
                                  &nbsp;User Tue Apr 24 22:30:31 2012<br>
                                  [0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
                                  /lib<br>
                                  [0]PETSC ERROR: Configure run at Mon
                                  Apr 23 21:45:20 2012<br>
                                  [0]PETSC ERROR: Configure options
                                  --with-cc="win32fe cl"
                                  --with-fc="win32fe ifor<br>
                                  t" --with-cxx="win32fe cl"
                                  --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
                                  --download-f-b<br>
                                  las-lapack=1
                                  --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
                                  --with-debuggin<br>
                                  g=1 --useThreads=0<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: MatNullSpaceCreate()
                                  line 250 in
                                  src/mat/interface/C:\temp\PETSC<br>
                                  -~1\src\mat\INTERF~1\matnull.c<br>
                                  [0]PETSC ERROR: ---------------------
                                  Error Message
                                  ----------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Invalid argument!<br>
                                  [0]PETSC ERROR: Wrong type of object:
                                  Parameter # 1!<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Petsc Development HG
                                  revision:
                                  fc934c1d84bc6ba8e2686702a8a99539d<br>
                                  50af122&nbsp; HG Date: Mon Apr 23 11:39:32
                                  2012 -0500<br>
                                  [0]PETSC ERROR: See
                                  docs/changes/index.html for recent
                                  updates.<br>
                                  [0]PETSC ERROR: See docs/faq.html for
                                  hints about trouble shooting.<br>
                                  [0]PETSC ERROR: See docs/index.html
                                  for manual pages.<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR:
                                  c:\obj_tmp\ex29f\Debug\ex29f.exe on a
                                  petsc-3.2 named USER-PC by<br>
                                  &nbsp;User Tue Apr 24 22:30:31 2012<br>
                                  [0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
                                  /lib<br>
                                  [0]PETSC ERROR: Configure run at Mon
                                  Apr 23 21:45:20 2012<br>
                                  [0]PETSC ERROR: Configure options
                                  --with-cc="win32fe cl"
                                  --with-fc="win32fe ifor<br>
                                  t" --with-cxx="win32fe cl"
                                  --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
                                  --download-f-b<br>
                                  las-lapack=1
                                  --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
                                  --with-debuggin<br>
                                  g=1 --useThreads=0<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: MatNullSpaceDestroy()
                                  line 305 in
                                  src/mat/interface/C:\temp\PETS<br>
                                  C-~1\src\mat\INTERF~1\matnull.c<br>
                                  [0]PETSC ERROR: ourdmfunction() line
                                  30 in
                                  src/dm/interface/ftn-custom/C:\temp\P<br>
ETSC-~1\src\dm\INTERF~1\FTN-CU~1\zdmf.c<br>
                                  [0]PETSC ERROR: DMComputeFunction()
                                  line 1783 in
                                  src/dm/interface/C:\temp\PETSC-<br>
                                  ~1\src\dm\INTERF~1\dm.c<br>
                                  [0]PETSC ERROR: KSPSetUp() line 218 in
src/ksp/ksp/interface/C:\temp\PETSC-~1\sr<br>
                                  c\ksp\ksp\INTERF~1\itfunc.c<br>
                                  [0]PETSC ERROR: ---------------------
                                  Error Message
                                  ----------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Corrupt argument:<br>
                                  see <a moz-do-not-send="true"
                                    href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind"
                                    target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a>!<br>
                                  [0]PETSC ERROR: Invalid Pointer to
                                  Object: Parameter # 4!<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Petsc Development HG
                                  revision:
                                  fc934c1d84bc6ba8e2686702a8a99539d<br>
                                  50af122&nbsp; HG Date: Mon Apr 23 11:39:32
                                  2012 -0500<br>
                                  [0]PETSC ERROR: See
                                  docs/changes/index.html for recent
                                  updates.<br>
                                  [0]PETSC ERROR: See docs/faq.html for
                                  hints about trouble shooting.<br>
                                  [0]PETSC ERROR: See docs/index.html
                                  for manual pages.<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR:
                                  c:\obj_tmp\ex29f\Debug\ex29f.exe on a
                                  petsc-3.2 named USER-PC by<br>
                                  &nbsp;User Tue Apr 24 22:30:31 2012<br>
                                  [0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
                                  /lib<br>
                                  [0]PETSC ERROR: Configure run at Mon
                                  Apr 23 21:45:20 2012<br>
                                  [0]PETSC ERROR: Configure options
                                  --with-cc="win32fe cl"
                                  --with-fc="win32fe ifor<br>
                                  t" --with-cxx="win32fe cl"
                                  --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
                                  --download-f-b<br>
                                  las-lapack=1
                                  --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
                                  --with-debuggin<br>
                                  g=1 --useThreads=0<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: MatNullSpaceCreate()
                                  line 250 in
                                  src/mat/interface/C:\temp\PETSC<br>
                                  -~1\src\mat\INTERF~1\matnull.c<br>
                                  [0]PETSC ERROR: ---------------------
                                  Error Message
                                  ----------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Invalid argument!<br>
                                  [0]PETSC ERROR: Wrong type of object:
                                  Parameter # 1!<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: Petsc Development HG
                                  revision:
                                  fc934c1d84bc6ba8e2686702a8a99539d<br>
                                  50af122&nbsp; HG Date: Mon Apr 23 11:39:32
                                  2012 -0500<br>
                                  [0]PETSC ERROR: See
                                  docs/changes/index.html for recent
                                  updates.<br>
                                  [0]PETSC ERROR: See docs/faq.html for
                                  hints about trouble shooting.<br>
                                  [0]PETSC ERROR: See docs/index.html
                                  for manual pages.<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR:
                                  c:\obj_tmp\ex29f\Debug\ex29f.exe on a
                                  petsc-3.2 named USER-PC by<br>
                                  &nbsp;User Tue Apr 24 22:30:31 2012<br>
                                  [0]PETSC ERROR: Libraries linked from
/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008<br>
                                  /lib<br>
                                  [0]PETSC ERROR: Configure run at Mon
                                  Apr 23 21:45:20 2012<br>
                                  [0]PETSC ERROR: Configure options
                                  --with-cc="win32fe cl"
                                  --with-fc="win32fe ifor<br>
                                  t" --with-cxx="win32fe cl"
                                  --with-mpi-dir=/cygdrive/d/Lib/MPICH2/
                                  --download-f-b<br>
                                  las-lapack=1
                                  --prefix=/cygdrive/d/Lib/petsc-3.2-dev_win32_vs2008
                                  --with-debuggin<br>
                                  g=1 --useThreads=0<br>
                                  [0]PETSC ERROR:
                                  ----------------------------------------------------------------<br>
                                  --------<br>
                                  [0]PETSC ERROR: MatNullSpaceDestroy()
                                  line 305 in
                                  src/mat/interface/C:\temp\PETS<br>
                                  C-~1\src\mat\INTERF~1\matnull.c<br>
                                  [0]PETSC ERROR: ourdmfunction() line
                                  30 in
                                  src/dm/interface/ftn-custom/C:\temp\P<br>
ETSC-~1\src\dm\INTERF~1\FTN-CU~1\zdmf.c<br>
                                  [0]PETSC ERROR: DMComputeFunction()
                                  line 1783 in
                                  src/dm/interface/C:\temp\PETSC-<br>
                                  ~1\src\dm\INTERF~1\dm.c<br>
                                  [0]PETSC ERROR: KSPSetUp() line 218 in
src/ksp/ksp/interface/C:\temp\PETSC-~1\sr<br>
                                  c\ksp\ksp\INTERF~1\itfunc.c<br>
                                  [0]PETSC ERROR: KSPSolve() line 402 in
src/ksp/ksp/interface/C:\temp\PETSC-~1\sr<br>
                                  c\ksp\ksp\INTERF~1\itfunc.c<br>
                                  Vector Object:Vec_0000000084000000_0 1
                                  MPI processes<br>
                                  &nbsp; type: mpi<br>
                                  Process [0]<br>
                                  <br>
                                  What's wrong?<br>
                                  <br>
                                  <br>
                                  <b>program ex29f</b><br>
                                  <br>
                                  implicit none<br>
                                  <br>
                                  ! - - - - - - - - - - - - - - - - - -
                                  - - - - - - - - - - - - - - - - - -<br>
                                  !&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Include files<br>
                                  ! - - - - - - - - - - - - - - - - - -
                                  - - - - - - - - - - - - - - - - - -<br>
                                  !<br>
                                  !&nbsp;&nbsp;&nbsp;&nbsp; petscsys.h&nbsp; - base PETSc
                                  routines&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; petscvec.h - vectors<br>
                                  !&nbsp;&nbsp;&nbsp;&nbsp; petscmat.h - matrices<br>
                                  !&nbsp;&nbsp;&nbsp;&nbsp; petscksp.h&nbsp;&nbsp;&nbsp; - Krylov subspace
                                  methods&nbsp; petscpc.h&nbsp; - preconditioners<br>
                                  <br>
                                  #include "finclude/petsc.h90"<br>
                                  <br>
                                  PetscErrorCode&nbsp;&nbsp; ierr<br>
                                  <br>
                                  DM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da<br>
                                  <br>
                                  KSP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ksp<br>
                                  <br>
                                  Vec&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x<br>
                                  <br>
                                  external&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                  ComputeRHS,ComputeMatrix<br>
                                  <br>
                                  PetscInt i1,i3<br>
                                  <br>
                                  call&nbsp;
                                  PetscInitialize(PETSC_NULL_CHARACTER,ierr)<br>
                                  <br>
                                  i3 = -4<br>
                                  <br>
                                  i1 = 1<br>
                                  <br>
                                  call
                                  KSPCreate(MPI_COMM_WORLD,ksp,ierr)<br>
                                  <br>
                                  call
DMDACreate2d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR,i3,i3,PETSC_DECIDE,PETSC_DECIDE,i1,i1,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,da,ierr)<br>
                                  call DMSetFunction(da,ComputeRHS,ierr)<br>
                                  call
                                  DMSetJacobian(da,ComputeMatrix,ierr)&nbsp;&nbsp;
                                  <br>
                                  call KSPSetDM(ksp,da,ierr)<br>
                                  <br>
                                  call KSPSetFromOptions(ksp,ierr)<br>
                                  call KSPSetUp(ksp,ierr)<br>
                                  call
                                  KSPSolve(ksp,PETSC_NULL_OBJECT,PETSC_NULL_OBJECT,ierr)<br>
                                  call KSPGetSolution(ksp,x,ierr)<br>
                                  call
                                  VecView(x,PETSC_VIEWER_STDOUT_WORLD,ierr)<br>
                                  call KSPDestroy(ksp,ierr)<br>
                                  call DMDestroy(da,ierr)<br>
                                  call PetscFinalize(ierr)<br>
                                  <br>
                                  end program ex29f<br>
                                  <br>
                                  subroutine ComputeRHS(da,x,b,ierr)<br>
                                  <br>
                                  implicit none<br>
                                  <br>
                                  #include "finclude/petsc.h90"<br>
                                  <br>
                                  PetscErrorCode&nbsp; ierr<br>
                                  PetscInt i,j,mx,my,xm,ym,xs,ys<br>
                                  PetscScalar&nbsp; h,nu,rho<br>
                                  PetscScalar Hx,Hy<br>
                                  PetscScalar,pointer :: array(:,:)<br>
                                  Vec&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x,b<br>
                                  DM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da<br>
                                  MatNullSpace nullspace&nbsp;&nbsp;&nbsp; !&gt;neumann
                                  BC<br>
                                  <br>
                                  nu = 0.1<br>
                                  <br>
                                  call
DMDAGetInfo(da,PETSC_NULL_INTEGER,mx,my,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,ierr)<br>
                                  <br>
                                  Hx = 1.d0 / (mx-1)<br>
                                  <br>
                                  Hy = 1.d0 / (my-1)<br>
                                  <br>
                                  call
DMDAGetCorners(da,xs,ys,PETSC_NULL_INTEGER,xm,ym,PETSC_NULL_INTEGER,ierr)<br>
                                  <br>
                                  call
                                  DMDAVecGetArrayF90(da,b,array,ierr)<br>
                                  <br>
                                  do j = ys,ys+ym-1<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; do i = xs,xs+xm-1<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; array(i,j) =
                                  exp(-(i*Hx)*(i*Hx)/nu)*exp(-(j*Hy)*(j*Hy)/nu)*Hx*Hy<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; end do<br>
                                  <br>
                                  end do<br>
                                  <br>
                                  call
                                  DMDAVecRestoreArrayF90(da,b,array,ierr)<br>
                                  <br>
                                  call VecAssemblyBegin(b,ierr)<br>
                                  <br>
                                  call VecAssemblyEnd(b,ierr)<br>
                                  <br>
                                  !call
MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_TRUE,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,nullspace,ierr)<br>
                                </div>
                              </blockquote>
                              <div><br>
                              </div>
                              <div>4th argument should be
                                PETSC_NULL_OBJECT.</div>
                              <div><br>
                              </div>
                              <div>&nbsp; &nbsp;Matt</div>
                              <div>&nbsp;</div>
                              <blockquote class="gmail_quote"
                                style="margin:0 0 0 .8ex;border-left:1px
                                #ccc solid;padding-left:1ex">
                                <div bgcolor="#FFFFFF" text="#000000">
                                  !call
                                  MatNullSpaceRemove(nullspace,b,PETSC_NULL,ierr)<br>
                                  <br>
                                  !call
                                  MatNullSpaceDestroy(nullspace,ierr)<br>
                                  <br>
                                  end subroutine ComputeRHS<br>
                                  <br>
                                  <br>
                                  subroutine
                                  ComputeMatrix(da,x,JJ,jac,str,ierr)<br>
                                  <br>
                                  implicit none<br>
                                  <br>
                                  #include "finclude/petsc.h90"<br>
                                  <br>
                                  Mat&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jac,JJ<br>
                                  <br>
                                  PetscErrorCode&nbsp;&nbsp;&nbsp; ierr<br>
                                  <br>
                                  DM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da<br>
                                  <br>
                                  PetscInt&nbsp;&nbsp;&nbsp; i,j,k,mx,my,xm<br>
                                  <br>
                                  PetscInt&nbsp;&nbsp;&nbsp; ym,xs,ys,i1,i5<br>
                                  <br>
                                  PetscScalar&nbsp; v(5),Hx,Hy,rho,centerRho<br>
                                  <br>
                                  PetscScalar&nbsp; HydHx<br>
                                  <br>
                                  PetscScalar&nbsp; HxdHy<br>
                                  <br>
                                  MatStencil&nbsp;&nbsp; row(4),col(4,5)<br>
                                  <br>
                                  Vec&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x<br>
                                  <br>
                                  MatStructure str<br>
                                  <br>
                                  MatNullSpace nullspace&nbsp;&nbsp;&nbsp; !&gt;neumann
                                  BC<br>
                                  <br>
                                  rho = 1.0<br>
                                  <br>
                                  i1 = 1<br>
                                  <br>
                                  i5 = 5<br>
                                  <br>
                                  centerRho = rho<br>
                                  <br>
                                  call
DMDAGetInfo(da,PETSC_NULL_INTEGER,mx,my,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,ierr)<br>
                                  <br>
                                  Hx = 1.d0 / (mx-1)<br>
                                  <br>
                                  Hy = 1.d0 / (my-1)<br>
                                  <br>
                                  HxdHy = Hx/Hy<br>
                                  <br>
                                  HydHx = Hy/Hx<br>
                                  <br>
                                  call
                                  DMDAGetCorners(da,xs,ys,PETSC_NULL_INTEGER,xm,ym,PETSC_NULL_INTEGER,ierr)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;




                                  <br>
                                  <br>
                                  do j=ys,ys+ym-1<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; do i=xs,xs+xm-1<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; row(MatStencil_i) = i&nbsp; <br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; row(MatStencil_j) = j<br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; call
                                  ComputeRho(i,j,mx,my,centerRho,rho)<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (i.eq.0 .or. j.eq.0 .or.
                                  i.eq.mx-1 .or. j.eq.my-1) then<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(1) = 2.0*rho*(HxdHy +
                                  HydHx)<br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; call
                                  MatSetValuesStencil(jac,i1,row,i1,row,v,INSERT_VALUES,ierr)<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else <br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(1) = -rho*HxdHy<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,1) = i<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,2) = j-1<br>
                                </div>
                              </blockquote>
                              <div><br>
                              </div>
                              <div>Cut and paste error above.</div>
                              <div><br>
                              </div>
                              <div>&nbsp; Matt</div>
                              <div>&nbsp;</div>
                              <blockquote class="gmail_quote"
                                style="margin:0 0 0 .8ex;border-left:1px
                                #ccc solid;padding-left:1ex">
                                <div bgcolor="#FFFFFF" text="#000000">
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(2) = -rho*HydHx<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,2) = i-1
                                  <br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,2) = j<br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(3) = 2.0*rho*(HxdHy +
                                  HydHx)<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,3) = i <br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,3) = j<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(4) = -rho*HydHx<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,4) = i+1
                                  <br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,4) = j <br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v(5) = -rho*HxdHy<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_i,5) = i <br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; col(MatStencil_j,5) = j+1<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; call
                                  MatSetValuesStencil(jac,i1,row,i5,col,v,INSERT_VALUES,ierr)<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end if<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; end do<br>
                                  <br>
                                  end do<br>
                                  <br>
                                  call
                                  MatAssemblyBegin(jac,MAT_FINAL_ASSEMBLY,ierr)<br>
                                  <br>
                                  call
                                  MatAssemblyEnd(jac,MAT_FINAL_ASSEMBLY,ierr)<br>
                                  <br>
                                  !call
MatNullSpaceCreate(PETSC_COMM_WORLD,PETSC_TRUE,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,nullspace,ierr)<br>
                                  <br>
                                  !call
                                  MatSetNullSpace(jac,nullspace,ierr)<br>
                                  <br>
                                  !call
                                  MatNullSpaceDestroy(nullspace,ierr)<br>
                                  <br>
                                  end subroutine ComputeMatrix<br>
                                  <br>
                                  subroutine
                                  ComputeRho(i,j,mx,my,centerRho,rho)<br>
                                  <br>
                                  PetscInt&nbsp;&nbsp;&nbsp; i,j,mx,my<br>
                                  <br>
                                  PetscScalar&nbsp; rho,centerRho<br>
                                  <br>
                                  if ((i &gt; mx/3.0) .and. (i &lt;
                                  2.0*mx/3.0) .and. (j &gt; my/3.0)
                                  .and. (j &lt; 2.0*my/3.0)) then<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; rho = centerRho<br>
                                  <br>
                                  else<br>
                                  <br>
                                  &nbsp;&nbsp;&nbsp; rho = 1.0<br>
                                  <br>
                                  end if<br>
                                  <br>
                                  <br>
                                  end subroutine ComputeRho<span><font
                                      color="#888888"><span><font
                                          color="#888888"><br>
                                          <pre cols="72">-- 
Yours sincerely,

TAY wee-beng</pre>
                                        </font></span></font></span></div>
                                <span><font color="#888888"> </font></span></blockquote>
                              <span><font color="#888888"> </font></span></div>
                            <span><font color="#888888"> <br>
                                <br clear="all">
                                <span class="HOEnZb"><font
                                    color="#888888">
                                    <div><br>
                                    </div>
                                    -- <br>
                                    What most experimenters take for
                                    granted before they begin their
                                    experiments is infinitely more
                                    interesting than any results to
                                    which their experiments lead.<br>
                                    -- Norbert Wiener<br>
                                  </font></span></font></span></div>
                          <span class="HOEnZb"><font color="#888888"> </font></span></blockquote>
                        <span class="HOEnZb"><font color="#888888"> </font></span></div>
                      <span class="HOEnZb"><font color="#888888"> </font></span></blockquote>
                    <span class="HOEnZb"><font color="#888888"> </font></span></div>
                  <span class="HOEnZb"><font color="#888888"> <br>
                      <br clear="all">
                      <div><br>
                      </div>
                      -- <br>
                      What most experimenters take for granted before
                      they begin their experiments is infinitely more
                      interesting than any results to which their
                      experiments lead.<br>
                      -- Norbert Wiener<br>
                    </font></span></div>
              </blockquote>
            </div>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <div><br>
        </div>
        -- <br>
        What most experimenters take for granted before they begin their
        experiments is infinitely more interesting than any results to
        which their experiments lead.<br>
        -- Norbert Wiener<br>
      </div>
    </blockquote>
  </body>
</html>