[petsc-users] question about contexts

Dominik Szczerba dominik at itis.ethz.ch
Fri Sep 30 12:09:20 CDT 2011


After educating myself in a long googling session on C++ member
function pointers I find that PCShellSetApply would simply only accept
C-style static functions (error: argument of type ‘PetscErrorCode
(FluidSolver::)(_p_PC*, _p_Vec*, _p_Vec*)’ does not match
‘PetscErrorCode (*)(_p_PC*, _p_Vec*, _p_Vec*)’), so my approach
unfortunately is not feasible, what a pity. Please notify me if I am
wrong, it is a fundamental issue for my design.

Dominik

On Fri, Sep 30, 2011 at 6:21 PM, 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.
>>
>


More information about the petsc-users mailing list