Commit 3ec85791 authored by graham's avatar graham
Browse files

Stabilising division by p.

parent 13bddac8
...@@ -71,9 +71,10 @@ scalar pitchForkRing::energy(const vector r) const ...@@ -71,9 +71,10 @@ scalar pitchForkRing::energy(const vector r) const
{ {
scalar p = sqrt(r.x()*r.x() + r.y()*r.y()); scalar p = sqrt(r.x()*r.x() + r.y()*r.y());
scalar pMinusRSqr = (p - rOrbit_)*(p - rOrbit_); scalar pMinusRSqr = sqr(p - rOrbit_);
return -0.5 * mu_ * pMinusRSqr return
-0.5 * mu_ * pMinusRSqr
+ 0.25 * pMinusRSqr * pMinusRSqr + 0.25 * pMinusRSqr * pMinusRSqr
+ 0.5 * alpha_ * r.z() * r.z(); + 0.5 * alpha_ * r.z() * r.z();
} }
...@@ -87,9 +88,9 @@ vector pitchForkRing::force(const vector r) const ...@@ -87,9 +88,9 @@ vector pitchForkRing::force(const vector r) const
return vector return vector
( (
(mu_ - pMinusR * pMinusR) * pMinusR * r.x()/p, (mu_ - sqr(pMinusR)) * pMinusR * r.x()/(p + VSMALL),
(mu_ - pMinusR * pMinusR) * pMinusR * r.y()/p, (mu_ - sqr(pMinusR)) * pMinusR * r.y()/(p + VSMALL),
-alpha_ * r.z() - alpha_ * r.z()
); );
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment