<div dir="ltr">Hi All,<div><br></div><div>I wonder if there is a good example on how PETSc should work with mesh refinement. I have done some online search/PETSc-user email search, but did not find a good one.</div><div><br></div><div>Here is my case. Currently, assuming NO mesh refinement (so I know exactly the problem size, mesh connectivity, non-zero pattern of matrices, etc.)</div><div>In a transient simulation, my PETSc code looks like:</div><div><br></div><div>========================================================================</div><div>SetupVectors(); // unknown vec, old unknown, etc.</div><div>SetupResFunc(); // residual function, basically pointing to the discretized PDE</div><div>SetupMatrices(); // allocate memory for preconditioning matrix based on non-zero pattern (so it is mesh dependent)</div><div>                           // I also use finite differencing to get preconditioning matrix, so there is another MatFDColoring object associated with the matrix</div><div>for (int step = 0; step < max_step; step++)</div><div>{</div><div>  SNESSolve();</div><div>}</div><div>========================================================================<br></div><div><br></div><div>This setup works perfectly for my problems.</div><div>(I understand it is low efficient to use FD to get the preconditioning matrix, but it is not a priority to me at this moment).</div><div><br></div><div>However, now I would like to do some mesh refinement, so the previous setup would not work, because the problem size, non-zero pattern of the matrix and MatFDColoring change with mesh size (and connectivity).</div><div>I suppose my code should be changed like this:</div><div><br></div><div>========================================================================<br></div><div><div><div>SetupVectors();</div><div>SetupResFunc();</div><div>SetupMatrices();</div></div></div><div><br></div><div><div>for (int step = 0; step < max_step; step++)</div><div>{</div><div>  MeshRefinement(); // I will manage my mesh</div><div><br></div><div><div>  AdjustVectors();   // resize vector</div><div>  AdjustMatrices(); // resize matrix, re-allocate memory, adjust non-zero pattern, etc.</div></div><div><br></div><div>  SNESSolve();</div><div>}</div></div><div>========================================================================<br></div><div><br></div><div>The issue is that I understand one should not re-allocate memory to both PETSc vector and matrix dynamically during simulation, which has been discussed here:</div><div><a href="https://scicomp.stackexchange.com/questions/373/is-it-possible-to-dynamically-resize-a-sparse-matrix-in-the-petsc-library">https://scicomp.stackexchange.com/questions/373/is-it-possible-to-dynamically-resize-a-sparse-matrix-in-the-petsc-library</a><br></div><div><br></div><div>So, the final questions are:</div><div>1) Any good example on PETSc working with mesh refinement?</div><div>2) Any suggestion on my proposed code structure?</div><div><br></div><div>Best,</div><div><br></div><div>Ling</div><div><br></div><div><br></div></div>