## Using the Previous Solution Operator in Transient Modeling

##### Walter Frei June 25, 2015

COMSOL Multiphysics version 5.1 includes a *Previous Solution* operator within time-dependent studies. This operator allows you to evaluate quantities at the previous time step when using the default implicit time-stepping algorithm. Let us take a look at how this operator is implemented and then examine how it can be used for various modeling needs.

### Transient Modeling and Time-Stepping

When you are solving a transient model, the COMSOL software by default uses an implicit time-stepping algorithm with adaptive time step size. This has the advantage of being unconditionally stable for many classes of problems and it lets the software choose the optimal time step size for the specified solver tolerances, thereby reducing the computational cost of the solution.

Two classes of time-stepping algorithms are available: a backward difference formula (BDF) and a generalized-alpha method. These algorithms use the solutions at several previous time steps (up to five) to numerically approximate the time derivatives of the fields and to predict the solution at the next time step.

However, these previous solutions are not by default accessible within the model. The *Previous Solution* operator makes the solution at the previous time step available as a field variable in the model. This *Previous Solution* operator is available for both transient as well as stationary problems solved using the continuation method. Let us take a look at how you can implement and use this *Previous Solution* operator in a transient model in COMSOL Multiphysics.

### Implementing the *Previous Solution* Operator in COMSOL Multiphysics

Using the *Previous Solution* operator requires only two additional features within the model tree. You must add an *ODE and DAE* interface to store the fields that you are interested in and you must add the *Previous Solution* feature to the Time-Dependent Solver. Let us take a look at the implementation in terms of a transient heat transfer example: The laser heating of a wafer with a moving heat load, solved on a rotating coordinate system.

The first step is to add a *Domain ODEs and DAEs* interface to the model, since we will be interested in tracking the solution at the previous time step throughout the volume of the part. If we were only interested in the previous solution across a boundary, edge, or point, or in some global quantity, we could also use a *Boundary*, *Edge*, *Point*, or *Global ODEs and DAEs* interface.

*The* Domain ODEs and DAEs *interface for tracking the solution at the previous time step.*

The screenshot above shows the relevant settings for the *Domain ODEs and DAEs* interface. Note that the units of both the dependent variable and the source are set to Temperature. It is a good modeling practice to appropriately set units. The discretization is set to a Lagrange Quadratic, which matches the discretization used by the *Heat Transfer in Solids* interface. You will always want to make sure that you are using the appropriate discretization. The name of the field variable here is left at the default “u”, although you can rename it to anything you would like.

*The equation being solved by the* Domain ODEs and DAEs *interface.*

The screenshot above shows the equation that stores the temperature solution at the previous time step. This equation can be read as:

`u-nojac(T)=0`

The `nojac()`

operator is needed, since we do not want this equation to contribute to the Jacobian (the system matrix). Lastly, we need to specify that this equation should be evaluated at the previous time step. This is done within the Solver Configurations.

*The Previous Solution feature added to the Solver Configuration.*

The screenshot above shows the *Previous Solution* feature added to the *Time-Dependent Solver*. Once you add this feature, simply select the appropriate field variable to be evaluated at the previous time step. It will also be faster (although not necessary) to use the Segregated Solver rather than the Fully Coupled solver.

And that is all there is to it. You can now solve the model just as you usually do and you will be able to evaluate the temperature at the previous computational time step.

### A More Practical Example: Keeping Track of the Maximum Temperature

Of course, having the solution at the previous time step isn’t really all that interesting in itself, but we can do quite a bit more than just store this solution. For example, we can apply logical expressions directly with the *ODEs and DAEs equation* interface. Consider the equation:

`u-nojac(if(T>u,T,u))`

This equation can be read as: “If the temperature at the previous time step is greater than u, set u equal to temperature. Otherwise, leave u unchanged.”

That is, it stores the maximum temperature reached at the previous time step at every point in the modeling domain. You can now evaluate the variables T and u at any point in the model to get both the temperature over time and the maximum temperature attained. To get the maximum temperature, you will want to take the maximum of the temperature at the previous time step and the temperature at the current time step, so you can introduce a variable in the model:

`MaxTemp = max(T,u)`

