[petsc-dev] The question about TS^pseudo-timestepping
Barry Smith
bsmith at mcs.anl.gov
Sun Sep 14 10:59:51 CDT 2014
On Sep 14, 2014, at 10:54 AM, Lulu Liu <lulu.liu at kaust.edu.sa> wrote:
> Hi,
>
> I looked at the example /petsc/src/ts/examples/tutorials/ex1.c, which is to solve a 2D Bratu nonlinear PDE with pseudo-timestepping.
>
> ierr = TSSetRHSFunction(ts,NULL,FormFunction,&user);CHKERRQ(ierr);
>
> Q1:In the FormFunction(), I do not understand why this example uses 1D array, not 2D array x[j][i]? Is it necessary to use 1D array when we use the pseudo-timestepping method?
It is just historical. This example was originally written a VERY long time ago. I can certainly be done in the style of using 2D arrays.
>
> #undef __FUNCT__
> #define __FUNCT__ "FormFunction"
> PetscErrorCode FormFunction(TS ts,PetscReal t,Vec X,Vec F,void *ptr)
> {
>
> …….
> for (j=0; j<my; j++) {
> for (i=0; i<mx; i++) {
> row = i + j*mx;
> if (i == 0 || j == 0 || i == mx-1 || j == my-1) {
> f[row] = x[row];
> continue;
> }
> u = x[row];
> ub = x[row - mx];
> ul = x[row - 1];
> ut = x[row + mx];
> ur = x[row + 1];
> uxx = (-ur + two*u - ul)*hydhx;
> uyy = (-ut + two*u - ub)*hxdhy;
> f[row] = -uxx + -uyy + sc*lambda*PetscExpScalar(u);
> }
> }
> ……..
> }
>
> Q2: I try to modify this function using local 2D array x[j][i], but got some errors:
> [0]PETSC ERROR:
> [0]PETSC ERROR: Must call DMShellSetLocalVector() or DMShellSetCreateLocalVector()
> [0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.
> [0]PETSC ERROR: Petsc Release Version 3.5.1, Jul, 24, 2014
> [0]PETSC ERROR: ./test on a arch-darwin-c-debug named kl-12681.local by liul Sun Sep 14 18:42:38 2014
> [0]PETSC ERROR: Configure options --with-cc=gcc --with-cxx=g++ --with-fc=gfortran --download-fblaslapack --download-mpich
> [0]PETSC ERROR: #1 DMCreateLocalVector_Shell() line 271 in /Users/liul/soft/petsc-3.5.1/petsc/src/dm/impls/shell/dmshell.c
> [0]PETSC ERROR: #2 DMCreateLocalVector() line 709 in /Users/liul/soft/petsc-3.5.1/petsc/src/dm/interface/dm.c
> [0]PETSC ERROR: #3 DMGetLocalVector() line 49 in /Users/liul/soft/petsc-3.5.1/petsc/src/dm/interface/dmget.c
> [0]PETSC ERROR: #4 FormFunction() line 253 in /Users/liul/Desktop/Combustion/test.c
> [0]PETSC ERROR: #5 TSComputeRHSFunction() line 475 in /Users/liul/soft/petsc-3.5.1/petsc/src/ts/interface/ts.c
> [0]PETSC ERROR: #6 TSComputeIFunction() line 688 in /Users/liul/soft/petsc-3.5.1/petsc/src/ts/interface/ts.c
> [0]PETSC ERROR: #7 TSPseudoMonitorDefault() line 330 in /Users/liul/soft/petsc-3.5.1/petsc/src/ts/impls/pseudo/posindep.c
> [0]PETSC ERROR: #8 TSMonitor() line 2809 in /Users/liul/soft/petsc-3.5.1/petsc/src/ts/interface/ts.c
> [0]PETSC ERROR: #9 TSSolve() line 2751 in /Users/liul/soft/petsc-3.5.1/petsc/src/ts/interface/ts.c
> [0]PETSC ERROR: #10 main() line 162 in /Users/liul/Desktop/Combustion/test.c
It looks like you did not change the main() part of the code to use a DM. You need to create the 2D DMDA up there, provide it to the TS and also create the vectors and matrix in main() from the DM not directly with calls to VecCreate() or MatCreate(); see, for example, ex7.c in that directory.
>
>
> This message and its contents, including attachments are intended solely for the original recipient. If you are not the intended recipient or have received this message in error, please notify me immediately and delete this message from your computer system. Any unauthorized use or distribution is prohibited. Please consider the environment before printing this email.
More information about the petsc-dev
mailing list