0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / FairCurve / FairCurve_EnergyOfMVC.cxx
CommitLineData
b311480e 1// Created on: 1996-04-01
2// Created by: Philippe MANGIN
3// Copyright (c) 1996-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
7fd59977 17
42cf5bc1 18#include <FairCurve_BattenLaw.hxx>
19#include <FairCurve_EnergyOfMVC.hxx>
7fd59977 20#include <math_GaussSetIntegration.hxx>
42cf5bc1 21#include <math_IntegerVector.hxx>
22#include <Standard_DomainError.hxx>
7fd59977 23#include <TColgp_HArray1OfPnt2d.hxx>
24
25//=====================================================================================
26FairCurve_EnergyOfMVC::FairCurve_EnergyOfMVC(const Standard_Integer BSplOrder,
27 const Handle(TColStd_HArray1OfReal)& FlatKnots,
28 const Handle(TColgp_HArray1OfPnt2d)& Poles,
29 const Standard_Integer ContrOrder1,
30 const Standard_Integer ContrOrder2,
31 const FairCurve_BattenLaw& Law,
32 const Standard_Real PhysicalRatio,
33 const Standard_Real LengthSliding,
34 const Standard_Boolean FreeSliding,
35 const Standard_Real Angle1,
36 const Standard_Real Angle2,
37 const Standard_Real Curvature1,
38 const Standard_Real Curvature2 )
39//=====================================================================================
40 : FairCurve_Energy( Poles, ContrOrder1, ContrOrder2,
258ff83b 41 FreeSliding, Angle1, Angle2,
42 BSplOrder-1, Curvature1, Curvature2),
7fd59977 43 MyLengthSliding(LengthSliding),
258ff83b 44 OriginalSliding(LengthSliding),
7fd59977 45 MyBattenLaw(Law),
46 MyPhysicalRatio(PhysicalRatio),
47 MyTension(BSplOrder, FlatKnots, Poles, 1, LengthSliding, Law, FreeSliding, Standard_True),
48 MySagging(BSplOrder, FlatKnots, Poles, 1, Law, FreeSliding),
258ff83b 49 MyJerk( BSplOrder, FlatKnots, Poles, 1, Law, FreeSliding)
7fd59977 50{
51 Standard_DomainError_Raise_if(PhysicalRatio < 0 || PhysicalRatio > 1,
258ff83b 52 "FairCurve_EnergyOfMVC: PhysicalRatio error" );
7fd59977 53}
54
55
56//=====================================================================================
57void FairCurve_EnergyOfMVC::ComputePoles(const math_Vector& X)
58//=====================================================================================
59{
60 FairCurve_Energy::ComputePoles(X);
61 if (MyWithAuxValue) { MyLengthSliding = X(X.Upper()); }
62}
63
64
65//=====================================================================================
66Standard_Boolean FairCurve_EnergyOfMVC::Variable(math_Vector& X) const
67//=====================================================================================
68{
69 Standard_Boolean Ok;
70 Ok = FairCurve_Energy::Variable(X);
71 if (MyWithAuxValue) { X(X.Upper()) = MyLengthSliding; }
72 return Ok;
73}
74
75
76//=====================================================================================
77Standard_Boolean FairCurve_EnergyOfMVC::Compute(const Standard_Integer DerivativeOrder,
78 math_Vector& Result)
79//=====================================================================================
80{
81 math_Vector Debut(1, 1, 0.), Fin(1, 1, 1.);
82 math_IntegerVector MyOrder(1, 1, 24);
83 Standard_Boolean Ok=Standard_False;
84
85// Blindage contre les longueur de glissement trop exotique
86 MyStatus = FairCurve_OK;
87 if ( MyLengthSliding > 10*OriginalSliding ) {
88 MyStatus = FairCurve_InfiniteSliding;
89 return Standard_False;
90}
91 if ( MyLengthSliding < OriginalSliding/100 ) {
92 MyLengthSliding = OriginalSliding/100;
93 }
94
95// Mise a jour des objets sous-fonction
96 MyTension.SetDerivativeOrder(DerivativeOrder);
97 MyTension.SetLengthSliding(MyLengthSliding);
98 MySagging.SetDerivativeOrder(DerivativeOrder);
99 MyJerk.SetDerivativeOrder(DerivativeOrder);
100 MyBattenLaw.SetSliding(MyLengthSliding);
101
102// Integrations
103
104 // on decoupe afin d'avoir au moins 2 points d'integration par poles
105 // 24 points de Gauss => 12 poles maximum.
106
107 Standard_Integer NbInterv = (MyPoles->Length()-1) / 12 + 1, ii;
108 Standard_Real Delta = 1./ NbInterv;
109 Result.Init(0);
110
111 if (MyPhysicalRatio <= 1.e-12) {
112
113 // Cas purement non physique --------------------------
114
115 for (ii=1; ii<=NbInterv; ii++) {
116 Debut(1) = (ii-1)*Delta;
117 Fin(1) = ii*Delta;
118
119 math_GaussSetIntegration SumTension(MyTension, Debut, Fin, MyOrder);
120 Ok = SumTension.IsDone();
121 if (!Ok) return Ok;
122
123 math_GaussSetIntegration SumJerk(MyJerk, Debut, Fin, MyOrder);
124 Ok = SumJerk.IsDone();
125 if (!Ok) return Ok;
126
127 Result += SumJerk.Value() + SumTension.Value(); // Cas purement non physique
128 }
129 }
130 else {
131 // Cas mixte --------------------------
132 for (ii=1; ii<=NbInterv; ii++) {
133 Debut(1) = (ii-1)*Delta;
134 Fin(1) = ii*Delta;
135
136 math_GaussSetIntegration SumTension(MyTension, Debut, Fin, MyOrder);
137 Ok = SumTension.IsDone();
138 if (!Ok) return Ok;
139
140 math_GaussSetIntegration SumSagging(MySagging, Debut, Fin, MyOrder);
141 Ok = SumSagging.IsDone();
142 if (!Ok) return Ok;
143
144 math_GaussSetIntegration SumJerk(MyJerk, Debut, Fin, MyOrder);
145 Ok = SumJerk.IsDone();
146 if (!Ok) return Ok;
147
148 Result += SumJerk.Value() * (1-MyPhysicalRatio)
149 + SumSagging.Value() * MyPhysicalRatio
150 + SumTension.Value();
151 }
152 }
153
154 return Ok;
155}