b311480e |
1 | // Created on: 1997-10-22 |
2 | // Created by: Sergey SOKOLOV |
3 | // Copyright (c) 1997-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 | |
f7b4312f |
18 | #include <NCollection_LocalArray.hxx> |
42cf5bc1 |
19 | #include <PLib.hxx> |
20 | #include <PLib_HermitJacobi.hxx> |
21 | #include <PLib_JacobiPolynomial.hxx> |
22 | #include <Standard_ConstructionError.hxx> |
23 | #include <Standard_Type.hxx> |
7fd59977 |
24 | #include <TColStd_HArray1OfReal.hxx> |
92efcf78 |
25 | |
26 | IMPLEMENT_STANDARD_RTTIEXT(PLib_HermitJacobi,PLib_Base) |
7fd59977 |
27 | |
28 | //======================================================================= |
29 | //function : PLib_HermitJacobi |
30 | //purpose : |
31 | //======================================================================= |
7fd59977 |
32 | PLib_HermitJacobi::PLib_HermitJacobi(const Standard_Integer WorkDegree, |
33 | const GeomAbs_Shape ConstraintOrder) : |
34 | myH(1,2*(PLib::NivConstr(ConstraintOrder)+1), |
35 | 1,2*(PLib::NivConstr(ConstraintOrder)+1)), |
36 | myWCoeff(1,2*(PLib::NivConstr(ConstraintOrder)+1)+1) |
37 | { |
38 | Standard_Integer NivConstr = PLib::NivConstr(ConstraintOrder); |
39 | PLib::HermiteCoefficients(-1.,1.,NivConstr,NivConstr,myH); |
40 | |
41 | myJacobi = new PLib_JacobiPolynomial (WorkDegree,ConstraintOrder); |
42 | |
43 | myWCoeff.Init(0.); |
44 | myWCoeff(1) = 1.; |
45 | switch(NivConstr) { |
46 | case 0: myWCoeff(3) = -1.; break; |
47 | case 1: myWCoeff(3) = -2.; myWCoeff(5) = 1.; break; |
48 | case 2: myWCoeff(3) = -3.; myWCoeff(5) = 3.; myWCoeff(7) = -1.; break; |
49 | } |
50 | } |
51 | |
52 | //======================================================================= |
53 | //function : MaxError |
54 | //purpose : |
55 | //======================================================================= |
56 | |
57 | Standard_Real PLib_HermitJacobi::MaxError(const Standard_Integer Dimension, |
58 | Standard_Real& HermJacCoeff, |
59 | const Standard_Integer NewDegree) const |
60 | { |
61 | return myJacobi->MaxError(Dimension,HermJacCoeff,NewDegree); |
62 | } |
63 | |
64 | //======================================================================= |
65 | //function : ReduceDegree |
66 | //purpose : |
67 | //======================================================================= |
68 | |
69 | void PLib_HermitJacobi::ReduceDegree(const Standard_Integer Dimension, |
70 | const Standard_Integer MaxDegree, |
71 | const Standard_Real Tol, |
72 | Standard_Real& HermJacCoeff, |
73 | Standard_Integer& NewDegree, |
74 | Standard_Real& MaxError) const |
75 | { |
76 | myJacobi->ReduceDegree(Dimension,MaxDegree,Tol, |
77 | HermJacCoeff,NewDegree,MaxError); |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : AverageError |
82 | //purpose : |
83 | //======================================================================= |
84 | |
85 | Standard_Real PLib_HermitJacobi::AverageError(const Standard_Integer Dimension, |
86 | Standard_Real& HermJacCoeff, |
87 | const Standard_Integer NewDegree) const |
88 | { |
89 | return myJacobi->AverageError(Dimension,HermJacCoeff,NewDegree); |
90 | } |
91 | |
92 | //======================================================================= |
93 | //function : ToCoefficients |
94 | //purpose : |
95 | //======================================================================= |
96 | |
97 | void PLib_HermitJacobi::ToCoefficients(const Standard_Integer Dimension, |
98 | const Standard_Integer Degree, |
99 | const TColStd_Array1OfReal& HermJacCoeff, |
100 | TColStd_Array1OfReal& Coefficients) const |
101 | { |
102 | Standard_Integer i,k,idim,i1,i2; |
103 | Standard_Real h1, h2; |
104 | Standard_Integer NivConstr = this->NivConstr(), |
105 | DegreeH = 2*NivConstr+1; |
106 | Standard_Integer ibegHJC = HermJacCoeff.Lower(), kdim; |
107 | |
108 | TColStd_Array1OfReal AuxCoeff(0,(Degree+1)*Dimension-1); |
109 | AuxCoeff.Init(0.); |
110 | |
111 | for (k=0; k<=DegreeH; k++) { |
112 | kdim = k*Dimension; |
113 | for (i=0; i<=NivConstr; i++) { |
114 | h1 = myH(i+1, k+1); |
115 | h2 = myH(i+NivConstr+2,k+1); |
116 | i1 = ibegHJC + i*Dimension; |
117 | i2 = ibegHJC + (i+NivConstr+1)*Dimension; |
118 | |
119 | for (idim=0; idim<Dimension; idim++) { |
120 | AuxCoeff(idim + kdim) += HermJacCoeff(i1 + idim) * h1 + |
121 | HermJacCoeff(i2 + idim) * h2; |
122 | } |
123 | } |
124 | } |
125 | kdim = (Degree+1)*Dimension; |
126 | for (k=(DegreeH+1)*Dimension; k<kdim; k++) { |
127 | AuxCoeff(k) = HermJacCoeff(ibegHJC + k); |
128 | } |
129 | |
130 | if(Degree > DegreeH) |
131 | myJacobi->ToCoefficients(Dimension,Degree,AuxCoeff,Coefficients); |
132 | else { |
133 | Standard_Integer ibegC = Coefficients.Lower(); |
134 | kdim = (Degree+1)*Dimension; |
135 | for(k=0; k < kdim; k++) |
136 | Coefficients(ibegC+k) = AuxCoeff(k); |
137 | } |
138 | } |
139 | |
140 | //======================================================================= |
141 | //function : D0123 |
142 | //purpose : common part of D0,D1,D2,D3 (FORTRAN subroutine MPOBAS) |
143 | //======================================================================= |
144 | |
145 | void PLib_HermitJacobi::D0123(const Standard_Integer NDeriv, |
146 | const Standard_Real U, |
147 | TColStd_Array1OfReal& BasisValue, |
148 | TColStd_Array1OfReal& BasisD1, |
149 | TColStd_Array1OfReal& BasisD2, |
150 | TColStd_Array1OfReal& BasisD3) |
151 | { |
f7b4312f |
152 | NCollection_LocalArray<Standard_Real> jac0 (4 * 20); |
153 | NCollection_LocalArray<Standard_Real> jac1 (4 * 20); |
154 | NCollection_LocalArray<Standard_Real> jac2 (4 * 20); |
155 | NCollection_LocalArray<Standard_Real> jac3 (4 * 20); |
156 | NCollection_LocalArray<Standard_Real> wvalues (4); |
7fd59977 |
157 | |
158 | Standard_Integer i, j; |
159 | Standard_Integer NivConstr = this->NivConstr(), |
160 | WorkDegree = this->WorkDegree(), |
161 | DegreeH = 2*NivConstr+1; |
162 | Standard_Integer ibeg0 = BasisValue.Lower(), |
163 | ibeg1 = BasisD1.Lower(), |
164 | ibeg2 = BasisD2.Lower(), |
165 | ibeg3 = BasisD3.Lower(); |
166 | Standard_Integer JacDegree = WorkDegree-DegreeH-1; |
167 | Standard_Real W0; |
168 | |
169 | TColStd_Array1OfReal JacValue0(jac0[0], 0, Max(0,JacDegree)); |
170 | TColStd_Array1OfReal WValues(wvalues[0],0,NDeriv); |
171 | WValues.Init(0.); |
172 | |
173 | // Evaluation des polynomes d'hermite |
174 | math_Matrix HermitValues(0,DegreeH, 0, NDeriv, 0.); |
175 | if(NDeriv == 0) |
176 | for (i=0; i<=DegreeH; i++) { |
177 | PLib::NoDerivativeEvalPolynomial(U,DegreeH,1, DegreeH, |
178 | myH(i+1,1), HermitValues(i,0)); |
179 | } |
180 | else |
181 | for (i=0; i<=DegreeH; i++) { |
182 | PLib::EvalPolynomial(U,NDeriv,DegreeH,1, |
183 | myH(i+1,1), HermitValues(i,0)); |
184 | } |
185 | |
186 | // Evaluation des polynomes de Jaccobi |
187 | if(JacDegree >= 0) { |
188 | |
189 | switch (NDeriv) { |
190 | case 0 : |
191 | myJacobi->D0(U,JacValue0); |
192 | break; |
193 | case 1 : |
194 | { |
195 | TColStd_Array1OfReal JacValue1(jac1[0], 0, JacDegree); |
196 | myJacobi->D1(U,JacValue0,JacValue1); |
197 | break; |
198 | } |
199 | case 2 : |
200 | { |
201 | TColStd_Array1OfReal JacValue1(jac1[0], 0, JacDegree); |
202 | TColStd_Array1OfReal JacValue2(jac2[0], 0, JacDegree); |
203 | myJacobi->D2(U,JacValue0,JacValue1,JacValue2); |
204 | break; |
205 | } |
206 | case 3 : |
207 | { |
208 | TColStd_Array1OfReal JacValue1(jac1[0], 0, JacDegree); |
209 | TColStd_Array1OfReal JacValue2(jac2[0], 0, JacDegree); |
210 | TColStd_Array1OfReal JacValue3(jac3[0], 0, JacDegree); |
211 | myJacobi->D3(U,JacValue0,JacValue1,JacValue2,JacValue3); |
212 | } |
213 | } |
214 | |
215 | // Evaluation de W(t) |
216 | if(NDeriv == 0) |
217 | PLib::NoDerivativeEvalPolynomial(U,DegreeH+1,1,DegreeH+1,myWCoeff(1), WValues(0)); |
218 | else |
219 | PLib::EvalPolynomial(U,NDeriv,DegreeH+1,1,myWCoeff(1), WValues(0)); |
220 | } |
221 | |
222 | // Evaluation a l'ordre 0 |
223 | for (i=0; i<=DegreeH; i++) { |
224 | BasisValue(ibeg0+i) = HermitValues(i,0); |
225 | } |
226 | W0 = WValues(0); |
227 | for (i=DegreeH+1, j=0; i<=WorkDegree; i++, j++) { |
228 | BasisValue(ibeg0+i) = W0 * jac0[j]; |
229 | } |
230 | |
231 | // Evaluation a l'ordre 1 |
232 | if (NDeriv >= 1) { |
233 | Standard_Real W1=WValues(1); |
234 | for (i=0; i<=DegreeH; i++) { |
235 | BasisD1(ibeg1+i) = HermitValues(i,1); |
236 | } |
237 | for (i=DegreeH+1, j=0; i<=WorkDegree; i++, j++) { |
238 | BasisD1(ibeg1+i) = W0 * jac1[j] + |
239 | W1 * jac0[j]; |
240 | } |
241 | // Evaluation a l'ordre 2 |
242 | if (NDeriv >= 2) { |
243 | Standard_Real W2=WValues(2); |
244 | for (i=0; i<=DegreeH; i++) { |
245 | BasisD2(ibeg2+i) = HermitValues(i,2); |
246 | } |
247 | for (i=DegreeH+1, j=0; i<=WorkDegree; i++, j++) { |
248 | BasisD2(ibeg2+i) = |
249 | W0 * jac2[j] + 2 * W1 * jac1[j] + W2 * jac0[j]; |
250 | } |
251 | |
252 | // Evaluation a l'ordre 3 |
253 | if (NDeriv == 3) { |
254 | Standard_Real W3 = WValues(3); |
255 | for (i=0; i<=DegreeH; i++) { |
256 | BasisD3(ibeg3+i) = HermitValues(i,3); |
257 | } |
258 | for (i=DegreeH+1, j=0; i<=WorkDegree; i++,j++) { |
259 | BasisD3(ibeg3+i) = W0*jac3[j] + W3*jac0[j] |
260 | + 3*(W1*jac2[j] + W2*jac1[j]); |
261 | } |
262 | } |
263 | } |
264 | } |
265 | } |
266 | |
267 | //======================================================================= |
268 | //function : D0 |
269 | //purpose : |
270 | //======================================================================= |
271 | |
272 | void PLib_HermitJacobi::D0(const Standard_Real U, TColStd_Array1OfReal& BasisValue) |
273 | { |
274 | D0123(0,U,BasisValue,BasisValue,BasisValue,BasisValue); |
275 | } |
276 | |
277 | //======================================================================= |
278 | //function : D1 |
279 | //purpose : |
280 | //======================================================================= |
281 | |
282 | void PLib_HermitJacobi::D1(const Standard_Real U, |
283 | TColStd_Array1OfReal& BasisValue, TColStd_Array1OfReal& BasisD1) |
284 | { |
285 | D0123(1,U,BasisValue,BasisD1,BasisD1,BasisD1); |
286 | } |
287 | |
288 | //======================================================================= |
289 | //function : D2 |
290 | //purpose : |
291 | //======================================================================= |
292 | |
293 | void PLib_HermitJacobi::D2(const Standard_Real U, TColStd_Array1OfReal& BasisValue, |
294 | TColStd_Array1OfReal& BasisD1,TColStd_Array1OfReal& BasisD2) |
295 | { |
296 | D0123(2,U,BasisValue,BasisD1,BasisD2,BasisD2); |
297 | } |
298 | |
299 | //======================================================================= |
300 | //function : D3 |
301 | //purpose : |
302 | //======================================================================= |
303 | |
304 | void PLib_HermitJacobi::D3(const Standard_Real U, |
305 | TColStd_Array1OfReal& BasisValue, TColStd_Array1OfReal& BasisD1, |
306 | TColStd_Array1OfReal& BasisD2, TColStd_Array1OfReal& BasisD3) |
307 | { |
308 | D0123(3,U,BasisValue,BasisD1,BasisD2,BasisD3); |
309 | } |