<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 3, 2014 at 12:35 PM, Jed Brown <span dir="ltr"><<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">Xiangdong <<a href="mailto:epscodes@gmail.com">epscodes@gmail.com</a>> writes:<br>
<br>
> I have a question about using KSPSetComputeOperator with user provided<br>
> function ComputeMatrix().<br>
><br>
> In order to use multigrid, this function ComputeMatrix() should be able to<br>
> generate the matrix for any grid level. However, the matrix I am trying to<br>
> generate depending on a vector u (the solution at previous time step). It<br>
> is okay for ComputeMatrix at finest level, because I have the vector u at<br>
> the finest level. However, if the ComputeMatrix tries to compute the matrix<br>
> at a coarse level, I do not have the vector u at the coarse level. Then I<br>
> see some error messages about nonconfirming sizes. Should I manually<br>
> restrict the vector u at a coarse level or petsc has some functions on this?<br>
><br>
> In other words, there is a vector u in ctx struct passing to the<br>
> ComputeMatrix at finest level, how can I interpolate/restrict it to the<br>
> correct grid level for multigrid applications?<br>
<br>
</div>I encourage you to use TS because it can manage this for you, but if you<br>
want to manage it yourself, use DMCoarsenHookAdd to set callbacks that<br>
are called as the coarse grids are constructed and set up and PCMG. Use<br>
DMGetNamedGlobalVector to store your coarsened state and access it from<br>
your compute matrix function. See the TS implementations if you want an<br>
example to follow.<br></blockquote><div><br></div><div><br></div><div>Could you please expand it a little more on using DMCoarsenHookAdd to restrict a fine vector on a coarse grid? The only example I can find is ex48 in snes. It is not clear how the coarsen vector are generated from that example.</div>
<div><br></div><div>thank you.</div><div><br></div><div>Xiangdong </div></div><br></div></div>