# Rodas4 vs Rodas4P vs Rodas4P2 solvers

**URL:** <https://discourse.julialang.org/t/rodas4-vs-rodas4p-vs-rodas4p2-solvers/101261>\
**Category:** Modelling & Simulations\
**Tags:** question, modelingtoolkit, differentialequation\
**Created:** [July 6, 2023, 2:13pm UTC](https://discourse.julialang.org/t/rodas4-vs-rodas4p-vs-rodas4p2-solvers/101261 "2023-07-06T14:13:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [July 6, 2023, 2:13pm UTC](https://discourse.julialang.org/t/rodas4-vs-rodas4p-vs-rodas4p2-solvers/101261/1 "2023-07-06T14:13:43Z")

</div>

Today I found that the solver Rodas4P2 is working best for my model. For an tolerance of 1e-7 it is 4 times faster than Simulink, operating at a tolerance of 1e-3.

But what is the difference between Rodas4, Rodas4P and Rodas4P2?

I know that Rodas is described in literature, but I could not find any paper explaining Rodas4P or Rodas4P2… Is there any paper about it?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 6, 2023, 2:26pm UTC](https://discourse.julialang.org/t/rodas4-vs-rodas4p-vs-rodas4p2-solvers/101261/2 "2023-07-06T14:26:01Z")

</div>

There’s [Improvement of Rosenbrock-Wanner Method RODASP | SpringerLink](https://link.springer.com/chapter/10.1007/978-3-030-53905-4_6) and [Construction of Rosenbrock–Wanner method Rodas5P and numerical benchmarks within the Julia Differential Equations package - BIT Numerical Mathematics](https://link.springer.com/article/10.1007/s10543-023-00967-x) which is about Rodas5P Note that you might want to try using `Rodas5P` which is very similar to `Rodas4P` but higher order.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [July 6, 2023, 2:48pm UTC](https://discourse.julialang.org/t/rodas4-vs-rodas4p-vs-rodas4p2-solvers/101261/3 "2023-07-06T14:48:57Z")

</div>

Thanks a lot! Rodas5P is indeed even faster, but at some point I saw that it had stability problems when using a step input…

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 6, 2023, 3:01pm UTC](https://discourse.julialang.org/t/rodas4-vs-rodas4p-vs-rodas4p2-solvers/101261/4 "2023-07-06T15:01:08Z")

</div>

If you’re using a step input, you should probably be using `tstops` or a `ContinuousCallback` to tell the solver where the discontinuity is (see [Handling Instability When Solving ODE Problems](https://discourse.julialang.org/t/handling-instability-when-solving-ode-problems/9019)).

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [July 6, 2023, 7:27pm UTC](https://discourse.julialang.org/t/rodas4-vs-rodas4p-vs-rodas4p2-solvers/101261/5 "2023-07-06T19:27:33Z")

</div>

Just tested to add tstops. It works, but it is not sufficient to add a tstop at the time of the discontinuity, but I need one more for a perfect result. Example (assuming the step happens at 200s):

```julia
function simulate(sys, ω, ω0, U, U0, D; p = [U => U0], prn=true, duration=1000)
    u0 = [ω => ω0, # this is a fixed initial value
           D(ω) => 0.0] # the value for the derivative is an inital estimate

    # simulation parameters
    tspan = (0.0, duration)
    dt = 0.01
    ts = 0:dt:duration

    # run the simulation
    prob = ODEProblem(sys, u0, tspan, p)
    sol = solve(prob, Rodas5(), tstops=[200, 200+dt], saveat=ts)
end

```

This works perfect. Thank you!

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [July 6, 2023, 7:52pm UTC](https://discourse.julialang.org/t/rodas4-vs-rodas4p-vs-rodas4p2-solvers/101261/6 "2023-07-06T19:52:48Z")

</div>

Is it the same bug as reported here?

> <https://github.com/SciML/ModelingToolkit.jl/issues/2163>
>
> Frequently, MTK models exhibit weird/unphysical oscillatoric behavior when I use… step inputs and default solvers:
> 
> \<img width="461" alt="image" src="https://user-images.githubusercontent.com/54220415/236844078-b841d6a7-6d09-47a6-8556-ef8be05d4e28.png"\>
> 
> This plot uses input functions:
> \`\`\`julia
> u\_p\_f(t) = t \< 0.5 ? 220e5 : 0.95\*220e5
> u\_p\_m(t) = t \< 1.5 ? 50e5 : 0.97\*50e5
> u\_f\_p(t) = t \< 2.5 ? 60 : 0.95\*60
> u\_χ\_w(t) = 0.35
> \`\`\`
> Observe that the oscillation starts \*prior\* to the temporal location of one of the step changes. It is as if a too infrequent sampling is used, in combination with the built-in interpolation of the solution.
> 
> I have tried to specify \`tstops\` at the location of the step changes, without any improvement. I have also tried to specify a high resolution \`saveat\`, without any improvement.
> 
> The displayed behavior shows up when I use the default solver. I have tried to specify other solvers. The solvers I typically end up with are the BDF solvers, e.g., \`QBDF\`. With this solver, I get a more realistic solution:
> 
> \<img width="462" alt="image" src="https://user-images.githubusercontent.com/54220415/236845583-f2619289-3509-42cb-8777-d19956824d4d.png"\>
> 
> This solution is somewhat jagged; the solution gets better if I set \`reltol\` to \`1e-4\` or smaller.
> 
> \* \*\*Question\*\*: what is the cause of this strange, oscillatory solution? Is there a way to fix it using the default solver?
> 
> If you need my code to figure out the problem (simplifies to one DE and one AE), I will be happy to share it.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [July 6, 2023, 7:59pm UTC](https://discourse.julialang.org/t/rodas4-vs-rodas4p-vs-rodas4p2-solvers/101261/7 "2023-07-06T19:59:11Z")

</div>

I don’t know, looks like it, but I did not report that and a different solver was used…