This will return the maximum temperature up to that time as shown in the plot below.

*Temperature at a point plotted over time. The variable MaxTemp is also plotted and shows the maximum temperature reached up to that instant in time.*

### Summary

We have shown here the implementation of the newly introduced *Previous Solution* operator for time-dependent models. The three steps to use this functionality appropriately are:

- Choose the appropriate
*ODEs and DAEs*interface and discretization. - Enter an appropriate equation.
- Add the
*Previous Solution*feature to the Solver Configurations.

We have shown how to evaluate the maximum temperature in this example, but there is a great deal more that can be done with this functionality, so stay tuned!

## Comments

Gongda LuJuly 11, 2015 1:46 pmGongda LuJuly 11, 2015 1:59 pmHello Walter,

Thanks a lot for sharing this new feature of COMSOL 5.1! Actually I have been longing for this functionality since a couple of years ago. Although it is a bit too late for me to implement that feature in my model, it does make a huge difference in the post-processing.

While I was practicing this functionality according to the example you provided, I was struggled by a problem: No data is stored after calculation, thus I can do nothing in the post-processing interface. However, the model does seem to have been executed properly because the “plot while solving” has presented the correct results I expected.

I am wondering if there is any other manipulation should be made in order to use the Previous Solution feature.

Your help is very much appreciated.

Best regards,

Gongda Lu

Walter FreiJuly 13, 2015 9:03 amDear Gongda,

This question will be best addressed via support, if you can please also send us the file you are having questions about.

Akash AggarwalAugust 24, 2015 4:14 amHello Walter .

Is this can be done in COMSOL 5.0

With regards,

Akash Aggarwal

Walter FreiAugust 24, 2015 8:48 amHello Akash,

We do recommend that you always upgrade to the latest version of the software, the functionality being described here is new.

Anu DasOctober 4, 2015 11:45 pmHello Walter

I was trying to couple poisson’s eqn (using electrostatics) and charge continuity eqn (using transport of diluted species) to study streamer discharge phenomena. I used the BC properly. they worked fine while run independently but coupling them didn’t converge. I tried it number of times but hardly any progress. So please send me your suggestions.

Regards,

- Anu Das

Anu DasOctober 5, 2015 4:54 amI have prepared the ppt slides (4 nos.) showing briefly the steps i followed in comsol and trying to solve. I want to share this with you so plz let me know your email.

Regards

- Anu Das

Julien GivernaudFebruary 19, 2016 4:53 amThis new feature can be very helpfull to implement very simple hysteresis loop over material properties

Best regards,

Julien

Walter FreiApril 13, 2017 5:05 pmIn followup to Julien’s comment about hysteresis modeling, please see:

https://www.comsol.com/blogs/thermal-modeling-of-phase-change-materials-with-hysteresis/

Saad PashaApril 20, 2017 6:44 amHi,

I’m totally unable to solve an ODE by using Domain-ODE module The equation is:

dNp/dt = 10e9*exp((Vm/0.245)^2)*(1-(Np/(1.5e9*exp(2.46(Vm/0.245)^2))))

where ‘Vm’ is a field variable and may be assumed as:

Vm = ec.normE/maximumOf(ec.normE)

i.e. 0 <= Vm <= 1

and

ec.normE is electric field computed by Electrical Currents(ec) Module on the below 2D 48x48mm model with 300V applied pulse of 0.1s at 0.5mm electrode in 5 second simulation.

___________

| |

| o o |

| |

'————'

Kindly help me out and make me the model if possible. I'll be very thankful to you

Caty FaircloughMay 5, 2017 2:16 pmHi Saad,

Thanks for your comment and interest in this blog post!

For questions related to your modeling, please contact our Support team.

Online Support Center: https://www.comsol.com/support

Email: support@comsol.com

Walter FreiMay 8, 2017 8:21 amHello,

We should also say that the timemax and timemin operators within more recent versions of the software do make this example of monitoring peak temperature somewhat moot. However, for some more relevant examples of using the previous solution operator, please see:

https://www.comsol.com/blogs/tracking-material-damage-with-the-previous-solution-operator/

https://www.comsol.com/blogs/thermal-modeling-of-phase-change-materials-with-hysteresis/