Virtual Polywell

Discuss how polywell fusion works; share theoretical questions and answers.

Moderators: tonybarry, MSimon

scareduck
Posts: 552
Joined: Wed Oct 17, 2007 5:03 am

Post by scareduck »

drmike wrote:Sounds like way too much fun! Always double check Numerical Recipes, I've run into lots of bugs in their code. But the theory is always right.
Hah, well, okay. I'll keep my eyes peeled to the extent I can.
PARI/GP is a really good symbolic/infinite precision package. And I've got a home brew floating point package which has 32 bit exponent and 256 bit mantissa. Hmmm, I guess I never ran that on a 64 bit processor, no reason I can't double that if I want to. Makes more sense to go with PARI though, lots of mathematicians use that and it is well debugged.
I was looking at using the GNU Multiple Precision Library, which I assume is widely used. (Edit: I see PARI/GP is a symbolic package on top of GMP.) One of the first things they tell you is
GMP is very often miscompiled! We are seeing ever increasing problems with miscompilations of the GMP code. It has now come to the point where a compiler should be assumed to miscompile GMP. Please never use your newly compiled libgmp.a or libgmp.so without first running make check. If it doesn't complete without errors, don't trust the library. Please try another compiler release, or change optimization flags until it works. If you have the skill to isolate the problem, please report it to us if it is a GMP bug; else to the compiler vendor. (The compilers that cause problems are HP's unbundled compilers and GCC, in particular Apple's GCC releases.)
Everything I've encountered so far in this area seems to have sand traps left and right!

Roger
Posts: 788
Joined: Fri Jul 06, 2007 2:03 am
Location: Metro NY

Post by Roger »

scareduck wrote: Everything I've encountered so far in this area seems to have sand traps left and right!
So, putting away the 1 wood and taking a 3 iron might be called for, an accurate 3 iron shot will put you in the fairway....

:-)
I like the p-B11 resonance peak at 50 KV acceleration. In2 years we'll know.

scareduck
Posts: 552
Joined: Wed Oct 17, 2007 5:03 am

Post by scareduck »

As it happens, Numerical Recipes just went to its 3rd edition, with C++ examples now, and "lifetime" subscriptions to the electronic version. I wonder if they've corrected the bugs you found in the earlier editions.

drmike
Posts: 825
Joined: Sat Jul 14, 2007 11:54 pm
Contact:

Post by drmike »

You would hope so. Part of the reason I wrote my own floating point was all the sand traps. I figured it was just a playtoy anyway, and I'd rather fix my own bugs than somebody elses!

Nothing is ever bug free, the real trick is to call it up front as a feature!
:D

drmike
Posts: 825
Joined: Sat Jul 14, 2007 11:54 pm
Contact:

Post by drmike »

I put the start of the next model up on virtual_polywell_take3.pdf but I realized I only did the derivation for particles on a face centered electron source and not for one on a cusp. So I've got a little more pencil and paper work to do yet before I'm done even writing things up let alone coding.

Let me know if even makes sense. I really like the simplicity of this method, but it will begin to break down in a hurry when ionization is added.

scareduck
Posts: 552
Joined: Wed Oct 17, 2007 5:03 am

Post by scareduck »

I tried installing PARI on my home machine, to no avail; it won't even get out of the Configure module, which is odd, because it does seem to know about and test for the "missing" functions it complains about (which are available in libm and libdl); it just doesn't succeed in finding them. I'll write up something to one of the PARI lists and see if they can help at all.

I haven't taken a look at your latest PDF, and I'm pretty sure I wouldn't be much help if I did understand the math clearly. Will get to it soonest.

drmike
Posts: 825
Joined: Sat Jul 14, 2007 11:54 pm
Contact:

Post by drmike »

I got PARI to run once, a long time ago on a 400 MHz machine. The community is pretty good, I got responses fairly fast from the usenet groups. Grad students have time to be friendly!

scareduck
Posts: 552
Joined: Wed Oct 17, 2007 5:03 am

Post by scareduck »

Sometimes, you just get blind lucky. I found a package for doing the exact calculations I was looking for ... I think.

http://www.alglib.net/integral/gq/glegendre.php

Have to do some more reading, but it looks like this should graft into the GMP library very nicely.

drmike
Posts: 825
Joined: Sat Jul 14, 2007 11:54 pm
Contact:

Post by drmike »

The net is amazing. Good luck!

scareduck
Posts: 552
Joined: Wed Oct 17, 2007 5:03 am

Post by scareduck »

... or not. I converted it to C and, well, no luck so far. Here's what it generated for n=15 and machine epsilon = 2e-17, just using IEEE doubles to see if I'm on the right track (abscissas on the left, weights on the right):

Code: Select all

n=15
         0.9879925180204854884281  0.0307532419961148821563
         0.9372733924007059513883  0.0703660474881080549858
         0.8482065834104272061822  0.1071592204671719394948
         0.7244177313601700696211  0.1395706779261543240001
         0.5709721726085388304739  0.1662692058169939757217
         0.3941513470775633853904  0.1861610000155621003071
         0.2011940939974345421426  0.1984314853271115786093
        -0.0000000000000000000000  0.2025782419255612865072
        -0.2011940939974345421426  0.1984314853271115786093
        -0.3941513470775633853904  0.1861610000155621003071
        -0.5709721726085388304739  0.1662692058169939757217
        -0.7244177313601700696211  0.1395706779261543240001
        -0.8482065834104272061822  0.1071592204671719394948
        -0.9372733924007059513883  0.0703660474881080549858
        -0.9879925180204854884281  0.0307532419961148821563
