[petsc-users] question about contexts

Jed Brown jedbrown at mcs.anl.gov
Fri Sep 30 09:44:01 CDT 2011


On Fri, Sep 30, 2011 at 09:34, Dominik Szczerba <dominik at itis.ethz.ch>wrote:

> I am currently declaring functions outside my C++ solver class to be
> used by via MatShellSetOperation like:
>
> #undef __FUNCT__
> #define __FUNCT__ "StiffnessMatrixMultiplication"
> PetscErrorCode StiffnessMatrixMultiplication(Mat A, Vec x, Vec y)
> {
>        // ...
>        ierr = MatShellGetContext(A, (void**) &ctx);CHKERRQ(ierr);
>        Mat foo;
>        foo = ctx->foo;
>        // ...
> }
>
> and I set/get contexts to e.g. pass 'foo' around. Is it possible in
> Petsc / is it a good idea / to instead declare such functions as
> static class member functions and then use the class members directly
> without any contexts shuffled around?
>

You have to go through the context unless your class is a singleton. Or do
you still mean casting the ctx to your class type and accessing members
through it (explicit "this")? That should work, if you prefer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110930/5f12f4a0/attachment.htm>


More information about the petsc-users mailing list