<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Dec 28, 2017 at 11:34 AM, Franck Houssen <span dir="ltr"><<a href="mailto:franck.houssen@inria.fr" target="_blank">franck.houssen@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">----- Mail original -----<br>
> De: "Barry F. Smith" <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>><br>
> À: "Franck Houssen" <<a href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>><br>
> Cc: "For users of the development version of PETSc" <<a href="mailto:petsc-dev@mcs.anl.gov">petsc-dev@mcs.anl.gov</a>><br>
> Envoyé: Jeudi 28 Décembre 2017 16:43:16<br>
> Objet: Re: [petsc-dev] How to pass user data to a registered PC (PCRegister) ?<br>
<span class="gmail-">><br>
><br>
>    The register is for a new type of PC of which can have many instantiations<br>
>    at the same time.<br>
<br>
</span>OK, I didn't get that that way ! I was looking for a way to plug "my" pc at the command line this way: -pc_type my_pc.<br>
I already call PCSetType(pc, PCSHELL) and PCShellSetName(pc, "my_pc"): maybe this already enables "-pc_type shell" or "-pc_type my_pc"... And I didn't know it ! :D I'll try that.<br>
<br>
I was looking for a way to integrate "my" (external) pc as any other regular/existing petsc pc (bjacobi, ...) like a kind of plugin but still integrated to the cmd line: I believed PCRegister was meant for that.<br>
Not sure if this is actually possible/enabled by the API.</blockquote><div><br></div><div>Yes, this is how PCRegister works. Barry is also right that you would put your information directly in the impl struct for my_pc. Then you write a specific interface</div><div>function for that data, e,g, PCJacobiSetUseAbs(). Here is our canonical example:</div><div><br></div><div>  <a href="https://bitbucket.org/petsc/petsc/src/4de00746c5d9ba3d09a7cdd5c64a5cab5c60cbfa/src/ksp/pc/impls/jacobi/jacobi.c?at=master&fileviewer=file-view-default">https://bitbucket.org/petsc/petsc/src/4de00746c5d9ba3d09a7cdd5c64a5cab5c60cbfa/src/ksp/pc/impls/jacobi/jacobi.c?at=master&fileviewer=file-view-default</a></div><div><br></div><div>There is a bunch of documentation at the top of that file.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">
> For example<br>
><br>
>     PCRegister("mypctype",mypc_<wbr>create);<br>
><br>
>     KSPCreate(&ksp1);<br>
>     KSPCreate(&ksp2);<br>
><br>
>     KSPGetPC(ksp1,&pc1);<br>
>     KSPGetPC(ksp2,&pc2);<br>
><br>
>     You don't want pc1 and pc2 to have the same dof multiplicities, domain<br>
>     intersections etc since they are associated with completely different<br>
>     linear systems and presumably meshes etc.<br>
><br>
><br>
>      Presumably you want each of pc1, pc2, to have their own version of the<br>
>      data so you need to stick it directly in the PC, for example<br>
><br>
>    PCMypcSetDOFMultiplicities(<wbr>pc1,stuff);<br>
>   PCMypcSetDOFMultiplicities(<wbr>pc2,otherstuff);<br>
><br>
> You write as many of these Set() functions as you need for your PCtype. You<br>
> store the data inside the PC_Mypc data structure you create with<br>
> mypc_create(). Look at PCCreate_Jacobi() and PCJacobiSetType for the<br>
> pattern.<br>
><br>
>    Barry<br>
><br>
><br>
> > On Dec 28, 2017, at 9:34 AM, Franck Houssen <<a href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>><br>
> > wrote:<br>
> ><br>
> > How to pass user data to a registered PC (PCRegister) ?<br>
> ><br>
> > At first, I expected the signature would be "PetscErrorCode<br>
> > PCRegister(const char sname[],PetscErrorCode (*function)(PC, void *))" but<br>
> > it turns out to be "PetscErrorCode PCRegister(const char<br>
> > sname[],PetscErrorCode (*function)(PC))"<br>
> ><br>
> > I try to integrate a PC that needs A but also other informations (dof<br>
> > multiplicities, domain intersections that the user must provide). I guess<br>
> > I can get A with PCGetOperators in the setup callback of the PC. But still<br>
> > not sure how to pass the other informations if I get to use PCRegister. I<br>
> > looked a few examples in the bitbucket (jacobi:<br>
> > src/ksp/ksp/examples/<wbr>tutorials/ex12.c and src/ksp/pc/impls/jacobi/<wbr>jacobi.c<br>
> > + SOR: src/ksp/pc/impls/sor/sor.c)... But didn't get any real relevant<br>
> > answer and feel a bit lost among the numerous pc !...<br>
> ><br>
> > The idea is: for now I use PCSetType(pc, PCSHELL) and PCShellSetContext<br>
> > with a context who knows the extra needed informations which is "not so<br>
> > handy" (that's OK as for now I am both the user and the PC provider). I'd<br>
> > like to package this in a more convenient way (a unique and "simple" call<br>
> > to PCRegister) to decouple the user from the PC machinery.<br>
> ><br>
> > Franck<br>
><br>
><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>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</div><div><br></div><div><a href="http://www.caam.rice.edu/~mk51/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div>
</div></div>