<div dir="ltr">Hi Zhang,<div><br></div><div>Thanks to your help i have implemented the TS routine for my temperature DMDA array, and it works correctly including in MPI.</div><div><br></div><div>The breakthrough for me was realizing that TS steps and max time steps are all set up once, and used/advanced all at once when invoked with TSSolution. So what i did was to add all of the TSCreate / initialization into the main loop so i am basically creating and destroying the TS objects every time step. I hope the overhead time is not to bad when i scale to bigger problems.</div><div><br></div><div>Next step would be to apply the same to advance the velocities, but problem now is that they are in a 4D dmda array of 3 degrees of freedom, any suggestions on how to implement this? does TS support multiple degrees of freedom arrays?</div><div><br></div><div>Thanks, </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 4, 2019 at 9:18 PM Zhang, Hong <<a href="mailto:hongzhang@anl.gov" target="_blank">hongzhang@anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<br>
<div><br>
<blockquote type="cite">
<div>On Jul 3, 2019, at 3:10 PM, Manuel Valera <<a href="mailto:mvalera-w@sdsu.edu" target="_blank">mvalera-w@sdsu.edu</a>> wrote:</div>
<br class="gmail-m_-2030399948005140960gmail-m_-5705247822916275700Apple-interchange-newline">
<div>
<div dir="ltr">Thanks Zhang for your answer,
<div><br>
</div>
<div>I ended up getting a compiling and running TS routine... that does not give me the answers, and i am not sure what i am doing wrong,</div>
<div><br>
</div>
<div>My TS code so far looks like this:</div>
<div><br>
</div>
<div>(...initialization...)</div>
<div><br>
</div>
<div><font face="courier new, monospace">call TSCreate(PETSC_COMM_WORLD,ts,ierr)<br>
call TSSetProblemType(ts,TS_NONLINEAR,ierr)<br>
call TSSetSolution(ts,gTemperature,ierr)<br>
call TSSetRHSFunction(ts,PETSC_NULL_VEC,FormRHSFunction,PETSC_NULL_VEC,ierr)<br>
</font></div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>The second last argument should be the user context. If you pass NULL, the ctx variable in your FormRHSFunction will be NULL. </div>
<br>
<blockquote type="cite">
<div>
<div dir="ltr">
<div><font face="courier new, monospace">call TSSetType(ts,TSSSP,ierr)<br>
call TSSetTimeStep(ts,dt,ierr)<br>
call TSSetDM(ts,daScalars,ierr)<br>
call TSSetMaxTime(ts,TotalTime,ierr)<br>
call TSSetExactFinalTime(ts,TS_EXACTFINALTIME_STEPOVER,ierr)<br>
call TSSetFromOptions(ts,ierr)<br>
call TSSetUp(ts,ierr)</font><br>
</div>
<div><br>
</div>
<div>(... then inside main calculations loop i have...)</div>
<div><br>
</div>
<div><font face="courier new, monospace">call TSSolve(ts,gTemperature,ierr)<br>
</font></div>
<div><br>
</div>
<div>(...and my RHSFunction looks like this...)</div>
<div><br>
</div>
<div><font face="courier new, monospace">subroutine FormRHSFunction(ts,t,t_loc,rhs_loc,ctx,ierr)<br>
<br>
use petscvec<br>
use petscts<br>
use petscdmda<br>
use petscdm<br>
<br>
USE utils<br>
USE dmdaobjs<br>
USE probsize<br>
USE modelparams<br>
<br>
implicit none<br>
<br>
TS :: ts<br>
PetscReal :: t<br>
Vec :: ctx,t_loc,rhs_loc<br>
PetscErrorCode :: ierr<br>
<br>
<br>
<br>
call TSGetDM(ts,daScalars,ierr)<br>
<br>
call DMGetLocalVector(daScalars,t_loc,ierr);<br>
</font></div>
</div>
</div>
</blockquote>
<div><br>
</div>
t_loc is the input, it should be not modified.</div>
<div><br>
</div>
<div>
<blockquote type="cite">
<div>
<div dir="ltr">
<div><font face="courier new, monospace"> call DMGlobalToLocalBegin(daScalars,gTemperature,INSERT_VALUES,t_loc,ierr);CHKERRQ(ierr)<br>
call DMGlobalToLocalEnd(daScalars,gTemperature,INSERT_VALUES,t_loc,ierr);CHKERRQ(ierr)<br>
</font></div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>FormRHSFunction is supposed to implement rhs_loc = f(t,t_loc). So you want to scatter ghost points for t_loc, not gTemperature.</div>
<br>
<blockquote type="cite">
<div>
<div dir="ltr">
<div><font face="courier new, monospace"> call DMDASolveTExplicit(3)<br>
<br>
call DMGetLocalVector(daScalars,rhs_loc,ierr);<br>
call DMGlobalToLocalBegin(daScalars,TRHSS_ts,INSERT_VALUES,rhs_loc,ierr);CHKERRQ(ierr)<br>
call DMGlobalToLocalEnd(daScalars,TRHSS_ts,INSERT_VALUES,rhs_loc,ierr);CHKERRQ(ierr)<br>
</font></div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>There is no need to scatter ghost points for rhs_loc.</div>
<div><br>
</div>
<blockquote type="cite">
<div>
<div dir="ltr">
<div><font face="courier new, monospace"><br>
<br>
call DMRestoreLocalVector(daScalars,t_loc,ierr);CHKERRQ(ierr)<br>
call DMRestoreLocalVector(daScalars,rhs_loc,ierr);CHKERRQ(ierr)<br>
<br>
end subroutine FormRHSFunction</font><br>
</div>
<div><br>
</div>
<div>Where DMDASolveTExplicit(3) is the old function to calculate time integration with runge kutta, modified to only generate the f(t,u) which in this case is rhs_loc,</div>
<div><br>
</div>
<div>I still have several doubts:</div>
<div><br>
</div>
<div>
<ul>
<li>Will this explicit RHS calculation work with TS routines? my time integration is explicit so far and it would involve a fair deal of extra work to make it implicit. </li></ul>
</div>
</div>
</div>
</blockquote>
<div>For explicit time integration, one needs to provide only RHSFunction.</div>
<br>
<blockquote type="cite">
<div>
<div dir="ltr">
<div>
<ul>
<li>This 't' parameter in the RHSFunction is controlled by PETSC? i am not providing anything for it directly, where is it coming from?</li></ul>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>It is controlled by PETSc. If your problem is autonomous (the RHS does not depend on t), it can be simply ignored.</div>
<div> </div>
<blockquote type="cite">
<div>
<div dir="ltr">
<div>
<ul>
<li>Do i need to provide a Jacobian or the TS routine will try to guess one? This is related to the first point where my time scheme being explicit does not use a jacobian.</li></ul>
</div>
</div>
</div>
</blockquote>
<div>For explicit time integration, Jacobian is not needed.</div>
<div><br>
</div>
<div>Hong</div>
<br>
<blockquote type="cite">
<div>
<div dir="ltr">
<div>
<div><br>
</div>
</div>
<div>Thanks, any help is appreciated, if you see any errors or need more information please let me know,</div>
</div>
</div>
</blockquote>
<blockquote type="cite">
<div>
<div dir="ltr">
<div><br>
</div>
<div>Regards,</div>
<div><br>
</div>
<div>Manuel </div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Jun 26, 2019 at 9:54 PM Zhang, Hong <<a href="mailto:hongzhang@anl.gov" target="_blank">hongzhang@anl.gov</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><br>
<div><br>
<blockquote type="cite">
<div>On Jun 26, 2019, at 4:17 PM, Manuel Valera via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:</div>
<br class="gmail-m_-2030399948005140960gmail-m_-5705247822916275700gmail-m_6853237684116060569Apple-interchange-newline">
<div>
<div dir="ltr">Hi PETSc,<br>
<div><br>
</div>
<div>I am trying to implement the Time stepping routines in my model, i have a working runge-kutta time scheme that goes to the following steps:</div>
<div><br>
</div>
<div>
<ul>
<li>Interpolate u,v,w to the time advancing variable position.</li><li>Calculate nonlinear coefficients and advect velocities with a forward-backward shock capturing scheme.</li><li>Calculate the variable laplacian </li><li>Sum terms to create RHS (nonlinear advected velocities + laplacian)</li><li>Finally, the runge kutta integration is done in a typical way that looks like:</li></ul>
<div> newtemp(t+1) = prevtemp(t) + dt*RHS</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>So my questions are:</div>
<div>
<ul>
<li>I think my problem is nonlinear, but is being made linearized by the advecting scheme, is this correct? this is to know if i should use the linear or nonlinear routines for TS.</li></ul>
</div>
</div>
</div>
</blockquote>
<span>TSComputeRHSFunctionLinear is just a convenience function for linear ODEs in the form udot=Au. Using it won’t buy you much. So for TS starters, it is fine to assume your problem is nonlinear and think of the form udot=f(t,u) where f is the RHS
function. </span><span><br>
</span>
<blockquote type="cite">
<div>
<div dir="ltr">
<div>
<ul>
<li>How do i know what are the appropriate routines i should be using here? so far i think i should use the following:</li></ul>
<div>call TSCreate(PETSC_COMM_WORLD,ts,ierr)<br>
call TSSetProblemType(ts,TS_LINEAR,ierr)<br>
call TSSetTimeStep(ts,dt,ierr)<br>
<br>
call TSSetFromOptions(ts,ierr)<br>
</div>
<div><br>
</div>
<div>call TSSetRHSFunction(ts,NULL,TSComputeRHSFunctionLinear,NULL,ierr)<br>
call TSSolve(ts,loctemperature,ierr)<br>
<br>
</div>
</div>
<div>Should i use call TSSetRHSJacobian for the temperature jacobian in this case?</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>I would suggest to write your own RHSFunction and set it to TS with TSSetRHSFunction().</div>
<div><br>
</div>
<blockquote type="cite">
<div>
<div dir="ltr">
<div> </div>
<div><br>
</div>
<div>I am using <a href="https://www.mcs.anl.gov/petsc/petsc-current/src/ts/examples/tutorials/ex4.c.html" target="_blank">https://www.mcs.anl.gov/petsc/petsc-current/src/ts/examples/tutorials/ex4.c.html</a> as a general guide, is there a
more appropriate example?</div>
</div>
</div>
</blockquote>
<div><br>
</div>
ex4 is a good example. In addition, ex9 uses finite volume method with slope limiters to solve a variety of problems such as advection equation, burgers equation and shallow water equation. It might be an overkill, but it seems to be close to the problem you
are trying to solve. Note that you might want to use the SSP methods (-ts_type ssp) instead of the classic Runge-Kutta methods for problems with shocks.</div>
<div><br>
</div>
<div>Hong (Mr.)</div>
<div><br>
</div>
<div>
<blockquote type="cite">
<div>
<div dir="ltr">
<div><br>
</div>
<div>The dt value and total timesteps are controlled by the model,</div>
<div><br>
</div>
<div>Thanks for your help,</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote></div>