[petsc-users] time stepping questions

Jed Brown jed at jedbrown.org
Tue Mar 10 09:03:26 CDT 2015


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.

> 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);
    }
  }

> 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).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150310/40e2a71c/attachment.pgp>


More information about the petsc-users mailing list