[petsc-users] pass a member function to MatShellSetOperation

Matthew Knepley knepley at gmail.com
Thu Sep 30 06:22:20 CDT 2021


That is the new way to do it. The other way to do it is to have it be a
static member function, so that it does not take "this".

  Thanks,

     Matt

On Thu, Sep 30, 2021 at 6:11 AM Praveen C <praveen at gmx.net> wrote:

> I have used something like this in similar situation
>
> auto MatMult = [this](…args…)
> {
>    this->MyMatMult(…args…);
> };
>
>
> Then pass MatMult to petsc.
>
> *this* refers to the class Global_Assem and we are assuming you are
> inside this class when doing the above.
>
> best
> praveen
>
> On 30-Sep-2021, at 3:25 PM, Michael Wick <michael.wick.1980 at gmail.com>
> wrote:
>
> Hi:
>
> I want to have the shell matrix-vector multiplication written as a class
> member function and pass it to the shell matrix via MatShellSetOperation.
>
> MatShellSetOperation(A, MATOP_MULT, (void
> (*)(void))(&Global_Assem::MyMatMult));
>
> Perhaps I have a wrong understanding of function pointers, and I am
> constantly getting warnings that say I cannot convert a member function to
> a void type. The warning indeed makes sense to me, as the function pointer
> passed in the above manner is independent of an instance. Perhaps there are
> other ways of passing a member function that I don't know of. If you know
> how to address this, I would appreciate it a lot!
>
> Thanks,
>
> Mike
>
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20210930/6d169d75/attachment.html>


More information about the petsc-users mailing list