I deal with a lot of simulation using julia. Actually, I am building an entire satellite simulator for validation of mission operational concepts in Pre-Phase A in julia.
I always have trouble to deal with many variables in distinct instants. For example, to integrate using Runge-Kutta (4th order) I need to compute each variable in four instants. Hence, I ended up with something like this:
q_k_1, q_k_2, q_k_3, q_k_4.
The biggest problem is that each variable in each of those instants is a function of many (MANY) other variables of those instants. So, I had something like that:
q_k_1 = a_k_1*b_k_1 + c_k_1*exp(d_k_1) q_k_2 = a_k_2*b_k_2 + c_k_2*exp(d_k_2) q_k_3 = a_k_3*b_k_3 + c_k_3*exp(d_k_3) q_k_4 = a_k_4*b_k_4 + c_k_4*exp(d_k_4)
Hence, I decided to create a very simple package, called
Workspace.jl, to make my life easier. This package defines a workspace, which is an array of variables, that can be loaded and saved from the global workspace. So, I can do things like:
ws_k_1 = @create_ws ws_k_2 = @create_ws ws_k_3 = @create_ws ws_k_4 = @create_ws ws_k_1[:a] = # Compute the value of variable a_k_1 ws_k_2[:a] = # Compute the value of variable a_k_2 # etc. ws_k_1[:q] = # Initialize the variable q_k_1 # etc. for w in (ws_k_1,ws_k_2,ws_k_3,ws_k_4) @load_ws w q = a*b + c*exp(d) @save_ws! w end
This was a simple example, but it really transformed my code into something much more readable. Well, I know I lose performance because the
@save_ws! involves too much writing. But, in the end, the gain in maintainability is bigger
The project is at the beginning. The implementation is ugly (I’m not a good julia programmer), but I think I can use some help / advice from the community. The URL is: https://github.com/ronisbr/Workspace.jl