1 // Created on: 2005-12-19
2 // Created by: Julia GERASIMOVA
3 // Copyright (c) 2005-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <math_ComputeGaussPointsAndWeights.ixx>
24 #include <math_EigenValuesSearcher.hxx>
25 #include <math_Array1OfValueAndWeight.hxx>
26 #include <math_CompareOfValueAndWeight.hxx>
27 #include <math_QuickSortOfValueAndWeight.hxx>
28 #include <Standard_ErrorHandler.hxx>
30 math_ComputeGaussPointsAndWeights::math_ComputeGaussPointsAndWeights(const Standard_Integer Number)
32 myIsDone = Standard_False;
35 myPoints = new TColStd_HArray1OfReal(1, Number);
36 myWeights = new TColStd_HArray1OfReal(1, Number);
40 TColStd_Array1OfReal aDiag(1, Number);
41 TColStd_Array1OfReal aSubDiag(1, Number);
43 //Initialization of a real symmetric tridiagonal matrix for
44 //computation of Gauss quadrature.
46 for (i = 1; i <= Number; i++) {
52 Standard_Integer sqrIm1 = (i-1)*(i-1);
53 aSubDiag(i) = sqrIm1/(4.*sqrIm1 - 1);
54 aSubDiag(i) = Sqrt(aSubDiag(i));
58 // Compute eigen values.
59 math_EigenValuesSearcher EVsearch(aDiag, aSubDiag);
61 if (EVsearch.IsDone()) {
62 math_Array1OfValueAndWeight VWarray(1, Number);
63 for (i = 1; i <= Number; i++) {
64 math_Vector anEigenVector = EVsearch.EigenVector(i);
65 Standard_Real aWeight = anEigenVector(1);
66 aWeight = 2. * aWeight * aWeight;
67 math_ValueAndWeight EVW( EVsearch.EigenValue(i), aWeight );
71 math_CompareOfValueAndWeight theComparator;
72 math_QuickSortOfValueAndWeight::Sort(VWarray, theComparator);
74 for (i = 1; i <= Number; i++) {
75 myPoints->ChangeValue(i) = VWarray(i).Value();
76 myWeights->ChangeValue(i) = VWarray(i).Weight();
78 myIsDone = Standard_True;
80 } catch (Standard_Failure) {
84 Standard_Boolean math_ComputeGaussPointsAndWeights::IsDone() const
89 math_Vector math_ComputeGaussPointsAndWeights::Points() const
91 Standard_Integer Number = myPoints->Length();
92 math_Vector thePoints(1, Number);
93 for (Standard_Integer i = 1; i <= Number; i++)
94 thePoints(i) = myPoints->Value(i);
99 math_Vector math_ComputeGaussPointsAndWeights::Weights() const
101 Standard_Integer Number = myWeights->Length();
102 math_Vector theWeights(1, Number);
103 for (Standard_Integer i = 1; i <= Number; i++)
104 theWeights(i) = myWeights->Value(i);