Hi! I 've been using EJS ever since 2009 when I was in Spain, and I'd like to encourage you to keep up doing such a briliant work. Nevertheless, this is the first time I use this forum...
I 'd like to make a question regarding the Evolution page in EJS. First of all, is there any problem if someone uses both pages of code and ODEs in the same simulation? In most of the cases I use a page sequence like...
Page of Code--Page of ODEs--Page of Code--Page of ODEs ... etc
so I organize my preliminary code before specific ODEs whenever it is necessary. Is this OK? (I guess I could use the preliminary code section of ODE pages instead...).
Moreover, let's say that I want to simulate a 2D grid of nxm devices and need a DE to describe the response of each device, in every time step. Is there any way to do this without having to declare nxm different DEs? Is there any kind of iteration I could use instead? (Maybe PJ could be helpful?) The devices are identical, so the DEs are all the same too, except for some different coefficient values that I pass as parameters to the method I use in the ODEs page.
Re: Page of Code Vs Page of ODEs in EJS Evolution -
Francisco Esquembre
237 Posts
Ioannis,
You can (and it certainly makes sense) use pages of code and ODEs in the same simulation. However, there are a couple of precautions that you need to observe: - do not use two pages of ODEs with the same independent variable, or you will have this variable increased twice at each evolution step, which I doubt you want to. - do not use the pages of code as preliminary code but rather a 'preparatory code'. The difference is that preliminary code can be executed several times with intermediate values of the variables within the process of solving the equations (actually, this is the case for all provided solvers which -except Euler- evaluate the rate more than once to step the solver). On the contrary, pages of code previous to the ODE page will be executed only once with the values of the variables before entering the solving process.
With respect to the second question, if I understood it correctly, I see two possibilities: - use a one-dimensional array of states, one for each of the devices (recommended) - declare one ODE and do not let the evolution run, but manage the ODE explicitly by using object-oriented programming. This is advanced, but you can see an example of how to do this in the Lorenz attractor example at http://www.compadre.org/osp/items/detail.cfm?ID=8986 Notice how the author runs the ODEs in the drawAttractor() custom method to display the attractor before actually playing the evolution.
You are welcomed. And thanks for your kind words on EJS.
Re: Re: Page of Code Vs Page of ODEs in EJS Evolution -
Ioannis Vourkas
4 Posts
Hi again and thanks for the usefull tips, though I have a few more doubts...
In the EJS model section, all declared pages run sequentially depending on the order they are found,? That is...if I have some pages declared in the following manner..
Page of Code 1 -- Page of ODEs 1 -- Page of Code 2 -- Page of ODEs 2 -- Page of Code 3 etc...
what is exactly the execution order?
Furthermore, regarding my second question in the previous post, I checked out the recomended code example...where only one page of ODEs is declared. So the author uses the _step() to make a preparatory simulation and then resets the variables of interest...but what if I have both pages of code and pages of ODEs? The _step() executes everything that is found inside the EJS Model, right? Nevertheless, I seem to understand that I could appropriately update the independent variable and coefficients of an ODE and use the _step() to control simulation execution as many times as I like, without having to declare a bunch of ODEs describing all of my devices...
Re: Re: Re: Page of Code Vs Page of ODEs in EJS Evolution -
Francisco Esquembre
237 Posts
Ioannis,
The order is always from left to right. (Except for Custom pages, of course, whose methods must be invoked explicitly.)
If you want to only step the solver, then you must enter secret/advanced/adventurous land :-). Use the method: _getODE("Lorenz ODE").step(); where you must replace "Lorenz ODE" by the name of your page of ODEs that you want to step. The _getODE(String name) gives you direct access to the ODE. This is an object of the class EJSODE. You can find a complete JavaDoc set of pages for classes used internally by EJS at:
http://fem.um.es/Javadoc/OSP_EJS/index.html
Finally, yes. I assume that used carefully you can tweak EJS to do what you want.