b311480e |
1 | // Created on: 1998-11-06 |
2 | // Created by: Igor FEOKTISTOV |
3 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
7fd59977 |
18 | #include <FEmTool_ElementsOfRefMatrix.hxx> |
42cf5bc1 |
19 | #include <FEmTool_LinearFlexion.hxx> |
20 | #include <math.hxx> |
21 | #include <math_GaussSetIntegration.hxx> |
7fd59977 |
22 | #include <math_IntegerVector.hxx> |
42cf5bc1 |
23 | #include <math_Matrix.hxx> |
7fd59977 |
24 | #include <math_Vector.hxx> |
42cf5bc1 |
25 | #include <PLib.hxx> |
26 | #include <PLib_HermitJacobi.hxx> |
27 | #include <PLib_JacobiPolynomial.hxx> |
7fd59977 |
28 | #include <Standard_ConstructionError.hxx> |
42cf5bc1 |
29 | #include <Standard_DomainError.hxx> |
30 | #include <Standard_NotImplemented.hxx> |
31 | #include <Standard_Type.hxx> |
32 | #include <TColStd_HArray2OfInteger.hxx> |
33 | #include <TColStd_HArray2OfReal.hxx> |
7fd59977 |
34 | |
35 | //======================================================================= |
36 | //function : FEmTool_LinearFlexion |
37 | //purpose : |
38 | //======================================================================= |
39 | FEmTool_LinearFlexion::FEmTool_LinearFlexion(const Standard_Integer WorkDegree, |
40 | const GeomAbs_Shape ConstraintOrder) |
41 | : RefMatrix(0,WorkDegree,0,WorkDegree) |
42 | { |
43 | static Standard_Integer Order = -333, WDeg = 14; |
44 | static math_Vector MatrixElemts(0, ((WDeg+2)*(WDeg+1))/2 -1 ); |
45 | |
46 | myOrder = PLib::NivConstr(ConstraintOrder); |
47 | |
48 | if (myOrder != Order) { |
49 | //Calculating RefMatrix |
50 | if (WorkDegree > WDeg) Standard_ConstructionError::Raise("Degree too high"); |
51 | Order = myOrder; |
52 | Standard_Integer DerOrder = 2; |
53 | Handle(PLib_HermitJacobi) theBase = new PLib_HermitJacobi(WDeg, ConstraintOrder); |
54 | FEmTool_ElementsOfRefMatrix Elem = FEmTool_ElementsOfRefMatrix(theBase, DerOrder); |
55 | Standard_Integer maxDegree = WDeg+1; |
51740958 |
56 | math_IntegerVector anOrder(1,1,Min(4*(maxDegree/2+1),math::GaussPointsMax())); |
7fd59977 |
57 | math_Vector Lower(1,1,-1.), Upper(1,1,1.); |
51740958 |
58 | math_GaussSetIntegration anInt(Elem, Lower, Upper, anOrder); |
7fd59977 |
59 | |
60 | MatrixElemts = anInt.Value(); |
61 | } |
62 | |
63 | Standard_Integer i, j, ii, jj; |
64 | for(ii = i = 0; i <= WorkDegree; i++) { |
65 | RefMatrix(i, i) = MatrixElemts(ii); |
66 | for(j = i+1, jj = ii+1; j <= WorkDegree; j++, jj++) { |
67 | RefMatrix(j, i) = RefMatrix(i, j) = MatrixElemts(jj); |
68 | } |
69 | ii += WDeg+1-i; |
70 | } |
71 | } |
72 | |
73 | //======================================================================= |
74 | //function : DependenceTable |
75 | //purpose : |
76 | //======================================================================= |
77 | Handle(TColStd_HArray2OfInteger) FEmTool_LinearFlexion::DependenceTable() const |
78 | { |
79 | if(myCoeff.IsNull()) Standard_DomainError::Raise("FEmTool_LinearFlexion::DependenceTable"); |
80 | |
81 | Handle(TColStd_HArray2OfInteger) DepTab = |
82 | new TColStd_HArray2OfInteger(myCoeff->LowerCol(), myCoeff->UpperCol(), |
83 | myCoeff->LowerCol(), myCoeff->UpperCol(),0); |
84 | Standard_Integer i; |
85 | for(i = myCoeff->LowerCol(); i <= myCoeff->UpperCol(); i++) DepTab->SetValue(i,i,1); |
86 | |
87 | return DepTab; |
88 | } |
89 | |
90 | |
91 | |
92 | //======================================================================= |
93 | //function : Value |
94 | //purpose : |
95 | //======================================================================= |
96 | Standard_Real FEmTool_LinearFlexion::Value() |
97 | { |
98 | Standard_Integer deg = Min(myCoeff->ColLength() - 1, RefMatrix.UpperRow()), |
99 | i, j, j0 = myCoeff->LowerRow(), degH = Min(2*myOrder+1, deg), |
100 | NbDim = myCoeff->RowLength(), dim; |
101 | |
102 | TColStd_Array2OfReal NewCoeff( 1, NbDim, 0, deg); |
103 | |
104 | Standard_Real coeff = (myLast - myFirst)/2., cteh3 = 2./Pow(coeff,3), |
105 | mfact, Jline; |
106 | |
107 | Standard_Integer k1; |
108 | |
109 | Standard_Real J = 0.; |
110 | |
111 | for(i = 0; i <= degH; i++) { |
112 | k1 = (i <= myOrder)? i : i - myOrder - 1; |
113 | mfact = Pow(coeff,k1); |
114 | for(dim = 1; dim <= NbDim; dim++) |
115 | NewCoeff(dim, i) = myCoeff->Value(j0 + i, dim) * mfact; |
116 | } |
117 | |
118 | for(i = degH + 1; i <= deg; i++) { |
119 | for(dim = 1; dim <= NbDim; dim++) |
120 | NewCoeff(dim, i) = myCoeff->Value(j0 + i, dim); |
121 | } |
122 | |
123 | for(dim = 1; dim <= NbDim; dim++) { |
124 | for(i = 0; i <= deg; i++) { |
125 | Jline = 0.5 * RefMatrix(i, i) * NewCoeff(dim, i); |
126 | for(j = 0; j < i; j++) |
127 | Jline += RefMatrix(i, j) * NewCoeff(dim, j); |
128 | J += Jline * NewCoeff(dim, i); |
129 | } |
130 | } |
131 | |
132 | if(J < 0.) J = 0.; |
133 | return cteh3*J; |
134 | |
135 | } |
136 | |
137 | //======================================================================= |
138 | //function : Hessian |
139 | //purpose : |
140 | //======================================================================= |
141 | |
142 | void FEmTool_LinearFlexion::Hessian(const Standard_Integer Dimension1, |
143 | const Standard_Integer Dimension2, math_Matrix& H) |
144 | { |
145 | |
146 | Handle(TColStd_HArray2OfInteger) DepTab = DependenceTable(); |
147 | |
148 | if(Dimension1 < DepTab->LowerRow() || Dimension1 > DepTab->UpperRow() || |
149 | Dimension2 < DepTab->LowerCol() || Dimension2 > DepTab->UpperCol()) |
150 | Standard_OutOfRange::Raise("FEmTool_LinearJerk::Hessian"); |
151 | |
152 | if(DepTab->Value(Dimension1,Dimension2) == 0) |
153 | Standard_DomainError::Raise("FEmTool_LinearJerk::Hessian"); |
154 | |
155 | Standard_Integer deg = Min(RefMatrix.UpperRow(), H.RowNumber() - 1), degH = Min(2*myOrder+1, deg); |
156 | |
157 | Standard_Real coeff = (myLast - myFirst)/2., cteh3 = 2./Pow(coeff,3), mfact; |
158 | Standard_Integer k1, k2, i, j; |
159 | |
160 | H.Init(0.); |
161 | |
162 | for(i = 0; i <= degH; i++) { |
163 | k1 = (i <= myOrder)? i : i - myOrder - 1; |
164 | mfact = Pow(coeff,k1)*cteh3; |
165 | // Hermite*Hermite part of matrix |
166 | for(j = i; j <= degH; j++) { |
167 | k2 = (j <= myOrder)? j : j - myOrder - 1; |
168 | H(i, j) = mfact*Pow(coeff, k2)*RefMatrix(i, j); |
169 | if (i != j) H(j, i) = H(i, j); |
170 | } |
171 | // Hermite*Jacobi part of matrix |
172 | for(j = degH + 1; j <= deg; j++) { |
173 | H(i, j) = H(j, i) = mfact*RefMatrix(i, j); |
174 | } |
175 | } |
176 | |
177 | |
178 | // Jacoby*Jacobi part of matrix |
179 | for(i = degH+1; i <= deg; i++) { |
180 | for(j = i; j <= deg; j++) { |
181 | H(i, j) = cteh3*RefMatrix(i, j); |
182 | if (i != j) H(j, i) = H(i, j); |
183 | } |
184 | } |
185 | } |
186 | |
187 | //======================================================================= |
188 | //function : Gradient |
189 | //purpose : |
190 | //======================================================================= |
191 | void FEmTool_LinearFlexion::Gradient(const Standard_Integer Dimension,math_Vector& G) |
192 | { |
193 | if(Dimension < myCoeff->LowerCol() || Dimension > myCoeff->UpperCol()) |
194 | Standard_OutOfRange::Raise("FEmTool_LinearFlexion::Gradient"); |
195 | |
196 | Standard_Integer deg = Min(G.Length() - 1, myCoeff->ColLength() - 1); |
197 | |
198 | math_Vector X(0,deg); |
199 | math_Matrix H(0,deg,0,deg); |
200 | Standard_Integer i, i1 = myCoeff->LowerRow(); |
201 | for(i = 0; i <= deg; i++) X(i) = myCoeff->Value(i1+i, Dimension); |
202 | |
203 | Hessian(Dimension, Dimension, H); |
204 | |
205 | G.Multiply(H, X); |
206 | } |
207 | |