mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-05 18:16:23 +03:00
219 lines
6.5 KiB
C++
Executable File
219 lines
6.5 KiB
C++
Executable File
// Copyright (c) 1997-1999 Matra Datavision
|
|
// Copyright (c) 1999-2012 OPEN CASCADE SAS
|
|
//
|
|
// The content of this file is subject to the Open CASCADE Technology Public
|
|
// License Version 6.5 (the "License"). You may not use the content of this file
|
|
// except in compliance with the License. Please obtain a copy of the License
|
|
// at http://www.opencascade.org and read it completely before using this file.
|
|
//
|
|
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
|
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
|
//
|
|
// The Original Code and all software distributed under the License is
|
|
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
|
// Initial Developer hereby disclaims all such warranties, including without
|
|
// limitation, any warranties of merchantability, fitness for a particular
|
|
// purpose or non-infringement. Please see the License for the specific terms
|
|
// and conditions governing the rights and limitations under the License.
|
|
|
|
|
|
|
|
/*
|
|
Ce programme permet le calcul de l'integrale nieme d'une fonction. La
|
|
resolution peut etre vue comme l'integrale de l'integrale de ....(n fois), ce
|
|
qui necessite l'emploi de fonction recursive.
|
|
|
|
Une integrale simple de Gauss est la somme de la fonction donnee sur les points
|
|
de Gauss affectee du poids de Gauss correspondant.
|
|
|
|
I = somme(F(GaussPt) * GaussW) sur i = 1 jusqu'a l'ordre d'integration.
|
|
|
|
Une integrale multiple est une somme recursive sur toutes les variables.
|
|
|
|
Tout le calcul est effectue dans la methode recursive_iteration appelee n fois.
|
|
(n = nombre de variables)
|
|
|
|
Cette methode fait une sommation sur toutes les variables, sur tous les ordres
|
|
d'integration correspondants de la valeur de la fonction aux points et poids
|
|
de Gauss.
|
|
|
|
*/
|
|
|
|
//#ifndef DEB
|
|
#define No_Standard_RangeError
|
|
#define No_Standard_OutOfRange
|
|
#define No_Standard_DimensionError
|
|
//#endif
|
|
|
|
#include <math_GaussMultipleIntegration.ixx>
|
|
#include <math.hxx>
|
|
#include <math_Matrix.hxx>
|
|
#include <math_Vector.hxx>
|
|
#include <math_IntegerVector.hxx>
|
|
#include <math_MultipleVarFunction.hxx>
|
|
|
|
class IntegrationFunction {
|
|
|
|
// Cette classe sert a conserver dans les champs les valeurs de tests de
|
|
// la fonction recursive.(En particulier le pointeur sur la fonction F,
|
|
// heritant d'une classe abstraite, non traite en cdl.)
|
|
|
|
math_MultipleVarFunction *Fsav;
|
|
math_IntegerVector Ordsav;
|
|
Standard_Integer NVarsav;
|
|
math_Vector xr;
|
|
math_Vector xm;
|
|
math_Matrix GaussPoint;
|
|
math_Matrix GaussWeight;
|
|
Standard_Real Val;
|
|
Standard_Boolean Done;
|
|
|
|
public:
|
|
IntegrationFunction(math_MultipleVarFunction& F,
|
|
const Standard_Integer maxsav, const Standard_Integer NVar,
|
|
const math_IntegerVector& Ord,
|
|
const math_Vector& Lowsav,
|
|
const math_Vector& Uppsav);
|
|
|
|
Standard_Real Value() ;
|
|
Standard_Boolean IsDone() const;
|
|
Standard_Boolean recursive_iteration(Standard_Integer& n, math_IntegerVector& inc);
|
|
};
|
|
|
|
IntegrationFunction::IntegrationFunction(math_MultipleVarFunction& F,
|
|
const Standard_Integer maxsav, const Standard_Integer NVar,
|
|
const math_IntegerVector& Ord,
|
|
const math_Vector& Lowsav,const math_Vector& Uppsav):
|
|
Ordsav(1, NVar),
|
|
xr(1, NVar),
|
|
xm(1, NVar),
|
|
GaussPoint(1, NVar, 1, maxsav),
|
|
GaussWeight(1, NVar, 1, maxsav)
|
|
{
|
|
|
|
Standard_Integer i, k;
|
|
math_IntegerVector inc(1, NVar);
|
|
inc.Init(0);
|
|
Fsav = &F;
|
|
NVarsav = NVar;
|
|
Ordsav = Ord;
|
|
Done = Standard_False;
|
|
|
|
//Recuperation des points et poids de Gauss dans le fichier GaussPoints
|
|
for (i =1; i<= NVarsav; i++) {
|
|
xm(i) = 0.5*(Lowsav(i) + Uppsav(i));
|
|
xr(i) = 0.5*(Uppsav(i) - Lowsav(i));
|
|
math_Vector GP(1,Ordsav(i)), GW(1,Ordsav(i));
|
|
math::GaussPoints(Ordsav(i),GP);
|
|
math::GaussWeights(Ordsav(i),GW);
|
|
for (k = 1; k <= Ordsav(i); k++) {
|
|
GaussPoint(i,k) = GP(k); //kieme point et poids de
|
|
GaussWeight(i,k) = GW(k);//Gauss de la variable i.
|
|
}
|
|
}
|
|
Val = 0.0;
|
|
Standard_Integer Iterdeb = 1;
|
|
Standard_Boolean recur = recursive_iteration(Iterdeb, inc);
|
|
if (recur) {
|
|
//On ramene l'integration a la bonne echelle.
|
|
for ( i = 1; i <= NVarsav; i++) {
|
|
Val *= xr(i);
|
|
}
|
|
Done = Standard_True;
|
|
}
|
|
}
|
|
|
|
Standard_Real IntegrationFunction::Value() {
|
|
return Val;
|
|
}
|
|
|
|
Standard_Boolean IntegrationFunction::IsDone() const{
|
|
return Done;
|
|
}
|
|
|
|
Standard_Boolean IntegrationFunction::recursive_iteration(Standard_Integer& n,
|
|
math_IntegerVector& inc) {
|
|
|
|
// Termination criterium :
|
|
// Calcul de la valeur de la fonction aux points de Gauss fixes:
|
|
int local;
|
|
if (n == (NVarsav+1)) {
|
|
math_Vector dx(1, NVarsav);
|
|
Standard_Integer j ;
|
|
for ( j = 1; j <= NVarsav; j++) {
|
|
dx(j) = xr(j)* GaussPoint(j, inc(j));
|
|
}
|
|
Standard_Real F1;
|
|
Standard_Boolean Ok = Fsav->Value(xm + dx, F1);
|
|
if (!Ok) {return Standard_False;};
|
|
Standard_Real Interm = 1;
|
|
for ( j = 1; j <= NVarsav; j++) {
|
|
Interm *= GaussWeight(j, inc(j));
|
|
}
|
|
Val += Interm*F1;
|
|
return Standard_True;
|
|
}
|
|
|
|
// Calcul recursif, pour chaque variable n de la valeur de la fonction aux
|
|
// Ordsav(n) points de Gauss.
|
|
|
|
Standard_Boolean OK=Standard_False;
|
|
for (inc(n) = 1; inc(n) <= Ordsav(n); inc(n)++) {
|
|
local = n + 1;
|
|
OK = recursive_iteration(local, inc);
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
math_GaussMultipleIntegration::
|
|
math_GaussMultipleIntegration(math_MultipleVarFunction& F,
|
|
const math_Vector& Lower,
|
|
const math_Vector& Upper,
|
|
const math_IntegerVector& Order)
|
|
{
|
|
Standard_Integer MaxOrder = math::GaussPointsMax();
|
|
|
|
Standard_Integer i, max =0;
|
|
Standard_Integer NVar = F.NbVariables();
|
|
math_IntegerVector Ord(1, NVar);
|
|
math_Vector Lowsav(1, NVar);
|
|
math_Vector Uppsav(1, NVar);
|
|
Lowsav = Lower;
|
|
Uppsav = Upper;
|
|
// Ord = Order;
|
|
Done = Standard_False;
|
|
for (i = 1; i <= NVar; i++) {
|
|
if (Order(i) > MaxOrder) {
|
|
Ord(i) = MaxOrder;
|
|
}
|
|
else {
|
|
Ord(i) = Order(i);
|
|
}
|
|
if(Ord(i) >= max) {max = Ord(i);}
|
|
}
|
|
|
|
//Calcul de l'integrale aux points de Gauss.
|
|
// Il s agit d une somme multiple sur le domaine [Lower, Upper].
|
|
|
|
IntegrationFunction Func(F, max, NVar, Ord, Lowsav, Uppsav);
|
|
if (Func.IsDone()) {
|
|
Val = Func.Value();
|
|
Done = Standard_True;
|
|
}
|
|
}
|
|
|
|
void math_GaussMultipleIntegration::Dump(Standard_OStream& o) const {
|
|
|
|
o <<"math_GaussMultipleIntegration ";
|
|
if (Done) {
|
|
o << " Status = Done \n";
|
|
o << " Integration value = " << Val <<"\n";
|
|
}
|
|
else {
|
|
o << "Status = not Done \n";
|
|
}
|
|
}
|
|
|
|
|
|
|