summaryrefslogtreecommitdiff
path: root/src/PLib/PLib_HermitJacobi.cxx
blob: bc4657d6c5bfc4ea6554b961c44ff78d3d7ec1e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
// File:	PLib_HermitJacobi.cxx
// Created:	Wed Oct 22 11:19:36 1997
// Author:	Sergey SOKOLOV
//		<ssv@velox.nnov.matra-dtv.fr>


#include <PLib_HermitJacobi.ixx>
#include <PLib.hxx>
#include <TColStd_HArray1OfReal.hxx>

//=======================================================================
//function : PLib_HermitJacobi
//purpose  : 
//=======================================================================

PLib_HermitJacobi::PLib_HermitJacobi(const Standard_Integer WorkDegree,
				     const GeomAbs_Shape ConstraintOrder) :
                                     myH(1,2*(PLib::NivConstr(ConstraintOrder)+1),
					 1,2*(PLib::NivConstr(ConstraintOrder)+1)),
				     myWCoeff(1,2*(PLib::NivConstr(ConstraintOrder)+1)+1)
{
  Standard_Integer NivConstr = PLib::NivConstr(ConstraintOrder);
  PLib::HermiteCoefficients(-1.,1.,NivConstr,NivConstr,myH);

  myJacobi = new PLib_JacobiPolynomial (WorkDegree,ConstraintOrder);
  
  myWCoeff.Init(0.);
  myWCoeff(1) = 1.;
  switch(NivConstr) {
    case 0: myWCoeff(3) = -1.; break;
    case 1: myWCoeff(3) = -2.; myWCoeff(5) = 1.; break;
    case 2: myWCoeff(3) = -3.; myWCoeff(5) = 3.; myWCoeff(7) = -1.; break;
  }
}

//=======================================================================
//function : MaxError
//purpose  : 
//=======================================================================

Standard_Real PLib_HermitJacobi::MaxError(const Standard_Integer Dimension,
					  Standard_Real& HermJacCoeff,
					  const Standard_Integer NewDegree) const
{
  return myJacobi->MaxError(Dimension,HermJacCoeff,NewDegree);
}

//=======================================================================
//function : ReduceDegree
//purpose  : 
//=======================================================================

void PLib_HermitJacobi::ReduceDegree(const Standard_Integer Dimension,
				     const Standard_Integer MaxDegree,
				     const Standard_Real Tol,
				     Standard_Real& HermJacCoeff,
				     Standard_Integer& NewDegree,
				     Standard_Real& MaxError) const
{
  myJacobi->ReduceDegree(Dimension,MaxDegree,Tol,
			 HermJacCoeff,NewDegree,MaxError);
}

//=======================================================================
//function : AverageError
//purpose  : 
//=======================================================================

Standard_Real PLib_HermitJacobi::AverageError(const Standard_Integer Dimension,
					      Standard_Real& HermJacCoeff,
					      const Standard_Integer NewDegree) const
{
  return myJacobi->AverageError(Dimension,HermJacCoeff,NewDegree);
}

//=======================================================================
//function : ToCoefficients
//purpose  : 
//=======================================================================

