On 29. aug. 2014 19:03, Barry Smith wrote: > > > On Aug 29, 2014, at 9:35 AM, Åsmund Ervik <[email protected]> wrote: > >>> On 28. aug. 2014 20:52, Barry Smith wrote: >>>> >>>> On Aug 28, 2014, at 4:34 AM, Åsmund Ervik <[email protected]> wrote: >>>> >>>>> Hello, >>>>> >>>>> I am solving a pressure Poisson equation with KSP, where the initial >>>>> guess, RHS and matrix are computed by functions that I've hooked into >>>>> KSPSetComputeXXX. (I'm also using DMDA for my domain decomposition.) >>>>> >>>>> For (single-phase|two-phase) I would like to (reuse|not reuse) the >>>>> preconditioner. How do I specify that when using this way of setting the >>>>> operator? Is it toggled by whether or not I call KSPSetOperators before >>>>> each KSPSolve? (The manual does not mention KSPSetComputeXXX.) >>>> >>>> You should call KSPSetOperators() before each KSPSolve() (otherwise the >>>> function you provide to compute the matrix won’t be triggered). >>>> >>>> With PETSc 3.5 after the call to KSPSetOperators() call >>>> KSPSetReusePreconditioner() to tell KSP wether to reuse the preconditioner >>>> or build a new one. >>>> With PETSc 3.4 and earlier, the final argument to KSPSetOperators() >>>> would be MAT_SAME_PRECONDITIONER to reuse the preconditioner or >>>> MAT_SAME_NONZERO_PATTERN to construct a new preconditioner >>>> >> >> Thanks Barry for the clarification. Is there an example somewhere that >> does this? All the ones I can find which use KSPSetComputeOperators() >> have no calls to KSPSetOperators(). I guess this is because they are >> only doing one linear solve? >> >> Furthermore, what should I pass in for Amat and Pmat to the >> KSPSetOperators() call? PetscNullObject, or do I get the Amat from the KSP >> somehow? > > You better call KSPGetOperators() to get them. Yes this is kind of silly.
Okay, thanks. I found I also have to call MatSetFromOptions() on Amat and Pmat after I get them from KSPGetOperators(), otherwise KSPSetOperators() complains that "Object is in the wrong state! Mat object's type is not set!" This is indeed a strange sequence of calls. If this is the "standard" way of doing like ksp/ex34.c but for several successive solves, then it would be nice to have a comment/instruction in ex34.c for that case. Åsmund
signature.asc
Description: OpenPGP digital signature
