[petsc-users] question about contexts

Dominik Szczerba dominik at itis.ethz.ch
Sat Oct 1 12:28:34 CDT 2011


Jed and Vijay,

Yes, thanks, this works. I somehow did not realize I can pass 'this'
as the context.
However, it has a serious drawback, that all the members the
out-of-class function needs to access must be public. I guess I will
have to live with this for now, but if you have some ideas to somehow
make the function a "friend" of my class, I am all ears...

Many thanks,

Dominik

On Fri, Sep 30, 2011 at 7:33 PM, Vijay S. Mahadevan <vijay.m at gmail.com> wrote:
> You should be able to do this:
>
> #undef __FUNCT__
> #define __FUNCT__ "StiffnessMatrixMultiplication"
> PetscErrorCode StiffnessMatrixMultiplication(Mat A, Vec x, Vec y)
> {
>       MyClass* ctx ;
>       // ...
>       ierr = MatShellGetContext(A, (void**) &ctx);CHKERRQ(ierr);
>       Mat foo;
>       foo = ctx->foo; // non-static public member of MyClass that is
> of type Mat
>       // ...
>       Mat bar;
>       bar = MyClass::bar; // static member of MyClass that is of type Mat
>       // ...
>       Mat foobar;
>       foobar = MyClass::foobar(); // static member function of
> MyClass that returns a Mat
>       // ...
> }
>
> And similarly for the PCShellApply, you can get the context MyClass
> from the PC instance. I don't see what problems you have with this
> use-case.
>
> Look at SampleShellPCApply in
> http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/src/ksp/ksp/examples/tutorials/ex15.c.html
> for a similar usage.
>
> On Fri, Sep 30, 2011 at 12:28 PM, Dominik Szczerba <dominik at itis.ethz.ch> wrote:
>>> But the method is like a "friend" in the sense that it can access members through an explicit pointer.
>>
>> Can you please expand a bit on this one? What is an explicit pointer?
>>
>> Dominik
>>
>
>


More information about the petsc-users mailing list