1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 Ce programme permet le calcul de l'integrale nieme d'une fonction. La
17 resolution peut etre vue comme l'integrale de l'integrale de ....(n fois), ce
18 qui necessite l'emploi de fonction recursive.
20 Une integrale simple de Gauss est la somme de la fonction donnee sur les points
21 de Gauss affectee du poids de Gauss correspondant.
23 I = somme(F(GaussPt) * GaussW) sur i = 1 jusqu'a l'ordre d'integration.
25 Une integrale multiple est une somme recursive sur toutes les variables.
27 Tout le calcul est effectue dans la methode recursive_iteration appelee n fois.
28 (n = nombre de variables)
30 Cette methode fait une sommation sur toutes les variables, sur tous les ordres
31 d'integration correspondants de la valeur de la fonction aux points et poids
37 #define No_Standard_RangeError
38 #define No_Standard_OutOfRange
39 #define No_Standard_DimensionError
44 #include <math_GaussMultipleIntegration.hxx>
45 #include <math_IntegerVector.hxx>
46 #include <math_Matrix.hxx>
47 #include <math_MultipleVarFunction.hxx>
48 #include <math_Vector.hxx>
50 class IntegrationFunction {
52 // Cette classe sert a conserver dans les champs les valeurs de tests de
53 // la fonction recursive.(En particulier le pointeur sur la fonction F,
54 // heritant d'une classe abstraite, non traite en cdl.)
56 math_MultipleVarFunction *Fsav;
57 math_IntegerVector Ordsav;
58 Standard_Integer NVarsav;
61 math_Matrix GaussPoint;
62 math_Matrix GaussWeight;
64 Standard_Boolean Done;
67 IntegrationFunction(math_MultipleVarFunction& F,
68 const Standard_Integer maxsav, const Standard_Integer NVar,
69 const math_IntegerVector& Ord,
70 const math_Vector& Lowsav,
71 const math_Vector& Uppsav);
73 Standard_Real Value() ;
74 Standard_Boolean IsDone() const;
75 Standard_Boolean recursive_iteration(Standard_Integer& n, math_IntegerVector& inc);
78 IntegrationFunction::IntegrationFunction(math_MultipleVarFunction& F,
79 const Standard_Integer maxsav, const Standard_Integer NVar,
80 const math_IntegerVector& Ord,
81 const math_Vector& Lowsav,const math_Vector& Uppsav):
85 GaussPoint(1, NVar, 1, maxsav),
86 GaussWeight(1, NVar, 1, maxsav)
89 Standard_Integer i, k;
90 math_IntegerVector inc(1, NVar);
95 Done = Standard_False;
97 //Recuperation des points et poids de Gauss dans le fichier GaussPoints
98 for (i =1; i<= NVarsav; i++) {
99 xm(i) = 0.5*(Lowsav(i) + Uppsav(i));
100 xr(i) = 0.5*(Uppsav(i) - Lowsav(i));
101 math_Vector GP(1,Ordsav(i)), GW(1,Ordsav(i));
102 math::GaussPoints(Ordsav(i),GP);
103 math::GaussWeights(Ordsav(i),GW);
104 for (k = 1; k <= Ordsav(i); k++) {
105 GaussPoint(i,k) = GP(k); //kieme point et poids de
106 GaussWeight(i,k) = GW(k);//Gauss de la variable i.
110 Standard_Integer Iterdeb = 1;
111 Standard_Boolean recur = recursive_iteration(Iterdeb, inc);
113 //On ramene l'integration a la bonne echelle.
114 for ( i = 1; i <= NVarsav; i++) {
117 Done = Standard_True;
121 Standard_Real IntegrationFunction::Value() {
125 Standard_Boolean IntegrationFunction::IsDone() const{
129 Standard_Boolean IntegrationFunction::recursive_iteration(Standard_Integer& n,
130 math_IntegerVector& inc) {
132 // Termination criterium :
133 // Calcul de la valeur de la fonction aux points de Gauss fixes:
135 if (n == (NVarsav+1)) {
136 math_Vector dx(1, NVarsav);
138 for ( j = 1; j <= NVarsav; j++) {
139 dx(j) = xr(j)* GaussPoint(j, inc(j));
142 Standard_Boolean Ok = Fsav->Value(xm + dx, F1);
143 if (!Ok) {return Standard_False;};
144 Standard_Real Interm = 1;
145 for ( j = 1; j <= NVarsav; j++) {
146 Interm *= GaussWeight(j, inc(j));
149 return Standard_True;
152 // Calcul recursif, pour chaque variable n de la valeur de la fonction aux
153 // Ordsav(n) points de Gauss.
155 Standard_Boolean OK=Standard_False;
156 for (inc(n) = 1; inc(n) <= Ordsav(n); inc(n)++) {
158 OK = recursive_iteration(local, inc);
163 math_GaussMultipleIntegration::
164 math_GaussMultipleIntegration(math_MultipleVarFunction& F,
165 const math_Vector& Lower,
166 const math_Vector& Upper,
167 const math_IntegerVector& Order)
169 Standard_Integer MaxOrder = math::GaussPointsMax();
171 Standard_Integer i, max =0;
172 Standard_Integer NVar = F.NbVariables();
173 math_IntegerVector Ord(1, NVar);
174 math_Vector Lowsav(1, NVar);
175 math_Vector Uppsav(1, NVar);
179 Done = Standard_False;
180 for (i = 1; i <= NVar; i++) {
181 if (Order(i) > MaxOrder) {
187 if(Ord(i) >= max) {max = Ord(i);}
190 //Calcul de l'integrale aux points de Gauss.
191 // Il s agit d une somme multiple sur le domaine [Lower, Upper].
193 IntegrationFunction Func(F, max, NVar, Ord, Lowsav, Uppsav);
196 Done = Standard_True;
200 void math_GaussMultipleIntegration::Dump(Standard_OStream& o) const {
202 o <<"math_GaussMultipleIntegration ";
204 o << " Status = Done \n";
205 o << " Integration value = " << Val <<"\n";
208 o << "Status = not Done \n";