12
$\begingroup$

Usually one would consult a paper or book to find integration points and weights for unit triangle and tetrahedra. I am looking for a method to automatically compute such points and weights. The following Mathematica code example computes integration weights and points for unit line (quad/hexahedron) elements:

unitGaussianQuadraturePoints[points_] := 
  Sort[x /. 
    Solve[Evaluate[LegendreP[points, x] == 0], {x}], ! 
     OrderedQ[N[{#1, #2}]] &];

unitGaussianQuadratureWeights[points_] := 
  Module[{gps, f, int, integr, vars, eqns}, 
   gps = unitGaussianQuadraturePoints[points];
   f[0, 0] := 1;
   f[0., 0] := 1.;
   f[x_, n_] := x^n;
   int = Integrate[f[x, #], x] & /@ Range[0, points - 1];
   integr = Subtract @@@ (int /. x :> {1, -1});
   vars = Table[Unique[c], {Length[gps]}];
   eqns = 
    Table[Plus @@ Thread[Times[vars, f[#, i - 1] & /@ gps]] == 
      integr[[i]], {i, points}];
   Return[(vars /. Solve[eqns, vars])];];


unitGaussianQuadratureWeights[2]

{{1, 1}}

unitGaussianQuadraturePoints[2]

{1/Sqrt[3], -(1/Sqrt[3])}

I am looking for a paper/book that describes algorithmically how this is done for triangles and/or tetrahedra. Can someone point me to some information about this. Thanks.

$\endgroup$
11
  • 1
    $\begingroup$ There's an easier way to do your Gauss-Legendre quadrature rules in Mathematica: {points, weights} = MapThread[Map, {{2 # - 1 &, 2 # &}, Most[NIntegrate`GaussRuleData[n, prec]]}]. $\endgroup$ – J. M. Jan 22 '12 at 16:31
  • $\begingroup$ In any event: have you seen this? $\endgroup$ – J. M. Jan 22 '12 at 16:35
  • $\begingroup$ @J.M, your above proposed method does, unfortunately, not work for prec=Infinity; but thanks for that too. $\endgroup$ – user530 Jan 22 '12 at 17:47
  • 2
    $\begingroup$ In that case, here's a method that works, due to Golub and Welsch: Transpose[MapAt[2(First /@ #)^2 &, Eigensystem[SparseArray[{Band[{2, 1}] -> #, Band[{1, 2}] -> #}, {n, n}]], {2}]] &[Table[k/Sqrt[(2 k - 1)(2 k + 1)], {k, n - 1}]]. $\endgroup$ – J. M. Jan 22 '12 at 17:59
  • 1
    $\begingroup$ Here is the paper by Golub and Welsch. I'll dig through my papers and see if there's something for simplices... $\endgroup$ – J. M. Jan 22 '12 at 23:14
7
$\begingroup$

The Encyclopaedia of Cubature Formulas has an extensive list of techniques for this purpose and associated references.

$\endgroup$
3
$\begingroup$

Here is a paper http://journal.library.iisc.ernet.in/vol200405/paper6/rathod.pdf that describes how to map the unit triangle to the standard 2-square in order to calculate the weights and sampling points for the triangle in terms of Gauss-Legendre points for the standard 2-square.

$\endgroup$
4
  • $\begingroup$ That's an interesting idea, it looks like for n=2 this needs 4 points, for the typical literature reference for triangles for n=2, 3 points are given. Do you know anything about this? $\endgroup$ – user530 Jan 22 '12 at 19:31
  • $\begingroup$ This stems from the fact that they are using a mapping from the triangle to the square. I can't say anything beyond that since I don't work with triangles (I use quadrilaterals), so I don't know what is usually done in practice. I just found the paper and thought it seemed like a pretty straightforward thing to do. $\endgroup$ – James Custer Jan 22 '12 at 19:36
  • $\begingroup$ indeed it is quite straightforward and I'll see that the other papers suggest, but the simplicity for this one and the elegance of using something I already have are a plus for this one. The downside is then the additional function evaluation. Thanks in any case. $\endgroup$ – user530 Jan 22 '12 at 19:42
  • $\begingroup$ another down side is that the points are not symmetrical. $\endgroup$ – user530 Jan 24 '12 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy