[petsc-users] Saving solution with monitor function

Guglielmo, Tyler Hardy guglielmo2 at llnl.gov
Wed Dec 14 16:42:56 CST 2022


Ah beautiful, thanks for showing me these.  Apologies for bugging you all with these questions.  Having to learn a ton of subroutines…

Btw is there a matrix addition function for M = a*M_1 + b*M_2, or one similar to MatAXPY that does not overwrite the Y matrix, i.e. M = a*X + Y ?

All the best,
Tyler

From: Barry Smith <bsmith at petsc.dev>
Date: Wednesday, December 14, 2022 at 12:51 PM
To: Guglielmo, Tyler Hardy <guglielmo2 at llnl.gov>
Cc: Matthew Knepley <knepley at gmail.com>, petsc-users at mcs.anl.gov <petsc-users at mcs.anl.gov>
Subject: Re: [petsc-users] Saving solution with monitor function

  See, for example https://petsc.org/release/docs/manualpages/TS/TSTrajectoryGetVecs/<https://urldefense.us/v3/__https:/petsc.org/release/docs/manualpages/TS/TSTrajectoryGetVecs/__;!!G2kpM7uM-TzIFchu!g_m1lKCrhOfOZS5ADCQjmV_Ma8U7ZZJpCFHg6T7Lu10M0jl8pC_5yXYCyQIH7-4dIko$> and https://petsc.org/release/docs/manualpages/TS/TSTrajectoryGetUpdatedHistoryVecs/<https://urldefense.us/v3/__https:/petsc.org/release/docs/manualpages/TS/TSTrajectoryGetUpdatedHistoryVecs/__;!!G2kpM7uM-TzIFchu!g_m1lKCrhOfOZS5ADCQjmV_Ma8U7ZZJpCFHg6T7Lu10M0jl8pC_5yXYCyQIHEECbTaM$>

  One does not directly access the data inside the trajectory; one calls functions in the API to obtained desired information.  If you need specific information that it does not currently provide we can attempt to provide additional functionality.


  Barry



On Dec 14, 2022, at 1:07 PM, Guglielmo, Tyler Hardy via petsc-users <petsc-users at mcs.anl.gov> wrote:

Thanks Matt,

I’m a bit confused on where the trajectory is being stored in the TSTrajectory object.

Basically I have run

TSSetSaveTrajectory(ts);
…
TSSolve(ts, x);
TSTrajectory tj;
TSGetTrajectory(ts, &tj);
TSTrajectorySetType(tj, ts, TSTRAJECTORYMEMORY);

How is the object supposed to be accessed to find the entire trajectory?  I couldn’t find a clear example of where this is laid out in the documentation.

The TSTrajectory object looks like some complicated struct, but parsing which pointer is pointing to the solution has alluded me.

Thanks for your time!

Best,
Tyler


From: Matthew Knepley <knepley at gmail.com<mailto:knepley at gmail.com>>
Date: Tuesday, December 13, 2022 at 6:41 AM
To: Guglielmo, Tyler Hardy <guglielmo2 at llnl.gov<mailto:guglielmo2 at llnl.gov>>
Cc: petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov> <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>>
Subject: Re: [petsc-users] Saving solution with monitor function
On Tue, Dec 13, 2022 at 8:40 AM Guglielmo, Tyler Hardy via petsc-users <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>> wrote:
Hi all,

I am a new PETSc user (and new to MPI in general), and was wondering if someone could help me out with what I am sure is a basic question (if this is not the appropriate email list or there is a better place please let me know!).

Basically, I am writing a code that requires a solution to an ODE that will be used later on during runtime.  I have written the basic ODE solver using TSRK, however I haven’t thought of a good way to store the actual solution at all time steps throughout the time evolution.  I would like to avoid writing each time step to a file through the monitor function, and instead just plug each time step into an array.

How is this usually done?  I suppose the user defined struct that gets passed into the monitor function could contain a pointer to an array in main?  This is how I would do this if the program wasn’t of the MPI variety, but I am not sure how to properly declare a pointer to an array declared as Vec and built through the usual PETSc process.  Any tips are greatly appreciated

I think this is what TSTrajectory is for. I believe you want https://petsc.org/main/docs/manualpages/TS/TSTRAJECTORYMEMORY/<https://urldefense.us/v3/__https:/petsc.org/main/docs/manualpages/TS/TSTRAJECTORYMEMORY/__;!!G2kpM7uM-TzIFchu!irkbXWpYDosRslumKjVGCqxHkKyU-riye4i1dWe58HYH_sFxImRj33gOkhB2sgd_duk$>

  Thanks,

      Matt

Thanks for your time,
Tyler

+++++++++++++++++++++++++++++
Tyler Guglielmo
Postdoctoral Researcher
Lawrence Livermore National Lab
Office: 925-423-6186
Cell: 210-480-8000
+++++++++++++++++++++++++++++


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

https://www.cse.buffalo.edu/~knepley/<https://urldefense.us/v3/__http:/www.cse.buffalo.edu/*knepley/__;fg!!G2kpM7uM-TzIFchu!irkbXWpYDosRslumKjVGCqxHkKyU-riye4i1dWe58HYH_sFxImRj33gOkhB27-uscIw$>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20221214/8699765f/attachment.html>


More information about the petsc-users mailing list