ldeo-glaciology / nye_eqns_bvp

solving the Nye fowler eqns as boundary value problem
1 stars 0 forks source link

suggested edits to Nye_NQ.m to speed up simulations #7

Closed jkingslake closed 2 years ago

jkingslake commented 3 years ago

Try editing Nye_NQ.m to speed up simulations.

These are small potential speed ups, but because you call that function SO many times it might make an appreciable difference

1. add

Q = y(2,:);
N = y(1,:);
S83 = S_x.^(8/3);

and use these new variables in the calculations.

2. try changing how you deal with the sign of Q so that you can avoid dividing by S83 twice and see if it improves things:

f1 = abs(Q).^3./S83;

dydx = [(sign(Q).*f1 - P.psi)/P.d
    P.e*(P.r-1)*f1 + P.e*S_x.*N.^3 + P.M];

obviously be really careful that this is actually exactly equivalent to the original by testing out the results of both versions.

3. More drastically, you could try neglecting terms including P.e, i.e.

dydx = [(Q.*abs(Q)./S83 - P.psi)/P.d
              P.M];

this is a change to the model, but i think you will find that it only makes a very small difference to the results because P.e is very small generally.

glugeorge commented 3 years ago

The first edit sped up the simulation by a bit (using 100 space grid points and 1000 time steps, sped up by ~10 seconds). The second one somehow made it a tad slower (~15-20 seconds slower). The third one did speed it up and didn't change the results by much, but will not be included as the speedup was quite negligible (a second or two).

jkingslake commented 3 years ago

what was the baseline time (the simulation time before the changes)?

glugeorge commented 3 years ago

Baseline time was around 330 seconds. the fastest with the changes was around 320 seconds.

jkingslake commented 3 years ago

I would expect number 2 to speed things up. Maybe doing a few runs for each test and averaging the time would be a better way of testing the improvement.

But given that the changes are small maybe it's not important to pursue.

glugeorge commented 2 years ago

Switched to discrete solver in new repo: https://github.com/glugeorge/coupled_ice_hydrology