As a test, I changed the line ? f[1] = (x[1]*x[1]*x[1]/3 - x[1])-x[0];? to
?f[1] = (PetscRealPart(x[1])*PetscRealPart(x[1])*PetscRealPart(x[1])/3 -
PetscRealPart(x[1]))-PetscRealPart(x[0]);?, and it runs with the same results
as I run ex19.c alone.
However, I don?t understand why I only need to change this line but leave
nothing else such as the line before it ?f[0] = xdot[0] + x[1];? unchanged?
And can anyone please tell me in ex19.c what does this part of code do?
PetscErrorCode ierr;
PetscFunctionBegin;
{
const PetscReal
A[3][3] = {{0,0,0},
{0.41421356237309504880,0,0},
{0.75,0.25,0}},
At[3][3] = {{0,0,0},
{0.12132034355964257320,0.29289321881345247560,0},
{0.20710678118654752440,0.50000000000000000000,0.29289321881345247560}};
ierr =
TSARKIMEXRegister("myark2",2,3,&At[0][0],PETSC_NULL,PETSC_NULL,&A[0][0],PETSC_NULL,PETSC_NULL,PETSC_NULL,PETSC_NULL,0,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
It seems to me an initialization of the A matrix. But I looked into
TSARKIMEXRegister, still couldn?t understand how it works.
Thanks,
Shuangshuang
From: petsc-users-bounces at mcs.anl.gov
[mailto:[email protected]] On Behalf Of Jin, Shuangshuang
Sent: Wednesday, March 20, 2013 4:18 PM
To: PETSc users list
Subject: Re: [petsc-users] TSSetIFunction
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> [mailto:[email protected]] 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/6c7d41a7/attachment.html>