0030611: Coding Rules - eliminate GCC compiler warnings -Wcatch-value
[occt.git] / src / math / math_ComputeGaussPointsAndWeights.cxx
CommitLineData
b311480e 1// Created on: 2005-12-19
2// Created by: Julia GERASIMOVA
973c2be1 3// Copyright (c) 2005-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
7fd59977 17#include <math_Array1OfValueAndWeight.hxx>
42cf5bc1 18#include <math_ComputeGaussPointsAndWeights.hxx>
19#include <math_EigenValuesSearcher.hxx>
7fd59977 20#include <Standard_ErrorHandler.hxx>
21
e35db416 22#include <algorithm>
7fd59977 23math_ComputeGaussPointsAndWeights::math_ComputeGaussPointsAndWeights(const Standard_Integer Number)
24{
25 myIsDone = Standard_False;
26
27 try {
28 myPoints = new TColStd_HArray1OfReal(1, Number);
29 myWeights = new TColStd_HArray1OfReal(1, Number);
30
31 Standard_Integer i;
32
33 TColStd_Array1OfReal aDiag(1, Number);
34 TColStd_Array1OfReal aSubDiag(1, Number);
35
36 //Initialization of a real symmetric tridiagonal matrix for
37 //computation of Gauss quadrature.
38
39 for (i = 1; i <= Number; i++) {
40 aDiag(i) = 0.;
41
42 if (i == 1)
43 aSubDiag(i) = 0.;
44 else {
45 Standard_Integer sqrIm1 = (i-1)*(i-1);
46 aSubDiag(i) = sqrIm1/(4.*sqrIm1 - 1);
47 aSubDiag(i) = Sqrt(aSubDiag(i));
48 }
49 }
50
51 // Compute eigen values.
52 math_EigenValuesSearcher EVsearch(aDiag, aSubDiag);
53
54 if (EVsearch.IsDone()) {
55 math_Array1OfValueAndWeight VWarray(1, Number);
56 for (i = 1; i <= Number; i++) {
57 math_Vector anEigenVector = EVsearch.EigenVector(i);
58 Standard_Real aWeight = anEigenVector(1);
59 aWeight = 2. * aWeight * aWeight;
60 math_ValueAndWeight EVW( EVsearch.EigenValue(i), aWeight );
61 VWarray(i) = EVW;
62 }
63
e35db416 64 std::sort (VWarray.begin(), VWarray.end());
7fd59977 65
66 for (i = 1; i <= Number; i++) {
67 myPoints->ChangeValue(i) = VWarray(i).Value();
68 myWeights->ChangeValue(i) = VWarray(i).Weight();
69 }
70 myIsDone = Standard_True;
71 }
a738b534 72 } catch (Standard_Failure const&) {
7fd59977 73 }
74}
75
76Standard_Boolean math_ComputeGaussPointsAndWeights::IsDone() const
77{
78 return myIsDone;
79}
80
81math_Vector math_ComputeGaussPointsAndWeights::Points() const
82{
83 Standard_Integer Number = myPoints->Length();
84 math_Vector thePoints(1, Number);
85 for (Standard_Integer i = 1; i <= Number; i++)
86 thePoints(i) = myPoints->Value(i);
87
88 return thePoints;
89}
90
91math_Vector math_ComputeGaussPointsAndWeights::Weights() const
92{
93 Standard_Integer Number = myWeights->Length();
94 math_Vector theWeights(1, Number);
95 for (Standard_Integer i = 1; i <= Number; i++)
96 theWeights(i) = myWeights->Value(i);
97
98 return theWeights;
99}