jonapost / field_propagation

Module for integrating a track's trajectory in a field, whether magnetic, electric, combined electromagnetic, or also including gravity or other forces.
6 stars 20 forks source link

Compare accuracy and performance of Nystrom steppers for quadrupole field #10

Open jonapost opened 9 years ago

jonapost commented 9 years ago

Compare the error of the position, momentum and number of field evaluations in new Nystrom steppers versus an established stepper ( ClassicalRK4 or CashKarpRKF45 ) and potentially a representative new non-Nystrom stepper.

( Issue to group these comparisons, and separate from other topics. ) Please add new information and results below.

jonapost commented 9 years ago

Copying the last information from topic #8, posted by Jason , to provide a starting point.

"Compute Step Size is 2000 mm. This is with all the geometry in tPMF, so intersections are checked for etc... Error would be lower in general without corrections for intersections with volumes." snipped to focus on this topic "These similar plots but for the Quadropole Mag field:

position_step_size_2000mm_geometryon

momentum_step_size_2000mm_geometryon

functioncalls_step_size_2000mm_geometryon

trajectory_3dplot_with_geometry

The number of function calls used by the Murua stepper shoots up after around 4000 mm, which is when the trajectory starts to double back on itself. I haven't had a chance to think about why that happens?"

jsuagee commented 9 years ago

The previous run started at the origin, which might be why the error is so large. I ran the test again, but this time I generated the base line trajectory with tPMF. At first this made no difference, but then I started looking at other starting points. Here are some graphics of two other starting points (the first two I tried actually):

(100 mm, 100 mm, 0.0 mm): This is all the steppers combined, which has a large error position_err__all_steppers-no_geometry

but the actual error of the Murua stepper is much smaller than that position_err__only_murua-no_geometry

Here is a plot of the number of function calls: function_calls__all_steppers-no_geometry

And here is the second point (-2000._mm,1300._mm,300.*mm): position_err__all_steppers-no_geometry with just the Murua stepper: position_err__only_murua-no_geometry

and the function calls plot: function_calls__all_steppers-no_geometry

jsuagee commented 9 years ago

The baseline for the following plots was from using tPMF, with geometry turned on. (previously I had commented out a section of code in tPMF in which all but the world volumes where placed.) Position error for starting position: (100mm,100mm,0mm) position_err__all_steppers-geometry_on Relative Position error (substituted the baseline solution for the true solution in Error/Magnitude True Solution): position_rel_err__all_steppers-geometry_on

Notice the big jumps that occur at intersection points. It seems that the Murua stepper might have more difficulties when going through an intersection point. Now for Momentum: momentum_err__all_steppers-geometry_on momentum_rel_err__all_steppers-geometry_on

Now the relative errors for starting point (-2000.mm,1300.mm,300.*mm):

position_rel_err__all_steppers-no_geometry momentum_rel_err__all_steppers-no_geometry

There were no intersections in this trajectory. Here is the relative error for just the Murua stepper since it is of a much smaller scale: position_rel_err__only_murua-no_geometry

momentum_rel_err__only_murua-no_geometry

I am now going to try a different baseline solution other than Fine45.

jsuagee commented 9 years ago

OK, I made a second version of the interpolation_error program, errror_by_stepper, which calculates an "interpolant" by just calling the stepper to make up the extra distance. The results are pretty much similar when averaged out (all of these are with the geometry and intersection locators turned on): Relative position error for starting position: (100mm,100mm,0mm): position_rel_err__all_steppers-geometry_on

momentum_rel_err__all_steppers-geometry_on

And now for just the Murua stepper: position_rel_err__only_murua-geometry_on momentum_rel_err__only_murua-geometry_on

Now for the relative errors for the point (-2000.mm,1300.mm,300.*mm): position_rel_err__all_steppers-geometry_on momentum_rel_err__all_steppers-geometry_on position_rel_err__only_murua-geometry_on momentum_rel_err__only_murua-geometry_on

So it seems that interpolation is a better way to estimate error for points located in between step endpoints. I tried this method because there is no ready interpolant available for ClassicalRK4.

jsuagee commented 9 years ago

For the above plots MinEps = 5e-05 and MaxEps = 0.001. These were the default values set in tPMF.

For the baseline solution I overrided the default values and set them equal to maxEpsStep= 0.00001; minEpsStep= 2.5e-10

They can be easily changed though.