afa1ee59da98a003dc4998ddc1d9e6b4d2c2d55a
[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 {
49 }
50
51 //=======================================================================
52 Standard_Boolean FairCurve_EnergyOfBatten::Variable(math_Vector& X) const
53 //======================================================================= 
54 {
55  Standard_Boolean Ok;
56  Ok = FairCurve_Energy::Variable(X);
57  if (MyWithAuxValue) { X(X.Upper()) = MyLengthSliding; }
58  return Ok;
59 }  
60
61 //=======================================================================
62 void FairCurve_EnergyOfBatten::ComputePoles(const math_Vector& X)
63 //======================================================================= 
64 {
65  FairCurve_Energy::ComputePoles(X);
66  if (MyWithAuxValue) { MyLengthSliding = X(X.Upper()); }
67 }
68
69 //=======================================================================
70 Standard_Boolean FairCurve_EnergyOfBatten::Compute(const Standard_Integer DerivativeOrder, 
71                                                    math_Vector& Result)
72 //=======================================================================
73 {
74   math_Vector Debut(1, 1, 0.),  Fin(1, 1, 1.);
75   math_IntegerVector MyOrder(1, 1, 24);
76   Standard_Boolean Ok=Standard_False;
77
78 // Blindage contre les longueur de glissement trop exotique
79   MyStatus = FairCurve_OK;
80   if ( MyLengthSliding > 10*OriginalSliding ) {
81     MyStatus =  FairCurve_InfiniteSliding;
82     return Standard_False;
83 }
84
85   if ( MyLengthSliding < OriginalSliding/100  ) {
86     MyLengthSliding = OriginalSliding/100;
87   }
88
89 // Mise a jour des objets sous-fonction
90   MyTension.SetDerivativeOrder(DerivativeOrder);
91   MyTension.SetLengthSliding(MyLengthSliding);
92   MySagging.SetDerivativeOrder(DerivativeOrder);
93   MyBattenLaw.SetSliding(MyLengthSliding);
94
95 //  Integrations
96   
97   // on decoupe afin d'avoir au moins 2 points d'integration par poles
98   // 24 points de Gauss => 12 poles maximum.
99
100   Standard_Integer NbInterv = (MyPoles->Length()-1) / 12 + 1, ii;
101   Standard_Real Delta = 1./ NbInterv;
102   Result.Init(0);
103
104   for (ii=1; ii<=NbInterv; ii++) {
105     Debut(1) = (ii-1)*Delta;
106     Fin(1) = ii*Delta;
107     
108     math_GaussSetIntegration SumTension(MyTension, Debut, Fin, MyOrder); 
109     Ok = SumTension.IsDone();
110     if (!Ok) return Ok;
111
112     math_GaussSetIntegration SumSagging(MySagging, Debut, Fin, MyOrder);
113     Ok = SumSagging.IsDone();
114
115     if (Ok) { Result += SumSagging.Value() + SumTension.Value(); }
116   }
117
118   return Ok;
119 }
120