d314e82a33a527dec18d05be2e376d3bb8e0f7af
[occt.git] / src / FairCurve / FairCurve_EnergyOfBatten.cxx
1 // Created on: 1996-02-01
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef OCCT_DEBUG
18 #define No_Standard_RangeError
19 #define No_Standard_OutOfRange
20 #endif
21
22
23 #include <FairCurve_BattenLaw.hxx>
24 #include <FairCurve_EnergyOfBatten.hxx>
25 #include <math_GaussSetIntegration.hxx>
26 #include <math_IntegerVector.hxx>
27 #include <TColgp_HArray1OfPnt2d.hxx>
28
29 //=======================================================================
30 FairCurve_EnergyOfBatten::FairCurve_EnergyOfBatten(const Standard_Integer BSplOrder, 
31                                                    const Handle(TColStd_HArray1OfReal)& FlatKnots,
32                                                    const Handle(TColgp_HArray1OfPnt2d)& Poles, 
33                                                    const Standard_Integer ContrOrder1, 
34                                                    const Standard_Integer ContrOrder2, 
35                                                    const FairCurve_BattenLaw& Law, 
36                                                    const Standard_Real LengthSliding, 
37                                                    const Standard_Boolean FreeSliding, 
38                                                    const Standard_Real Angle1, 
39                                                    const Standard_Real Angle2)
40 //=======================================================================
41                          : FairCurve_Energy( Poles, ContrOrder1,  ContrOrder2,
42                                              FreeSliding,  Angle1, Angle2),
43                            MyLengthSliding(LengthSliding),
44                            OriginalSliding(LengthSliding),
45                            MyBattenLaw(Law), 
46                            MyTension(BSplOrder, FlatKnots, Poles, 1, LengthSliding,  Law, FreeSliding),
47                            MySagging(BSplOrder, FlatKnots, Poles, 1, Law, FreeSliding),
48                            MyStatus(FairCurve_OK)
49 {
50 }
51
52 //=======================================================================
53 Standard_Boolean FairCurve_EnergyOfBatten::Variable(math_Vector& X) const
54 //======================================================================= 
55 {
56  Standard_Boolean Ok;
57  Ok = FairCurve_Energy::Variable(X);
58  if (MyWithAuxValue) { X(X.Upper()) = MyLengthSliding; }
59  return Ok;
60 }  
61
62 //=======================================================================
63 void FairCurve_EnergyOfBatten::ComputePoles(const math_Vector& X)
64 //======================================================================= 
65 {
66  FairCurve_Energy::ComputePoles(X);
67  if (MyWithAuxValue) { MyLengthSliding = X(X.Upper()); }
68 }
69
70 //=======================================================================
71 Standard_Boolean FairCurve_EnergyOfBatten::Compute(const Standard_Integer DerivativeOrder, 
72                                                    math_Vector& Result)
73 //=======================================================================
74 {
75   math_Vector Debut(1, 1, 0.),  Fin(1, 1, 1.);
76   math_IntegerVector MyOrder(1, 1, 24);
77   Standard_Boolean Ok=Standard_False;
78
79 // Blindage contre les longueur de glissement trop exotique
80   MyStatus = FairCurve_OK;
81   if ( MyLengthSliding > 10*OriginalSliding ) {
82     MyStatus =  FairCurve_InfiniteSliding;
83     return Standard_False;
84 }
85
86   if ( MyLengthSliding < OriginalSliding/100  ) {
87     MyLengthSliding = OriginalSliding/100;
88   }
89
90 // Mise a jour des objets sous-fonction
91   MyTension.SetDerivativeOrder(DerivativeOrder);
92   MyTension.SetLengthSliding(MyLengthSliding);
93   MySagging.SetDerivativeOrder(DerivativeOrder);
94   MyBattenLaw.SetSliding(MyLengthSliding);
95
96 //  Integrations
97   
98   // on decoupe afin d'avoir au moins 2 points d'integration par poles
99   // 24 points de Gauss => 12 poles maximum.
100
101   Standard_Integer NbInterv = (MyPoles->Length()-1) / 12 + 1, ii;
102   Standard_Real Delta = 1./ NbInterv;
103   Result.Init(0);
104
105   for (ii=1; ii<=NbInterv; ii++) {
106     Debut(1) = (ii-1)*Delta;
107     Fin(1) = ii*Delta;
108     
109     math_GaussSetIntegration SumTension(MyTension, Debut, Fin, MyOrder); 
110     Ok = SumTension.IsDone();
111     if (!Ok) return Ok;
112
113     math_GaussSetIntegration SumSagging(MySagging, Debut, Fin, MyOrder);
114     Ok = SumSagging.IsDone();
115
116     if (Ok) { Result += SumSagging.Value() + SumTension.Value(); }
117   }
118
119   return Ok;
120 }
121