0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / FEmTool / FEmTool_ElementsOfRefMatrix.cxx
1 // Created on: 1998-11-10
2 // Created by: Igor FEOKTISTOV
3 // Copyright (c) 1998-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
18 #include <FEmTool_ElementsOfRefMatrix.hxx>
19 #include <PLib_Base.hxx>
20 #include <Standard_ConstructionError.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22
23 FEmTool_ElementsOfRefMatrix::FEmTool_ElementsOfRefMatrix(const Handle(PLib_Base)& TheBase,
24                                                          const Standard_Integer DerOrder):
25        myBase(TheBase)
26 {
27   if(DerOrder < 0 || DerOrder > 3) 
28     throw Standard_ConstructionError("FEmTool_ElementsOfRefMatrix");
29
30   myDerOrder = DerOrder;
31   myNbEquations = (myBase->WorkDegree()+2)*(myBase->WorkDegree()+1)/2;
32
33 }
34
35 Standard_Integer FEmTool_ElementsOfRefMatrix::NbVariables() const
36 {
37   return 1;
38 }
39
40 Standard_Integer FEmTool_ElementsOfRefMatrix::NbEquations() const
41 {
42   return myNbEquations;
43 }
44
45 Standard_Boolean FEmTool_ElementsOfRefMatrix::Value(const math_Vector& X, math_Vector& F) 
46 {
47   if(F.Length() < myNbEquations) throw Standard_OutOfRange("FEmTool_ElementsOfRefMatrix::Value");
48
49   Standard_Real u = X(X.Lower());
50   TColStd_Array1OfReal Basis(0,myBase->WorkDegree()), Aux(0,myBase->WorkDegree());
51
52   switch (myDerOrder) {
53   case 0 :
54     myBase->D0(u, Basis);
55     break;
56   case 1 :
57     myBase->D1(u, Aux, Basis);
58     break;
59   case 2 :
60     myBase->D2(u, Aux, Aux, Basis);
61     break;
62   case 3 :
63     myBase->D3(u, Aux, Aux, Aux, Basis);
64     break; 
65   }
66  
67   Standard_Integer i, j, ii = 0;
68   for(i = 0; i<=myBase->WorkDegree(); i++)
69     for(j = i; j<=myBase->WorkDegree(); j++) {
70       F(F.Lower()+ii) = Basis(i)*Basis(j); ii++;
71     }
72
73   return Standard_True;
74 }
75