1 // Created on: 1998-12-07
2 // Created by: Igor FEOKTISTOV
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <math_Matrix.hxx>
18 #include <math_Vector.hxx>
19 #include <TColStd_Array2OfReal.hxx>
20 #include <PLib_Base.hxx>
21 #include <PLib_JacobiPolynomial.hxx>
22 #include <PLib_HermitJacobi.hxx>
23 #include <FEmTool_HAssemblyTable.hxx>
27 //=======================================================================
28 //function : Optimization
29 //purpose : (like FORTRAN subroutine MINIMI)
30 //=======================================================================
31 void AppParCurves_Variational::Optimization(Handle(AppParCurves_SmoothCriterion)& J,
33 const Standard_Boolean ToAssemble,
34 const Standard_Real EpsDeg,
35 Handle(FEmTool_Curve)& Curve,
36 const TColStd_Array1OfReal& Parameters) const
38 Standard_Integer MxDeg = Curve->Base()->WorkDegree(),
39 NbElm = Curve->NbElements(),
40 NbDim = Curve->Dimension();
42 Handle(FEmTool_HAssemblyTable) AssTable;
44 math_Matrix H(0, MxDeg, 0, MxDeg);
45 math_Vector G(0, MxDeg), Sol(1, A.NbGlobVar());
47 Standard_Integer el, dim;
49 A.GetAssemblyTable(AssTable);
50 Standard_Integer NbConstr = myNbPassPoints + myNbTangPoints + myNbCurvPoints;
52 Standard_Real CBLONG = J->EstLength();
60 for (el = 1; el <= NbElm; el++) {
62 J->Hessian(el, 1, 1, H);
63 for(dim = 1; dim <= NbDim; dim++)
64 A.AddMatrix(el, dim, dim, H);
67 for(dim = 1; dim <= NbDim; dim++) {
68 J->Gradient(el, dim, G);
69 A.AddVector(el, dim, G);
76 if(NbConstr != 0) { //Treatment of constraints
77 AssemblingConstraints(Curve, Parameters, CBLONG, A);
86 J->InputVector(Sol, AssTable);
88 // Updating Curve and reduction of degree
90 Standard_Integer Newdeg;
91 Standard_Real MaxError;
94 for(el = 1; el <= NbElm; el++) {
95 Curve->ReduceDegree(el, EpsDeg, Newdeg, MaxError);
100 TColStd_Array1OfReal& TabInt = Curve->Knots();
101 Standard_Integer Icnt = 1, p0 = Parameters.Lower() - myFirstPoint, point;
102 for(el = 1; el <= NbElm; el++) {
103 while((Icnt < NbConstr) &&
104 (Parameters(p0 + myTypConstraints->Value(2 * Icnt - 1)) <= TabInt(el))) Icnt++;
105 point = p0 + myTypConstraints->Value(2 * Icnt - 1);
106 if(Parameters(point) <= TabInt(el) || Parameters(point) >= TabInt(el + 1))
107 Curve->ReduceDegree(el, EpsDeg, Newdeg, MaxError);
109 if(Curve->Degree(el) < MxDeg) Curve->SetDegree(el, MxDeg);