I want to create a differential algebraic model by reading information from a file, thus I can only construct the model at run time. But I don’t know how to do this because the example models from documentation of DifferentialEquations.jl are defined before compilation. How should I do this? Any help is warmly welcomed.
What is the use case? How broad of a class of models does your file format want to specify? Why can’t the file be a Julia script?
In general, if you have some class of models you want to support, you can define some file format that expresses those models, read them into a data structure, and have a function that defines the corresponding model from the data structure. It’s hard to be specific about knowing more about what you are trying to accomplish.
But reading a Julia script defining the model is infinitely flexible.
Thanks for your reply!
I am trying to simulate electric circuits, which is in fact solving a set of differential algebraic equations (DAE). The circuits are descriped by SPICE format, which describes the parameters of electric devices (such as resistors, capacitors and mosfets) and their interconnections. The SPICE file is the input of the code I want to develop and out of my control. I think I need to firstly read the SPICE file and construct the DAE, and then solve them using the solvers in julia packages.
The difficulties I encounter is that the examples is predefined upto a freedom of p, but I think I need more freedom so that, say, the rober function in this example is defined at runtime.
So my difficulty is roughly to “translate” the models in SPICE file to julia DAE.
For example, if you have a data structure representing the graph of a simple RLC circuit, you could loop over that data structure inside your function to define the rhs of an ODE.
I think you are thinking of code generation/metaprogramming, but code generation (while possible) is hardly the only option here, and in some ways is the most primitive option (thinking about spitting out code is in some ways easier than thinking more abstractly about data structures).
I would start by thinking of what data structures you would use to represent the kinds of circuits you want to handle. (Handling the entire SPICE format is a tall order — I would start with a small subset.) e.g. figure out the data structure you might use to represent an arbitrary RLC circuit network. Then figure out how you would process this data structure to implement the equations of the corresponding ODE.
Thanks for your thoughtful and enlightening replies! They are really helpful to me.