<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; ">-gideon</span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Mar 10, 2015, at 10:03 AM, Jed Brown <<a href="mailto:jed@jedbrown.org" class="">jed@jedbrown.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Gideon Simpson <<a href="mailto:gideon.simpson@gmail.com" class="">gideon.simpson@gmail.com</a>> writes:<br class=""><br class=""><blockquote type="cite" class="">I had two questions on time stepping routines:<br class=""><br class="">1. What’s the proper usage of TSMonitorSolutionBinary? As near as I can tell from source, I need to call:<br class=""><br class="">PetscViewerBinaryOpen(PETSC_COMM_WORLD, "sim.bin",FILE_MODE_WRITE, &viewer);<br class=""><br class="">TSMonitorSet(ts, TSMonitorSolutionBinary, viewer,(PetscErrorCode (*)(void**))PetscViewerDestroy);<br class=""><br class="">I’m guessing it’s necessary to include the PetscViewerDestroy command? <br class=""></blockquote><br class="">If you created a viewer, you need to destroy it.<br class=""></div></blockquote><div><br class=""></div><div><br class=""></div><div>But the destruction of the viewer is handled by the TSMonitor routine, and not done manually, with a PetscViewerDestroy routine?</div><br class=""><blockquote type="cite" class=""><div class=""><br class=""><blockquote type="cite" class="">Also, is there a reason why I’m not passing a pointer to the viewer,<br class="">but rather just the view itself?<br class=""></blockquote><br class="">All PETSc objects are pointers.<br class=""><br class=""> ierr = PetscOptionsString("-ts_monitor_solution_binary","Save each solution to a binary file","TSMonitorSolutionBinary",0,monfilename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);<br class=""> if (flg) {<br class=""> PetscViewer ctx;<br class=""> if (monfilename[0]) {<br class=""> ierr = PetscViewerBinaryOpen(PetscObjectComm((PetscObject)ts),monfilename,FILE_MODE_WRITE,&ctx);CHKERRQ(ierr);<br class=""> ierr = TSMonitorSet(ts,TSMonitorSolutionBinary,ctx,(PetscErrorCode (*)(void**))PetscViewerDestroy);CHKERRQ(ierr);<br class=""> } else {<br class=""> ctx = PETSC_VIEWER_BINARY_(PetscObjectComm((PetscObject)ts));<br class=""> ierr = TSMonitorSet(ts,TSMonitorSolutionBinary,ctx,(PetscErrorCode (*)(void**))NULL);CHKERRQ(ierr);<br class=""> }<br class=""> }<br class=""></div></blockquote><div><br class=""></div><div>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:</div><div><br class=""></div><div><pre style="widows: 1;" class="">PetscErrorCode PetscViewerBinaryOpen(MPI_Comm comm,const char name[],PetscFileMode type,PetscViewer *binv)</pre><div class="">but for TSMonitorSet and TSMonitorSolutionBinary, it’s written as:</div><div class=""><pre style="widows: 1;" class="">PetscErrorCode TSMonitorSet(TS ts,PetscErrorCode (*monitor)(TS,PetscInt,PetscReal,Vec,void*),void *mctx,PetscErrorCode (*mdestroy)(void**))</pre><div class=""><pre style="widows: 1;" class="">PetscErrorCode TSMonitorSolutionBinary(TS ts,PetscInt step,PetscReal ptime,Vec u,void *viewer)</pre><div class="">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</div></div></div></div><br class=""><blockquote type="cite" class=""><div class=""><br class=""><blockquote type="cite" class="">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?<br class=""></blockquote><br class="">Do you want output from -ts_monitor or -ts_adapt_monitor? The former<br class="">takes a filename argument and the latter probably should (instead of<br class="">just beeing a boolean).<br class=""></div></blockquote></div><br class=""><div class="">I was more interested in -ts_monitor. I suppose I just need to do string processing on that to get the actual times.</div></body></html>