ejs5.3 and ejss6.0 solvers behave differently (maybe?)
Paul DeYoung
100 Posts
First thank you to wolfgang and fransisco for a prompt response to my recent post. That post was a question asked that I thought would solve the problem below. I apologize for thinking I understood the issue when I should have described the problem.
I am updating a number of our local ejs simulations to ejss. One involving SHO with friction was working strangely. The amplitude of the oscilation would blow up when the friction coefficients were zero (after a few to a few dozen oscillations depending on dt). To probe this I downloaded an EJS sim from the compadre site simple sho - attached in next post) and found that it worked just fine. I made a stripped down EJSS sim (from scratch, also attached) that is, as far as I can tell, functionally equivalent. The amplitude in the EJSS version always grows over time (less so if the dt is made smaller) in contrast to the ejs version that is very stable and insensitive to reasonable changes in dt. I also tried a number of the algorithms and got the same behavior in all that I tried.
I am guessing the basic solver algorithms are the same in 5.3 and 6.0 which leads me to think that I have missed something in the programming, set up, or some option setting.
Re: ejs5.3 and ejss6.0 solvers behave differently (maybe?) -
Wolfgang
192 Posts
The Java and JavaScript ODE solvers are exactly the same but you have used the ODE solver incorrectly in the JavaScript version of your JavaScript model. In the Java model the SHO acceleration is defined on the ODE evolution page as shown in the screenshot.
a=-k*x/m;
However, in your JavaScript model you compute the acceleration on the Fixed Relations panel. This is incorrect because the fixed relation is computed once at the end of the evolution step. In other words, a constant value of acceleration is used by the algorithm. The Runge-Kutta 4 algorithm then uses the constant incorrect value of the acceleration when it computes the values of the dynamical variables at the 4 intermediate times. The four incorrect intermediates values are then used compute the final values of the dynamical variables.
You must enter the rate equations in the ODE evolution page or in the preliminary code page for the EJS ODE solvers to work correctly.
Re: ejs5.3 and ejss6.0 solvers behave differently (maybe?) -
Cleon Teunissen
29 Posts
In addition to the information provided by Wolfgang
How to decide which statements to place in the 'Evolution Panel' and which to place in the "Fixed Relations' panel let me copy the entire content of the page in the EJS documenation about the 'Fixed Relations' panel:
(Granted, that documentation was last modified in 2009. Also, it would appear the documentation has decayed in some respects. Mathjax was supported in the past, by the looks of it, but not anymore.)
EJS evaluates the statements on the Fixed Relations panel before the first evolution step, and after that between each evolution step.
The Evolution panel and the Fixed Relations panel complement each other. To show how that works out let us take the example of a simulation that works with position and velocity as variables for calculation of the dynamics, in which the kinetic energy is also calculated, for displaying that in the view. Then the correct place for calculating the kinetic energy is on the Fixed Relations panel.
More generally, Fixed Relations are expressed explicitly by expressions like: {$$ x_i = g_i(x_1,x_2,\dots,x_{i-1},x_{i+1},\dots,x_n) $$} where, as you can see, each variable appears only on one side of the equation.
Using again the example of a simulation that works with position and velocity as variables, with kinetic energy calculated on the Fixed Relations panel:
If the Evolution evaluates ODEs then what needs to be in the Evolution panel are the equations in which the current position and velocity are the input for calculating the next position and velocity. The kinetic energy is not input for calculating the next position and velocity, so it doesn't need to be in the Evolution panel. If the user pauses the simulation and alters one of the dynamic variables, then the kinetic energy must immediately be recalculated, it would not look good if updating the kinetic energy would have to wait until the first evolution step has been calculated.
So while the statements in the Evolution panel and the Fixed Relations are similar (both deal with a change in one variable produced by changes in other variables), there are clear criteria to decide whether a particular calculation belongs in the Evolution panel or the Fixed Relations panel.