[petsc-users] time stepping questions

Gideon Simpson gideon.simpson at gmail.com
Tue Mar 10 09:24:35 CDT 2015


-gideon

> On Mar 10, 2015, at 10:03 AM, Jed Brown <jed at jedbrown.org> wrote:
> 
> Gideon Simpson <gideon.simpson at gmail.com> writes:
> 
>> I had two questions on time stepping routines:
>> 
>> 1.  What’s the proper usage of TSMonitorSolutionBinary?  As near as I can tell from source, I need to call:
>> 
>> PetscViewerBinaryOpen(PETSC_COMM_WORLD, "sim.bin",FILE_MODE_WRITE, &viewer);
>> 
>> TSMonitorSet(ts, TSMonitorSolutionBinary, viewer,(PetscErrorCode (*)(void**))PetscViewerDestroy);
>> 
>> I’m guessing it’s necessary to include the PetscViewerDestroy command?  
> 
> If you created a viewer, you need to destroy it.


But the destruction of the viewer is handled by the TSMonitor routine, and not done manually, with a PetscViewerDestroy routine?

> 
>> Also, is there a reason why I’m not passing a pointer to the viewer,
>> but rather just the view itself?
> 
> All PETSc objects are pointers.
> 
>  ierr = PetscOptionsString("-ts_monitor_solution_binary","Save each solution to a binary file","TSMonitorSolutionBinary",0,monfilename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
>  if (flg) {
>    PetscViewer ctx;
>    if (monfilename[0]) {
>      ierr = PetscViewerBinaryOpen(PetscObjectComm((PetscObject)ts),monfilename,FILE_MODE_WRITE,&ctx);CHKERRQ(ierr);
>      ierr = TSMonitorSet(ts,TSMonitorSolutionBinary,ctx,(PetscErrorCode (*)(void**))PetscViewerDestroy);CHKERRQ(ierr);
>    } else {
>      ctx = PETSC_VIEWER_BINARY_(PetscObjectComm((PetscObject)ts));
>      ierr = TSMonitorSet(ts,TSMonitorSolutionBinary,ctx,(PetscErrorCode (*)(void**))NULL);CHKERRQ(ierr);
>    }
>  }

What I find confusing about that, though, is that you call PetscViewerBinaryOpen with &ctx, a pointer to the viewer object, and this makes sense, because the command is:

PetscErrorCode  PetscViewerBinaryOpen(MPI_Comm comm,const char name[],PetscFileMode type,PetscViewer *binv)
but for TSMonitorSet and TSMonitorSolutionBinary, it’s written as:
PetscErrorCode  TSMonitorSet(TS ts,PetscErrorCode (*monitor)(TS,PetscInt,PetscReal,Vec,void*),void *mctx,PetscErrorCode (*mdestroy)(void**))
PetscErrorCode  TSMonitorSolutionBinary(TS ts,PetscInt step,PetscReal ptime,Vec u,void *viewer)
which makes it look like i should be passing an &ctx, and not the ct. itself.  But this is a minor point.  One works, and one doesn't

> 
>> 2.  Is there a built in way to track the time steps that the TS solver takes?  Assuming it’s using adaptivity, this could be variable.  I imagine I could use a TSMonitor routine to print it to the screen, but is there some way to get it into a file?
> 
> Do you want output from -ts_monitor or -ts_adapt_monitor?  The former
> takes a filename argument and the latter probably should (instead of
> just beeing a boolean).

I was more interested in -ts_monitor.  I suppose I just need to do string processing on that to get the actual times.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150310/c4fc2438/attachment.html>


More information about the petsc-users mailing list