[petsc-users] TSSetIFunction

Jin, Shuangshuang Shuangshuang.Jin at pnnl.gov
Wed Mar 20 18:18:16 CDT 2013


Thanks, I make the “IFunction” and “IJacobian” static in the header file and the mismatch goes away.

Another question is I know ex19.c is using real numbers only, if I run it alone, I should use arch-real to compile it successfully.
However, because my code has to do complex numbers computation somewhere else, I built the PETSc with an ARCH-complex. Now when I  integrate ex19.c into my code, I get the following compilation error:

[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 static member function ‘static PetscErrorCode Simulation::IFunction(_p_TS*, PetscReal, _p_Vec*, _p_Vec*, _p_Vec*, void*)’:
simulation.C:25: error: no match for ‘operator/’ in ‘std::operator* [with _Tp = double](((const std::complex<double>&)((const std::complex<double>*)(& std::operator* [with _Tp = double](((const std::complex<double>&)((const std::complex<double>*)(x + 16u))), ((const std::complex<double>&)((const std::complex<double>*)(x + 16u))))))), ((const std::complex<double>&)((const std::complex<double>*)(x + 16u)))) / 3’
make: *** [simulation.o] Error 1

I guess it is because of the complex number and real number mismatch. But I’m not sure if it’s the case.
simulation.C:25 corresponds to line  “f[1] = (x[1]*x[1]*x[1]/3 - x[1])-x[0];” in the code:

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);
}

Thanks,
Shuangshuang




From: petsc-users-bounces at mcs.anl.gov [mailto:petsc-users-bounces at mcs.anl.gov] On Behalf Of Jed Brown
Sent: Wednesday, March 20, 2013 2:52 PM
To: PETSc users list
Subject: Re: [petsc-users] TSSetIFunction

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<mailto: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/d8ca0d58/attachment-0001.html>


More information about the petsc-users mailing list