How can we save & extract Derivatives from the Solver in Julia?

Hello everybody and happy new year to all of you,

I’m solving a PDE system using MethodeOfLines tool of Julia. The documentation guided me quite well.

benefiting from ChrisRackauckas advise to speed up the non linearity, here is the good setup of the solve line , that works very well for this problem.

sol = solve(prob, FBDF(linsolve = LinearSolve.KrylovJL_GMRES()), abstol=1e-8, reltol=1e-8)

pdesys = PDESystem(eqs, bcs, domains, [t, x], [u(t, x), v(t, x), w(t, x)])
prob = discretize(pdesys, discretization)

The problem was solved successfully, but very slowly. ChrisRackauckas is currently collaborating with Julia’s community to find ways to speed things up.

Now, I want to calculate the derivatives ( Dx(u) ), ( Dx(v) ), and possibly ( Dt(u) ) and ( Dt(v) ) throughout the domain. This would help me better understand the flux in the system.

To retrieve the solutions, I assign them like this:

solu =  sol[u(t,x)]
solv =  sol[v(t,x)]
solw = sol[w(t,x)]

I thought getting the derivatives would be as simple as retrieving the solutions, for example:

solDxu = sol[Dx(u)]

But this doesn’t work.

Maybe I need to save the derivative information during the solving stage,
Maybe I should also ask for symbolic discretization because I’m using ModelingToolkit as fellow

sym_prob = symbolic_discretize(pdesys, discretization)

so I can access it later? I’m not sure how to proceed.

If someone understands my question and can help, I’d be really grateful!

If retrieving the derivatives isn’t possible, could you at least guide me on how to extract the boundary values of ( u ) and ( v ) from solu and solv? That way, I can calculate an average flux in the domain as a function of time.


Naceur Bouziani

Does this help you or are you looking for something else?

1 Like

Hi abraemer

Thank you so much! I’ll give this a try and let you know how it goes.

I’ve realized that I need to dive deeper into understanding how the integrator works—it’s becoming clear that learning more about it will be super helpful for achieving a lot. That said, I’ll probably need quite a bit of guidance along the way. I hope I won’t end up wearing you all out! :blush:

I’ve started reading through this resource and working through it line by line. It’s not easy, but I know that with time, I’ll learn something new and make progress!

Hi abraemer

While trying to learn about something (Val(1)) that I didn’t understand in the code you gave me, I found one utility, DiffEqCallbacks.jl that seems to save information about the integrator. I’m trying to comprehend how this works, I made some progress. If I can use diff(u)/dx at each time and each x that could give me an estimation of derivatives. And DiffEqCallbacks save them for me, I can plot this and see the flux in my medium and see how this changes vs. time and also vs x. I will come back as soon as I progress