[petsc-users] passing information to TSIFunction

Sanjay Kharche Sanjay.Kharche at manchester.ac.uk
Wed Feb 4 14:59:20 CST 2015


Hi

I started with the ex15.c example from ts. Now I would like to pass a 2D int array I call data2d to the FormIFunction which constructs the udot - RHS. FormIFunction is used in Petsc's TSSetIFunction. My data2d is determined at run time in the initialisation on each rank. data2d is the same size as the solution array and the residual array.

I tried adding a Vec to FormIFunction, but Petsc's TSIFunction (    TSSetIFunction(ts,r,FormIFunction,&user);  ) expects a set number & type of arguments to FormIFunction. I tried passing data2d as a regular int pointer as well as a Vec. As a Vec, I tried to access the data2d in a similar way as the solution vector, which caused the serial and parallel execution to produce errors. 

Any ideas on how I can get an array of ints to FormIFunction?

thanks
Sanjay


The function declaration:
// petsc functions.
extern PetscInt FormIFunction(TS,PetscReal,Vec,Vec,Vec,void*, Vec); // last Vec is supposed to be my data2D, which is a duplicate of the u.

I duplicate as follows:
   DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,usr_MX,usr_MY,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&da); 
   user.da = da;
   DMCreateGlobalVector(da,&u); 
   VecDuplicate(u,&r); 
   VecDuplicate(u,&Data2D);  // so my assumption is that data2D is part of da, but I cannot see/set its type anywhere

The warnings/notes at build time:

> make sk2d
/home/sanjay/petsc/linux-gnu-c-debug/bin/mpicc -o sk2d.o -c -fPIC -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -g3 -O0   -I/home/sanjay/petsc/include -I/home/sanjay/petsc/linux-gnu-c-debug/include    `pwd`/sk2d.c
/home/sanjay/petscProgs/Work/twod/sk2d.c: In function ‘main’:
/home/sanjay/petscProgs/Work/twod/sk2d.c:228:4: warning: passing argument 3 of ‘TSSetIFunction’ from incompatible pointer type [enabled by default]
/home/sanjay/petsc/include/petscts.h:261:29: note: expected ‘TSIFunction’ but argument is of type ‘PetscInt (*)(struct _p_TS *, PetscReal,  struct _p_Vec *, struct _p_Vec *, struct _p_Vec *, void *, struct _p_Vec *)’



More information about the petsc-users mailing list