[petsc-users] TSSetIFunction

Jed Brown jedbrown at mcs.anl.gov
Wed Mar 20 16:52:00 CDT 2013


You cannot use a member function as a callback. You can (with almost all
compilers) use a _static_ member function. Note that static member
functions do not have a "this" pointer. The void* argument in the callback
should be set to the class so that you can use it as a "this" pointer.


On Wed, Mar 20, 2013 at 4:47 PM, Jin, Shuangshuang <
Shuangshuang.Jin at pnnl.gov> wrote:

>  Hi, I use src\ts\examples\tutorials\ex19.c as an example to use PETSc
> DAE solver. I get the following problem while running my code:
>
> [d3m956 at olympus ss00]$ make
> mpicxx -I/pic/projects/ds/petsc-dev/include
> -I/pic/projects/ds/petsc-dev/arch-complex/include
> -I/share/apps/openmpi/1.5.4/gcc/4.1.2/include -g -c -o simulation.o
> simulation.C
> simulation.C: In member function ‘PetscErrorCode
> Simulation::simu(_p_Mat*, _p_Mat*, _p_Mat*)’:
> simulation.C:80: error: argument of type ‘PetscErrorCode
> (Simulation::)(_p_TS*, PetscReal, _p_Vec*, _p_Vec*, _p_Vec*, void*)’ does
> not match ‘PetscErrorCode (*)(_p_TS*, PetscReal, _p_Vec*, _p_Vec*,
> _p_Vec*, void*)’
> make: *** [simulation.o] Error 1
>
> What does it mean?
>
> The IFunction is copied from ex19.c,
>
> PetscErrorCode Simulation::IFunction(TS ts,PetscReal t,Vec X,Vec Xdot,Vec
> F,void *ctx)
> {
>   PetscErrorCode ierr;
>   PetscScalar *x,*xdot,*f;
>
>   PetscFunctionBegin;
>   ierr = VecGetArray(X,&x);CHKERRQ(ierr);
>   ierr = VecGetArray(Xdot,&xdot);CHKERRQ(ierr);
>   ierr = VecGetArray(F,&f);CHKERRQ(ierr);
>   f[0] = xdot[0] + x[1];
>   f[1] = (x[1]*x[1]*x[1]/3 - x[1])-x[0];
>   ierr = VecRestoreArray(X,&x);CHKERRQ(ierr);
>   ierr = VecRestoreArray(Xdot,&xdot);CHKERRQ(ierr);
>   ierr = VecRestoreArray(F,&f);CHKERRQ(ierr);
>   PetscFunctionReturn(0);
> }
>
> And in Simulation::simu(Mat f1, Mat f2, Mat f3), I have:
>
> ierr = TSSetIFunction(ts,NULL,IFunction,&user);CHKERRQ(ierr);
>
> Thanks,
> Shuangshuang
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130320/1e91b116/attachment.html>


More information about the petsc-users mailing list