[petsc-users] question about contexts

Jed Brown jedbrown at mcs.anl.gov
Fri Sep 30 12:23:54 CDT 2011


You should understand what it means to he a static member function of a
class. There is no object, you can only access static members which are just
namespaced globals. But the method is like a "friend" in the sense that it
can access members through an explicit pointer.
On Sep 30, 2011 11:22 AM, "Dominik Szczerba" <dominik at itis.ethz.ch> wrote:
> It does not seem to work, unless I just miss some C/C++ idiom.
> I was wrong, StiffnessMatrixMultiplication can not be static member,
> else all the other non-static members are inaccessible.
> So I am trying non-static, but can not pray PCShellSetApply work with
> such a function, always get some syntax error.
>
> Any hints are highly appreciated.
>
> Dominik
>
>
>
> On Fri, Sep 30, 2011 at 5:54 PM, Dominik Szczerba <dominik at itis.ethz.ch>
wrote:
>> Yes, I only have one instance of my solver class, if this is what you
>> mean by a singleton.
>> I did not mean to cast my context, I meant to avoid any contexts and
>> just access the members. I so far use the context only to pass KSP,
>> Mat and Vec objects around a few functions. I am asking, because I
>> have not seen anyone doing it, while it appears natural to me. Also, I
>> am doubting if #define __FUNCT__ "StiffnessMatrixMultiplication" will
>> continue to work for static functions.
>>
>> Thanks,
>> Dominik
>>
>> On Fri, Sep 30, 2011 at 4:44 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
>>> 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/1170ae42/attachment.htm>


More information about the petsc-users mailing list