[petsc-users] accessing fields from previous, converged solution.

Matthew Knepley knepley at gmail.com
Wed Aug 16 09:17:52 CDT 2017

On Wed, Aug 16, 2017 at 8:56 AM, Maximilian Hartig <imilian.hartig at gmail.com
> wrote:

> Hello,
> I have a problem with several fields that I solve with PetscFE and TS. I
> now need to access the solution from the previous timestep to compute the
> residual for the current timestep.
> I tried a TSMonitor with the following code in it:
> TSGetDM(ts,&dm);
> DMClone(dm,&dm_aux);
> DMGetDS(dm,&prob_aux);
> DMSetDS(dm_aux,prob_aux);
> DMCreateGlobalVector(dm_aux,&old_solution);
> VecCopy(u,oldsolution);
> PetscObjectCompose((PetscObject) dm, “A”, (PetscObject) old_solution);
> VecDestroy(&old_solution);
> DMDestroy(&dm_aux);
> hoping that it would create an auxiliary field that I could access in the
> evaluation of the residual. It did that but messed with the discretisation
> of the initial problem in some way. So I figure that adding auxiliary
> fields to a dm after having fed it to a TS context is not something you
> should be doing.
> Is there a way to access the fields of the solution for the previous
> timestep during the evaluation of the current residual?

First, I can show you how to do what you are asking for. I think you can

PetscObjectQuery((PetscObject) dm, "old_solution", (PetscObject *)
if (!old_solution) {
  DMCreateGlobalVector(dm, &old_solution);
  PetscObjectCompose((PetscObject) dm, "old_solution", old_solution);
VecCopy(u, oldsolution);

Second, I think a better way to do this than composition is to use

  DMGetNamedGlobalVector(dm, "old_solution", &old_solution);

Third, I can say that I am profoundly troubled by this. This interferes
with the operation of
the time integrator, and I cannot see a reason for this. If you are keeping
track of the integral
of some quantity, I would update that in TSPostStep() and request that
integral instead of the
previous solution. We do this for some non-Newtonian rheologies.



> Thanks,
> Max

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

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

More information about the petsc-users mailing list