Xiangdong <[email protected]> writes: > I have a question about using KSPSetComputeOperator with user provided > function ComputeMatrix(). > > In order to use multigrid, this function ComputeMatrix() should be able to > generate the matrix for any grid level. However, the matrix I am trying to > generate depending on a vector u (the solution at previous time step). It > is okay for ComputeMatrix at finest level, because I have the vector u at > the finest level. However, if the ComputeMatrix tries to compute the matrix > at a coarse level, I do not have the vector u at the coarse level. Then I > see some error messages about nonconfirming sizes. Should I manually > restrict the vector u at a coarse level or petsc has some functions on this? > > In other words, there is a vector u in ctx struct passing to the > ComputeMatrix at finest level, how can I interpolate/restrict it to the > correct grid level for multigrid applications?
I encourage you to use TS because it can manage this for you, but if you want to manage it yourself, use DMCoarsenHookAdd to set callbacks that are called as the coarse grids are constructed and set up and PCMG. Use DMGetNamedGlobalVector to store your coarsened state and access it from your compute matrix function. See the TS implementations if you want an example to follow.
pgpyj1RYrl7DW.pgp
Description: PGP signature
