0025418: Debug output to be limited to OCC development environment
[occt.git] / src / math / math_Crout.cxx
1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 // lpa le 20/08/91
16
17 //#ifndef OCCT_DEBUG
18 #define No_Standard_RangeError
19 #define No_Standard_OutOfRange
20 #define No_Standard_DimensionError
21 //#endif
22
23 #include <math_Crout.ixx>
24 #include <math_NotSquare.hxx>
25 #include <StdFail_NotDone.hxx>
26 #include <math_Vector.hxx>
27
28 math_Crout::math_Crout(const math_Matrix& A, const Standard_Real MinPivot):
29                        InvA(1, A.RowNumber(), 1, A.ColNumber()) 
30 {
31   Standard_Integer i,j,k;
32   Standard_Integer Nctl = A.RowNumber();
33   Standard_Integer lowr = A.LowerRow(), lowc = A.LowerCol();
34   Standard_Real scale;
35
36   math_Matrix L(1, Nctl, 1, Nctl);
37   math_Vector Diag(1, Nctl);
38
39
40   
41   math_NotSquare_Raise_if(Nctl != A.ColNumber(), " ");
42   
43   Det = 1;
44   for (i =1; i <= Nctl; i++) {
45     for (j = 1; j <= i -1; j++) {
46       scale = 0.0;
47       for (k = 1; k <= j-1; k++) {
48         scale += L(i,k)*L(j,k)*Diag(k);
49       }
50       L(i,j) = (A(i+lowr-1,j+lowc-1)-scale)/Diag(j);
51     }
52     scale = 0.0;
53     for (k = 1; k <= i-1; k++) {
54       scale += L(i,k)*L(i,k)*Diag(k);
55     }
56     Diag(i) = A(i+lowr-1,i+lowc-1)-scale;
57     Det *= Diag(i);
58     if (Abs(Diag(i)) <= MinPivot) {
59       Done = Standard_False;
60       return;
61     }
62     L(i,i) = 1.0;
63   }
64
65 // Calcul de l inverse de L:
66 //==========================
67
68   L(1,1) = 1./L(1,1);
69   for (i = 2; i <= Nctl; i++) {
70     for (k = 1; k <= i-1; k++) {
71       scale = 0.0;
72       for (j = k; j <= i-1; j++) {
73         scale += L(i,j)*L(j,k);
74       }
75       L(i,k) = -scale/L(i,i);
76     }
77     L(i,i) = 1./L(i,i);
78   }
79
80 // Calcul de l inverse de Mat:
81 //============================
82
83   for (j = 1; j <= Nctl; j++) {
84     scale = L(j,j)*L(j,j)/Diag(j);
85     for (k = j+1; k <= Nctl; k++) {
86       scale += L(k,j) *L(k,j)/Diag(k);
87     }
88     InvA(j,j) = scale;
89     for (i = j+1; i <= Nctl; i++) {
90       scale = L(i,j) *L(i,i)/Diag(i);
91       for (k = i+1; k <= Nctl; k++) {
92         scale += L(k,j)*L(k,i)/Diag(k);
93       }
94       InvA(i,j) = scale;
95     }
96   }
97   Done = Standard_True;
98 }
99
100
101
102 void math_Crout::Solve(const math_Vector& B, math_Vector& X) const 
103 {
104   StdFail_NotDone_Raise_if(!Done, " ");
105   Standard_DimensionError_Raise_if((B.Length() != InvA.RowNumber()) ||
106                                    (X.Length() != B.Length()), " ");
107   
108   Standard_Integer n = InvA.RowNumber();
109   Standard_Integer lowb = B.Lower(), lowx = X.Lower();
110   Standard_Integer i, j;
111
112   for (i = 1; i <= n; i++) {
113     X(i+lowx-1) = InvA(i, 1)*B(1+lowb-1);
114     for ( j = 2; j <= i; j++) {
115       X(i+lowx-1) += InvA(i, j)*B(j+lowb-1);
116     }
117     for (j = i+1; j <= n; j++) {
118       X(i+lowx-1) += InvA(j,i)*B(j+lowb-1);
119     }
120   }
121 }
122
123 void math_Crout::Dump(Standard_OStream& o) const 
124 {
125   o << "math_Crout ";
126   if(Done) {
127     o << " Status = Done \n";
128   }
129   else {
130     o << " Status = not Done \n";
131   }
132 }
133
134
135
136
137
138
139