void PLib_HermitJacobi::ToCoefficients(const Standard_Integer Dimension,
				       const Standard_Integer Degree,
				       const TColStd_Array1OfReal& HermJacCoeff,
				       TColStd_Array1OfReal& Coefficients) const
{
  Standard_Integer i,k,idim,i1,i2;
  Standard_Real h1, h2;
  Standard_Integer NivConstr  = this->NivConstr(),
                   DegreeH    = 2*NivConstr+1;
  Standard_Integer ibegHJC = HermJacCoeff.Lower(), kdim;

  TColStd_Array1OfReal AuxCoeff(0,(Degree+1)*Dimension-1);
  AuxCoeff.Init(0.);

  for (k=0; k<=DegreeH; k++) {
    kdim =  k*Dimension;
    for (i=0; i<=NivConstr; i++) {
      h1 =  myH(i+1, k+1);
      h2 =  myH(i+NivConstr+2,k+1);
      i1 =  ibegHJC + i*Dimension;
      i2 =  ibegHJC + (i+NivConstr+1)*Dimension;
      
      for (idim=0; idim<Dimension; idim++) {
	AuxCoeff(idim + kdim) += HermJacCoeff(i1 + idim) * h1 +
	                         HermJacCoeff(i2 + idim) * h2;
      }
    }
  }
  kdim = (Degree+1)*Dimension;
  for (k=(DegreeH+1)*Dimension; k<kdim; k++) {
    AuxCoeff(k) = HermJacCoeff(ibegHJC + k);
  }
  
  if(Degree > DegreeH) 
    myJacobi->ToCoefficients(Dimension,Degree,AuxCoeff,Coefficients);
  else {
    Standard_Integer ibegC = Coefficients.Lower();
    kdim = (Degree+1)*Dimension;    
    for(k=0; k < kdim; k++)
	Coefficients(ibegC+k) = AuxCoeff(k);
  }
}

//=======================================================================
//function : D0123
//purpose  : common part of D0,D1,D2,D3 (FORTRAN subroutine MPOBAS)
//=======================================================================

void PLib_HermitJacobi::D0123(const Standard_Integer NDeriv,
			      const Standard_Real U,
			      TColStd_Array1OfReal& BasisValue,
			      TColStd_Array1OfReal& BasisD1,
			      TColStd_Array1OfReal& BasisD2,
			      TColStd_Array1OfReal& BasisD3)
{
// Tableaux en static
  static Standard_Real jac0[4*20];
  static Standard_Real jac1[4*20];
  static Standard_Real jac2[4*20];
  static Standard_Real jac3[4*20];
  static Standard_Real wvalues[4];


  Standard_Integer i, j;
  Standard_Integer NivConstr  = this->NivConstr(),
                   WorkDegree = this->WorkDegree(),
                   DegreeH    = 2*NivConstr+1;
  Standard_Integer ibeg0 = BasisValue.Lower(), 
                   ibeg1 = BasisD1.Lower(),
                   ibeg2 = BasisD2.Lower(),
                   ibeg3 = BasisD3.Lower();
  Standard_Integer JacDegree = WorkDegree-DegreeH-1;
  Standard_Real W0;

  TColStd_Array1OfReal JacValue0(jac0[0], 0, Max(0,JacDegree)); 
  TColStd_Array1OfReal WValues(wvalues[0],0,NDeriv); 
  WValues.Init(0.);

// Evaluation des polynomes d'hermite
  math_Matrix HermitValues(0,DegreeH, 0, NDeriv, 0.);
  if(NDeriv == 0)
    for (i=0; i<=DegreeH; i++) {
      PLib::NoDerivativeEvalPolynomial(U,DegreeH,1, DegreeH,
				       myH(i+1,1), HermitValues(i,0));
    }
  else
    for (i=0; i<=DegreeH; i++) {
      PLib::EvalPolynomial(U,NDeriv,DegreeH,1,
			   myH(i+1,1), HermitValues(i,0));
    }

// Evaluation des polynomes de Jaccobi
  if(JacDegree >= 0) {

    switch (NDeriv) {
    case 0 :
      myJacobi->D0(U,JacValue0);
      break;
    case 1 :
      {
	TColStd_Array1OfReal JacValue1(jac1[0], 0, JacDegree);
	myJacobi->D1(U,JacValue0,JacValue1);
	break;
      }
    case 2 :
      {      
	TColStd_Array1OfReal JacValue1(jac1[0], 0, JacDegree);      
	TColStd_Array1OfReal JacValue2(jac2[0], 0, JacDegree);
	myJacobi->D2(U,JacValue0,JacValue1,JacValue2);      
	break;
      }
    case 3 :
      {
	TColStd_Array1OfReal JacValue1(jac1[0], 0, JacDegree);      
	TColStd_Array1OfReal JacValue2(jac2[0], 0, JacDegree);  
	TColStd_Array1OfReal JacValue3(jac3[0], 0, JacDegree);
	myJacobi->D3(U,JacValue0,JacValue1,JacValue2,JacValue3);
      }
    }

// Evaluation de W(t)
    if(NDeriv == 0)
      PLib::NoDerivativeEvalPolynomial(U,DegreeH+1,1,DegreeH+1,myWCoeff(1), WValues(0));
    else
      PLib::EvalPolynomial(U,NDeriv,DegreeH+1,1,myWCoeff(1), WValues(0));
  }

// Evaluation a l'ordre 0
  for (i=0; i<=DegreeH; i++) {
    BasisValue(ibeg0+i) = HermitValues(i,0);
  }
  W0 = WValues(0);
  for (i=DegreeH+1, j=0; i<=WorkDegree; i++, j++) {
    BasisValue(ibeg0+i) = W0 * jac0[j];
  }

// Evaluation a l'ordre 1
  if (NDeriv >= 1) {
    Standard_Real W1=WValues(1);
    for (i=0; i<=DegreeH; i++) {
      BasisD1(ibeg1+i) = HermitValues(i,1);
    }
    for (i=DegreeH+1, j=0; i<=WorkDegree; i++, j++) {
      BasisD1(ibeg1+i) = W0 * jac1[j] +
	                 W1 * jac0[j];
    }
// Evaluation a l'ordre 2
    if (NDeriv >= 2) {
      Standard_Real W2=WValues(2);
      for (i=0; i<=DegreeH; i++) {
	BasisD2(ibeg2+i) = HermitValues(i,2);
      }
      for (i=DegreeH+1, j=0; i<=WorkDegree; i++, j++) {
	BasisD2(ibeg2+i) =  
	  W0 * jac2[j] + 2 * W1 * jac1[j] + W2 * jac0[j];
      }

// Evaluation a l'ordre 3
      if (NDeriv == 3) {
	 Standard_Real W3 = WValues(3);
	for (i=0; i<=DegreeH; i++) {
	  BasisD3(ibeg3+i) = HermitValues(i,3);
	}
	for (i=DegreeH+1, j=0; i<=WorkDegree; i++,j++) {
	  BasisD3(ibeg3+i) = W0*jac3[j] + W3*jac0[j] 
                           + 3*(W1*jac2[j] + W2*jac1[j]);
	}
      }
    }
  }
}