Not even close; the constants from the GSL library, from qk15:

Code: Select all

static const double xgk[8] =    /* abscissae of the 15-point kronrod rule */
{
  0.991455371120812639206854697526329,
  0.949107912342758524526189684047851,
  0.864864423359769072789712788640926,
  0.741531185599394439863864773280788,
  0.586087235467691130294144838258730,
  0.405845151377397166906606412076961,
  0.207784955007898467600689403773245,
  0.000000000000000000000000000000000
};
I have this bad feeling I'm massively misunderstanding what they're trying to do here, or else I've somehow got the computations wrong because the interval is different ( over [-1,1] for Gauss-Legendre, vs. ?? for Gauss-Kronrod).

From what I can tell, the main point of using Gauss-Kronrod (or any of the Gauss-derived quadrature methods) is that it's a lot faster than the Simpson method, plus it comes with its own error estimate built in. (Kronrod's stroke of genius was designing the sample points such that the abscissas and weights would overlap between the sample and the error estimate.) I may change my mind and try to do this using Simpson's method just because I can at least get the darn thing working!

I may ask the guys who built the qd library if they've ever attempted to do this or if anyone they were aware of had done so.

drmike
Posts: 825
Joined: Sat Jul 14, 2007 11:54 pm
Contact:

Post by drmike »

At least your results are symmetric! I would assume that Gauss-Kronrod is totally different than Legendre - the weights have to be correctly orthogonal. If you can compare your formulas and results to the Wikipedia page you pointed to, you'll know you're on the right track.

Details always matter, and I think the "eureka" moment of when all the details finally click and you _know_ you've got the right answer is worth the frustration of all the time you know you don't. If it hasn't already been done for quad-size numbers, it needs to be.

I don't know who the quote is attributable to, but I like "Technology marches on, over you or through you. Take your pick." I'd say keep marching on!

scareduck
Posts: 552
Joined: Wed Oct 17, 2007 5:03 am

Post by scareduck »

I transcribed the example on p. 152 of Numerical Recipes so that it was right and proper C. (For some reason in the second edition they couldn't quite shake the old FORTRAN notion of array indices starting at 1!) I got (mostly) the same abscissas, which makes me feel weirdly triumphant in the sense that I now have a feeling that if I grope through the GSL code, I'll come up with a reason why their numbers are different. (There are some differences in alignment that are probably leftovers from my translation.) From what I've read so far in Recipes, there seem to be two reasons that might be likely:

1) A different interval. Gauss-Legendre integration wants to run over the interval -1<x<1.
2) A different W(x). Gaussian quadratures are all sums of the function f(x)W(x), where the f(x) is the function you hope to numerically integrate, and W(x) is a function of convenience; for Gauss-Legendre, W(x)=1, which makes it the simplest of these functions, but there are others. (Gauss-Chebychev, for instance, uses W(x) = (1-x^2)^-1/2.)

From what I can tell, Gauss-Kronrod doesn't say anything about what the W(x) should be, so you can use Gauss-Jacobi, Gauss-Legendre, etc. so long as you pick your abscissas and weights consistently.

drmike
Posts: 825
Joined: Sat Jul 14, 2007 11:54 pm
Contact:

Post by drmike »

I think I see, my first reading was that W(x) was special for Kronrod. It's not so much the function as the points you pick have to be consistent. The major advantage is that you get a true error estimate.

Slow but sure. While I was grinding through the formulas for an electron source on a cusp I realized I'd goofed and had to start over. Twice! But I think I have the right answer now, so next step is to type it up and post it, then see if I can follow electron blobs. It'll be interesting if any of this even comes within an order of magnitude of any measurements.

Keep on keepin' on!!
:D

scareduck
Posts: 552
Joined: Wed Oct 17, 2007 5:03 am

Post by scareduck »

drmike wrote:I think I see, my first reading was that W(x) was special for Kronrod. It's not so much the function as the points you pick have to be consistent. The major advantage is that you get a true error estimate.
Yup, and you get to re-use your previous abscissas/weights along the way, saving yourself considerable trouble in so doing.
Slow but sure.
Hey, I've got the first part down pat! :-)
While I was grinding through the formulas for an electron source on a cusp I realized I'd goofed and had to start over. Twice! But I think I have the right answer now, so next step is to type it up and post it, then see if I can follow electron blobs. It'll be interesting if any of this even comes within an order of magnitude of any measurements.
One thing that occurred to me while I was looking at the GSL code is that there are a number of different quadrature modules hiding in there, and at least one of them deals with discontinuous cases -- qags, which allows for singularities in the range. If there are zeros appearing in the denominator somewhere, maybe you have an application for this.
Keep on keepin' on!!
:D
I intend to do just that.

scareduck
Posts: 552
Joined: Wed Oct 17, 2007 5:03 am

Post by scareduck »

An aside about Numerical Recipes: wow.
I've found that Numerical Recipes provide just enough information for a person to get himself into trouble, because after reading NR, one thinks that one understands what's going on. The one saving grace of NR is that it usually provides references; after one has been burned enough times, one learns to go straight to the references :-).

Post Reply