<div class="gmail_extra">On Thu, Apr 26, 2012 at 3:26 PM, TAY wee-beng <span dir="ltr">&lt;<a 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>
    Thanks for pointing out my mistake. I&#39;m still learning about the
    code. I corrected but I still get the error:<br></div></blockquote><div><br></div><div>I am sure its another simple bug. Go in with the debugger. When it says you are inserting a new nonzero,</div><div>back up the stack to your routine and see what indices you are tying to insert. If its not part of the stencil,</div>
<div>you have found the bug.</div><div><br></div><div>  Matt</div><div> </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: --------------------- 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>
                    if (j/=0) then<br>
                    <br>
                        v(num) = -rho*HxdHy<br>
    <br>
                        col(MatStencil_i,num) = i<br>
    <br>
                        col(MatStencil_j,num) = j-1<br>
    <br>
                        num = num + 1<br>
    <br>
                    end if<br>
    <br>
                    if (i/=0) then<br>
                    <br>
                        v(num) = -rho*HydHx<br>
    <br>
                        col(MatStencil_i,num) = i-1<br>
    <br>
                        col(MatStencil_j,num) = j<br>
    <br>
                        num = num + 1<br>
    <br>
                    end if<br>
    <br>
                    if (i/=mx-1) then<br>
                    <br>
                        v(num) = -rho*HydHx<br>
    <br>
                        col(MatStencil_i,num) = i+1<br>
    <br>
                        col(MatStencil_j,num) = j<br>
    <br>
                        num = num + 1<br>
    <br>
                    end if<br>
    <br>
                    if (j/=my-1) then<br>
                    <br>
                        v(num) = -rho*HxdHy<br>
    <br>
                        col(MatStencil_i,num) = i<br>
    <br>
                        col(MatStencil_j,num) = j+1<br>
    <br>
                        num = num + 1<br>
    <br>
                    end if<br>
                    <br>
                    v(num) = (num/2.0)*rho*(HxdHy + HydHx)<br>
    <br>
                    col(MatStencil_i,num) = i<br>
    <br>
                    col(MatStencil_j,num) = j+1<br>
    <br>
                    num = num + 1<br>
                <br>
                    call
    MatSetValuesStencil(jac,i1,row,num,col,v,INSERT_VALUES,ierr)<br>
    <pre cols="72">Yours sincerely,

TAY wee-beng</pre>
    <br>
    On 26/4/2012 2:45 PM, Matthew Knepley wrote:
    <blockquote type="cite">
      <div class="gmail_extra">On Thu, Apr 26, 2012 at 8:27 AM, TAY
        wee-beng <span dir="ltr">&lt;<a 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>
               I still can&#39;t get it working.<br>
              <br>
              Thanks.<br>
              <br>
              <br>
              Hi,<br>
              <br>
              There&#39;s no error now but I didn&#39;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>
                        num = 0;<br>
                        if (j!=0) {<br>
                          v[num] = -rho*HxdHy;              col[num].i =
              i;   col[num].j = j-1;<br>
            </div>
          </blockquote>
          <div>                                                         
                    ^^^ See this? </div>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000">             num++;<br>
                        }<br>
                        if (i!=0) {<br>
                          v[num] = -rho*HydHx;              col[num].i =
              i-1; col[num].j = j;<br>
                          num++;<br>
                        }<br>
                        if (i!=mx-1) {<br>
                          v[num] = -rho*HydHx;              col[num].i =
              i+1; col[num].j = j;<br>
                          num++;<br>
                        }<br>
                        if (j!=my-1) {<br>
                          v[num] = -rho*HxdHy;              col[num].i =
              i;   col[num].j = j+1;<br>
                          num++;<br>
                        }<br>
                        v[num]   = (num/2.0)*rho*(HxdHy + HydHx);
              col[num].i = i;   col[num].j = j;<br>
                        num++;<br>
                        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>
                              num = 1<br>
              <br>
                              if (j/=0) then<br>
                              <br>
                                  v(num) = -rho*HxdHy<br>
              <br>
                                  col(MatStencil_i,1) = i<br>
            </div>
          </blockquote>
          <div>                                               ^^ Why is
            this 1 in stead of &#39;num&#39;? </div>
          <div><br>
          </div>
          <div>   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">                    
              col(MatStencil_j,2) = j-1<br>
              <br>
                                  num = num + 1<br>
              <br>
                              end if<br>
              <br>
                              if (i/=0) then<br>
                              <br>
                                  v(num) = -rho*HydHx<br>
              <br>
                                  col(MatStencil_i,1) = i-1<br>
              <br>
                                  col(MatStencil_j,2) = j<br>
              <br>
                                  num = num + 1<br>
              <br>
                              end if<br>
              <br>
                              if (i/=mx-1) then<br>
                              <br>
                                  v(num) = -rho*HydHx<br>
              <br>
                                  col(MatStencil_i,1) = i+1<br>
              <br>
                                  col(MatStencil_j,2) = j<br>
              <br>
                                  num = num + 1<br>
              <br>
                              end if<br>
              <br>
                              if (j/=my-1) then<br>
                              <br>
                                  v(num) = -rho*HxdHy<br>
              <br>
                                  col(MatStencil_i,1) = i<br>
              <br>
                                  col(MatStencil_j,2) = j+1<br>
              <br>
                                  num = num + 1<br>
              <br>
                              end if<br>
                              <br>
                              v(num) = (num/2.0)*rho*(HxdHy + HydHx)<br>
              <br>
                              col(MatStencil_i,1) = i<br>
              <br>
                              col(MatStencil_j,2) = j+1<br>
              <br>
                              num = num + 1<br>
                          <br>
                              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 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>  Matt</div>
                    <div> </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  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>
                         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=&quot;win32fe cl&quot; --with-fc=&quot;win32fe ifor<br>
                        t&quot; --with-cxx=&quot;win32fe cl&quot;
                        --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 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&#39;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  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>
                                   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=&quot;win32fe cl&quot;
                                  --with-fc=&quot;win32fe ifor<br>
                                  t&quot; --with-cxx=&quot;win32fe cl&quot;
                                  --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 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  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>
                                   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=&quot;win32fe cl&quot;
                                  --with-fc=&quot;win32fe ifor<br>
                                  t&quot; --with-cxx=&quot;win32fe cl&quot;
                                  --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  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>
                                   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=&quot;win32fe cl&quot;
                                  --with-fc=&quot;win32fe ifor<br>
                                  t&quot; --with-cxx=&quot;win32fe cl&quot;
                                  --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 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  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>
                                   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=&quot;win32fe cl&quot;
                                  --with-fc=&quot;win32fe ifor<br>
                                  t&quot; --with-cxx=&quot;win32fe cl&quot;
                                  --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  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>
                                   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=&quot;win32fe cl&quot;
                                  --with-fc=&quot;win32fe ifor<br>
                                  t&quot; --with-cxx=&quot;win32fe cl&quot;
                                  --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>
                                    type: mpi<br>
                                  Process [0]<br>
                                  <br>
                                  What&#39;s wrong?<br>
                                  <br>
                                  <br>
                                  <b>program ex29f</b><br>
                                  <br>
                                  implicit none<br>
                                  <br>
                                  ! - - - - - - - - - - - - - - - - - -
                                  - - - - - - - - - - - - - - - - - -<br>
                                  !                    Include files<br>
                                  ! - - - - - - - - - - - - - - - - - -
                                  - - - - - - - - - - - - - - - - - -<br>
                                  !<br>
                                  !     petscsys.h  - base PETSc
                                  routines      petscvec.h - vectors<br>
                                  !     petscmat.h - matrices<br>
                                  !     petscksp.h    - Krylov subspace
                                  methods  petscpc.h  - preconditioners<br>
                                  <br>
                                  #include &quot;finclude/petsc.h90&quot;<br>
                                  <br>
                                  PetscErrorCode   ierr<br>
                                  <br>
                                  DM               da<br>
                                  <br>
                                  KSP              ksp<br>
                                  <br>
                                  Vec              x<br>
                                  <br>
                                  external        
                                  ComputeRHS,ComputeMatrix<br>
                                  <br>
                                  PetscInt i1,i3<br>
                                  <br>
                                  call 
                                  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)  
                                  <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 &quot;finclude/petsc.h90&quot;<br>
                                  <br>
                                  PetscErrorCode  ierr<br>
                                  PetscInt i,j,mx,my,xm,ym,xs,ys<br>
                                  PetscScalar  h,nu,rho<br>
                                  PetscScalar Hx,Hy<br>
                                  PetscScalar,pointer :: array(:,:)<br>
                                  Vec          x,b<br>
                                  DM           da<br>
                                  MatNullSpace nullspace    !&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>
                                      do i = xs,xs+xm-1<br>
                                  <br>
                                          array(i,j) =
                                  exp(-(i*Hx)*(i*Hx)/nu)*exp(-(j*Hy)*(j*Hy)/nu)*Hx*Hy<br>
                                  <br>
                                      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>   Matt</div>
                              <div> </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 &quot;finclude/petsc.h90&quot;<br>
                                  <br>
                                  Mat          jac,JJ<br>
                                  <br>
                                  PetscErrorCode    ierr<br>
                                  <br>
                                  DM           da<br>
                                  <br>
                                  PetscInt    i,j,k,mx,my,xm<br>
                                  <br>
                                  PetscInt    ym,xs,ys,i1,i5<br>
                                  <br>
                                  PetscScalar  v(5),Hx,Hy,rho,centerRho<br>
                                  <br>
                                  PetscScalar  HydHx<br>
                                  <br>
                                  PetscScalar  HxdHy<br>
                                  <br>
                                  MatStencil   row(4),col(4,5)<br>
                                  <br>
                                  Vec          x<br>
                                  <br>
                                  MatStructure str<br>
                                  <br>
                                  MatNullSpace nullspace    !&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)       




                                  <br>
                                  <br>
                                  do j=ys,ys+ym-1<br>
                                  <br>
                                      do i=xs,xs+xm-1<br>
                                  <br>
                                          row(MatStencil_i) = i  <br>
                                  <br>
                                          row(MatStencil_j) = j<br>
                                          <br>
                                          call
                                  ComputeRho(i,j,mx,my,centerRho,rho)<br>
                                  <br>
                                          if (i.eq.0 .or. j.eq.0 .or.
                                  i.eq.mx-1 .or. j.eq.my-1) then<br>
                                  <br>
                                              v(1) = 2.0*rho*(HxdHy +
                                  HydHx)<br>
                                              <br>
                                              call
                                  MatSetValuesStencil(jac,i1,row,i1,row,v,INSERT_VALUES,ierr)<br>
                                  <br>
                                          else <br>
                                  <br>
                                              v(1) = -rho*HxdHy<br>
                                  <br>
                                              col(MatStencil_i,1) = i<br>
                                  <br>
                                              col(MatStencil_j,2) = j-1<br>
                                </div>
                              </blockquote>
                              <div><br>
                              </div>
                              <div>Cut and paste error above.</div>
                              <div><br>
                              </div>
                              <div>  Matt</div>
                              <div> </div>
                              <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                                <div bgcolor="#FFFFFF" text="#000000">
                                              v(2) = -rho*HydHx<br>
                                  <br>
                                              col(MatStencil_i,2) = i-1
                                  <br>
                                  <br>
                                              col(MatStencil_j,2) = j<br>
                                              <br>
                                              v(3) = 2.0*rho*(HxdHy +
                                  HydHx)<br>
                                  <br>
                                              col(MatStencil_i,3) = i <br>
                                  <br>
                                              col(MatStencil_j,3) = j<br>
                                  <br>
                                              v(4) = -rho*HydHx<br>
                                  <br>
                                              col(MatStencil_i,4) = i+1
                                  <br>
                                  <br>
                                              col(MatStencil_j,4) = j <br>
                                  <br>
                                              v(5) = -rho*HxdHy<br>
                                  <br>
                                              col(MatStencil_i,5) = i <br>
                                  <br>
                                              col(MatStencil_j,5) = j+1<br>
                                  <br>
                                              call
                                  MatSetValuesStencil(jac,i1,row,i5,col,v,INSERT_VALUES,ierr)<br>
                                  <br>
                                          end if<br>
                                  <br>
                                      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    i,j,mx,my<br>
                                  <br>
                                  PetscScalar  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>
                                      rho = centerRho<br>
                                  <br>
                                  else<br>
                                  <br>
                                      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><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><font color="#888888"> </font></span></blockquote>
                        <span><font color="#888888"> </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>