ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

Documentation: Tutorial on ODE/DAE systems coming from semi-discretized PDE System modelling

Open rschiemann1 opened this issue 2 years ago • 12 comments

As a newcomer to Julia and MTK, I struggled to find tutorials and resources about modelling of large DAEs stemming from semi-discretization PDE systems, where generally PDEs can have a time derivative term or not.

Such Systems arise often in practice, See for example the derivation of such a system in this post. I think, it is worthwhile to devote a tutorial page in the MTK documentation for such kind of systems.

More specifically, I think the tutorial should cover up-to-date and best practice approaches for:

  • Building an MTK System with scalar and array variables, with the array variables representing the solved variable field of the discretized PDE

  • Constructing a numerical problem out of that system. Describe rationale for choice of ODEProblem, DAEProblem of ODAEProblem system in problem building. What is best in which situation, what is already fully functional and what is limited/feature incomplete for the time being

  • Definition of initial values/guesses for the variables of the system, most importantly of the discretized array variables.

  • Structural simplification of the system and further usage of the simplified system without having to set the initial values again

  • Solving the simplified and non-simplified system in mass matrix form and in fully implicit form using IDA. Usage of sparsity and symbolic Jacobian in both of these cases.

  • Plotting of the solved (and observed) variables, especially of the array variables: Plotting certain (or all) elements of the array variables over time as well as plotting all elements of an array variable over a different (e.g. spatial) coordinate for a given point in time

  • Hints and possibly demonstration of further tricks to improve performance of the numerical solution, if there are any

Being a newcomer myself, I can certainly not help with the coding part of the tutorial, but I am happy to assist in the overall narrative and can provide text and ideas, if need be. I already have a first MTK implementation of the system I linked to above, if that is of any help.

rschiemann1 avatar Mar 10 '22 09:03 rschiemann1

Merge with #1459 for MTK handling of DAE systems. I would add:

  • symbolic arithmetic of parameters. At present, just numeric arithmetic is allowed;
  • numeric evaluation of jacobian corresponding to the symbolic calculate_jacobian;
  • domains/intervals of parameters and variables in ODAEProblem as in PDEProblem.

finmod avatar Mar 11 '22 12:03 finmod

Have you come across MethodOfLines.jl? It doesn't do everything you list here yet, but I think it's all within scope. @xtalax

valentinsulzer avatar Mar 17 '22 00:03 valentinsulzer

@finmod MethodOfLines.jl handles most of this, please reach out either with an issue there or on the julia slack @Alex Jones with a system that you are trying to solve and I'd be happy to support you getting it working.

xtalax avatar Mar 17 '22 10:03 xtalax

Hi,

I appreciate the offered support in using MethodOfLines.jl for automatic discretization of PDEs. Infact, this is part of my use case and so I definitely see myself coming back to that offer when the time comes.

However, this issue did not aim at the matter of MethodOfLines.jl (of any other package that might support the specific modeling task described in the original post. The modelling task was rather mentioned to demonstrate the need for telling newcomers in a streamlined way how to use MTK for such systems, going a bit beyond the examples and tutorials that are typically presented in talks and topics about MTK.

So in my opinion, this issue still has its reason to exist.

Am 17.03.2022 um 11:36 schrieb xtalax @.***>:

 @finmod MethodOfLines.jl handles most of this, please reach out either with an issue there or on the julia slack @Alex Jones with a system that you are trying to solve and I'd be happy to support you getting it working.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.

rschiemann1 avatar Mar 17 '22 19:03 rschiemann1

@xtalax Submitted a demo DAE problem specified in MTK at https://github.com/SciML/MethodOfLines.jl/issues/50 .

I agree with @rschiemann1 that a tutorial on DAE problems should remain in MTK where it is likely to get good visibility. MethodOfLines is one of the solutions available to solve these DAE problems along with other issues like structural identifiability, sensitivity analysis and jacobian analysis. The common denominator provided by MTK is a symbolic specification as you would write it on paper without the clustering of definining functions.

Another spectacular use of MTK is https://github.com/qojulia/QuantumCumulants.jl

finmod avatar Mar 18 '22 15:03 finmod

Bump. If there is any interest from the main MTK developers to realize such a documentation, I am willing to help.

rschiemann1 avatar Apr 05 '22 15:04 rschiemann1

It would be nice. While people should be using MethodOfLines.jl for this specifically (and the tutorial should mention that), I think it would be good to have such a non-trivial example presented as a tutorial for how to use MTK. A good demo that is both non-trivial but also "large" is always a partial differential equation, so this makes sense. And showing how you can do algebraic boundary conditions would be a plus to show why MTK is so useful in this domain.

Maybe to keep people on their toes, doing a finite volume or something might be a way to twist it, but then again, for this kind of thing, simplifying out as much as possible is always good.

ChrisRackauckas avatar Apr 05 '22 15:04 ChrisRackauckas

Thanks. Okay, so how should we get this started?

rschiemann1 avatar Apr 05 '22 18:04 rschiemann1

Try writing something, check it against MethodOfLines.jl, and start asking questions until the script works! Feel free to post WIP stuff to get help.

ChrisRackauckas avatar Apr 05 '22 20:04 ChrisRackauckas

@rschiemann1 I have submitted a model DAE/ODE Problem specified in MTK with domains and BCs #50 to MethodOfLines as a prototype for a tutorial

finmod avatar Apr 05 '22 20:04 finmod

@rschiemann1 I have submitted a model DAE/ODE Problem specified in MTK with domains and BCs #50 to MethodOfLines as a prototype for a tutorial

I just checked your model problem. To be honest, I don't see the connection to MethodOfLines (the code models a DAE problem, what is there to discretize?), but besides, it is a nice piece of code demonstrating some good approaches.

I have a few issues open here. As soon as they are closed, I will go ahead and try to get the tutorial done. When time has come, I will post WIP codes & text here.

rschiemann1 avatar Apr 07 '22 18:04 rschiemann1

I just checked your model problem. To be honest, I don't see the connection to MethodOfLines (the code models a DAE problem, what is there to discretize?), @rschiemann1 Method of Lines.jl is a recent development to SciML aimed at showing when MOL is appropriate and when it is not.

The DAE tutorial that is required in MTK should mimic the methological steps and flowchart in https://reference.wolfram.com/language/tutorial/NDSolveDAE.html. How to code a DAE system: parameters, functions, equations, domains, constraints, re-arrange the DAE problem, index-lowering, numerical methods applicable and available in SciML etc. There is a ample section on examples in the Wolfram tutorial and the AkzoNobel example has been implemented in Julia here https://benchmarks.sciml.ai/html/DAE/ChemicalAkzoNobel.html but with no explanation on why and which numerical solution is being used and, again, this was before MethodOfLines.jl.

finmod avatar Apr 09 '22 13:04 finmod

Thanks! Ok, so how should we get this started?

rschiemann1 avatar Oct 11 '22 08:10 rschiemann1

There's already multiple tutorials on this topic in http://methodoflines.sciml.ai/dev/ . Please open a more specific issue on MethodOfLines.jl if there's any issues with those tutorials

ChrisRackauckas avatar Oct 12 '22 21:10 ChrisRackauckas