b311480e |
1 | // Created on: 1998-12-07 |
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 | // |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
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> |
24 | |
25 | |
26 | |
27 | //======================================================================= |
28 | //function : Optimization |
29 | //purpose : (like FORTRAN subroutine MINIMI) |
30 | //======================================================================= |
31 | void AppParCurves_Variational::Optimization(Handle(AppParCurves_SmoothCriterion)& J, |
32 | FEmTool_Assembly& A, |
33 | const Standard_Boolean ToAssemble, |
34 | const Standard_Real EpsDeg, |
35 | Handle(FEmTool_Curve)& Curve, |
36 | const TColStd_Array1OfReal& Parameters) const |
37 | { |
38 | Standard_Integer MxDeg = Curve->Base()->WorkDegree(), |
39 | NbElm = Curve->NbElements(), |
40 | NbDim = Curve->Dimension(); |
41 | |
42 | Handle(FEmTool_HAssemblyTable) AssTable; |
43 | |
44 | math_Matrix H(0, MxDeg, 0, MxDeg); |
45 | math_Vector G(0, MxDeg), Sol(1, A.NbGlobVar()); |
46 | |
47 | Standard_Integer el, dim; |
48 | |
49 | A.GetAssemblyTable(AssTable); |
50 | Standard_Integer NbConstr = myNbPassPoints + myNbTangPoints + myNbCurvPoints; |
51 | |
52 | Standard_Real CBLONG = J->EstLength(); |
53 | |
54 | // Updating Assembly |
55 | if (ToAssemble) |
56 | A.NullifyMatrix(); |
57 | A.NullifyVector(); |
58 | |
59 | |
60 | for (el = 1; el <= NbElm; el++) { |
61 | if (ToAssemble) { |
62 | J->Hessian(el, 1, 1, H); |
63 | for(dim = 1; dim <= NbDim; dim++) |
64 | A.AddMatrix(el, dim, dim, H); |
65 | } |
66 | |
67 | for(dim = 1; dim <= NbDim; dim++) { |
68 | J->Gradient(el, dim, G); |
69 | A.AddVector(el, dim, G); |
70 | } |
71 | } |
72 | |
73 | |
74 | // Solution of system |
75 | if (ToAssemble) { |
76 | if(NbConstr != 0) { //Treatment of constraints |
77 | AssemblingConstraints(Curve, Parameters, CBLONG, A); |
78 | } |
79 | A.Solve(); |
80 | } |
81 | A.Solution(Sol); |
82 | |
83 | |
84 | // Updating J |
85 | J->SetCurve(Curve); |
86 | J->InputVector(Sol, AssTable); |
87 | |
88 | // Updating Curve and reduction of degree |
89 | |
90 | Standard_Integer Newdeg; |
91 | Standard_Real MaxError; |
92 | |
93 | if(NbConstr == 0) { |
94 | for(el = 1; el <= NbElm; el++) { |
95 | Curve->ReduceDegree(el, EpsDeg, Newdeg, MaxError); |
96 | } |
97 | } |
98 | else { |
99 | |
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); |
108 | else |
109 | if(Curve->Degree(el) < MxDeg) Curve->SetDegree(el, MxDeg); |
110 | } |
111 | } |
112 | } |
113 | |