//=======================================================================
//function : D0
//purpose  : 
//=======================================================================

void PLib_HermitJacobi::D0(const Standard_Real U, TColStd_Array1OfReal& BasisValue) 
{
  D0123(0,U,BasisValue,BasisValue,BasisValue,BasisValue);
}

//=======================================================================
//function : D1
//purpose  : 
//=======================================================================

void PLib_HermitJacobi::D1(const Standard_Real U,
			   TColStd_Array1OfReal& BasisValue, TColStd_Array1OfReal& BasisD1)  
{
  D0123(1,U,BasisValue,BasisD1,BasisD1,BasisD1);
}

//=======================================================================
//function : D2
//purpose  : 
//=======================================================================

void PLib_HermitJacobi::D2(const Standard_Real U, TColStd_Array1OfReal& BasisValue,
			   TColStd_Array1OfReal& BasisD1,TColStd_Array1OfReal& BasisD2) 
{
  D0123(2,U,BasisValue,BasisD1,BasisD2,BasisD2);
}

//=======================================================================
//function : D3
//purpose  : 
//=======================================================================

void PLib_HermitJacobi::D3(const Standard_Real U,
			   TColStd_Array1OfReal& BasisValue, TColStd_Array1OfReal& BasisD1,
			   TColStd_Array1OfReal& BasisD2,    TColStd_Array1OfReal& BasisD3) 
{
  D0123(3,U,BasisValue,BasisD1,BasisD2,BasisD3);
}