[petsc-users] passing information to TSIFunction

Matthew Knepley knepley at gmail.com
Wed Feb 4 15:03:09 CST 2015


On Wed, Feb 4, 2015 at 2:59 PM, Sanjay Kharche <
Sanjay.Kharche at manchester.ac.uk> wrote:

>
> 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.
>

1) This is auxiliary data which must come in through the context argument.
Many many example use a context

2) You should read the chapter on DAs in the manual. It describes the data
layout. In order for your code to
    work in parallel I suggest you use a Vec and cast to int when you need
the value.

 Thanks,

    Matt


> 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 *)’
>
>


-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150204/63543af0/attachment.html>


More information about the petsc-users mailing list