~ubuntu-branches/ubuntu/maverick/openturns/maverick

« back to all changes in this revision

Viewing changes to lib/src/Base/Func/NumericalMathFunctionImplementation.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2008-11-18 06:32:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20081118063222-pa0qncclrerrqkg2
Tags: 0.12.2-1
* New upstream release
* Bug fix: "New upstream release available (0.12.2)", thanks to Jerome
  Robert (Closes: #506005).
* Applied patch by J. Robert.
* debian/control: build-depends on libxml2

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21
21
 *
22
22
 *  @author: $LastChangedBy: dutka $
23
 
 *  @date:   $LastChangedDate: 2008-06-26 13:50:17 +0200 (jeu, 26 jun 2008) $
24
 
 *  Id:      $Id: NumericalMathFunctionImplementation.cxx 862 2008-06-26 11:50:17Z dutka $
 
23
 *  @date:   $LastChangedDate: 2008-10-15 17:56:07 +0200 (mer 15 oct 2008) $
 
24
 *  Id:      $Id: NumericalMathFunctionImplementation.cxx 972 2008-10-15 15:56:07Z dutka $
25
25
 */
26
26
#include "NumericalMathFunction.hxx"
27
27
#include "NumericalMathFunctionImplementation.hxx"
35
35
#include "CenteredFiniteDifferenceGradient.hxx"
36
36
#include "CenteredFiniteDifferenceHessian.hxx"
37
37
#include "PersistentObjectFactory.hxx"
38
 
#include "WrapperFile.hxx"
39
38
#include "Log.hxx"
40
39
#include "OSS.hxx"
41
40
 
61
60
 
62
61
      /* Default constructor */
63
62
      NumericalMathFunctionImplementation::NumericalMathFunctionImplementation()
64
 
        : PersistentObject(OT::DefaultName),
65
 
          p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation(OT::DefaultName)),
66
 
          p_gradientImplementation_(new NoNumericalMathGradientImplementation(OT::DefaultName)),
67
 
          p_hessianImplementation_(new NoNumericalMathHessianImplementation(OT::DefaultName)),
 
63
        : PersistentObject(),
 
64
          p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation),
 
65
          p_gradientImplementation_(new NoNumericalMathGradientImplementation),
 
66
          p_hessianImplementation_(new NoNumericalMathHessianImplementation),
68
67
          p_initialEvaluationImplementation_(p_evaluationImplementation_),
69
68
          p_initialGradientImplementation_(p_gradientImplementation_),
70
69
          p_initialHessianImplementation_(p_hessianImplementation_)
72
71
        // Nothing to do
73
72
      }
74
73
 
75
 
      /* Default constructor */
 
74
      /* Constructor from a wrapper name */
76
75
      NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const String & name)
77
76
        : PersistentObject(name),
78
 
          p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation(OT::DefaultName)),
79
 
          p_gradientImplementation_(new NoNumericalMathGradientImplementation(OT::DefaultName)),
80
 
          p_hessianImplementation_(new NoNumericalMathHessianImplementation(OT::DefaultName)),
81
 
          p_initialEvaluationImplementation_(p_evaluationImplementation_),
82
 
          p_initialGradientImplementation_(p_gradientImplementation_),
83
 
          p_initialHessianImplementation_(p_hessianImplementation_)
84
 
      {
85
 
        // We need to constructs object in the body because of some useful temporary
86
 
        // It also speeds the creation of the object because the wrapper file is parsed only once
87
 
        FileName wrapperPath;
88
 
          
89
 
        // Find the path of the wrapper file that describes the numerical
90
 
        // math function interface
91
 
        wrapperPath = Common::WrapperFile::FindWrapperPathByName( name );
92
 
          
93
 
        // Open the wrapper file and get the name of the library and the names of
94
 
        // the function, its gradient and its hessian if defined
95
 
        // If the gradient or the hessian are not defined, ask for default ones
96
 
        // Then create the actual functions
97
 
        // Get also the data read inside the wrapper file and pass them to the wrapper
98
 
        Common::WrapperFile wrapperFile( wrapperPath );
99
 
          
 
77
          p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation),
 
78
          p_gradientImplementation_(new NoNumericalMathGradientImplementation),
 
79
          p_hessianImplementation_(new NoNumericalMathHessianImplementation),
 
80
          p_initialEvaluationImplementation_(p_evaluationImplementation_),
 
81
          p_initialGradientImplementation_(p_gradientImplementation_),
 
82
          p_initialHessianImplementation_(p_hessianImplementation_)
 
83
      {
 
84
        // Read the description file of the wrapper
 
85
        WrapperFile wrapperFile = WrapperFile::FindWrapperByName( name );
 
86
        
 
87
        // We set the implementations
 
88
        initImplementations( wrapperFile );
 
89
      }
 
90
 
 
91
      /* Constructor from a wrapper file */
 
92
      NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const WrapperFile & wrapperFile)
 
93
        : PersistentObject(wrapperFile.getName()),
 
94
          p_evaluationImplementation_(new NoNumericalMathEvaluationImplementation),
 
95
          p_gradientImplementation_(new NoNumericalMathGradientImplementation),
 
96
          p_hessianImplementation_(new NoNumericalMathHessianImplementation),
 
97
          p_initialEvaluationImplementation_(p_evaluationImplementation_),
 
98
          p_initialGradientImplementation_(p_gradientImplementation_),
 
99
          p_initialHessianImplementation_(p_hessianImplementation_)
 
100
      {
 
101
        // We set the implementations
 
102
        initImplementations( wrapperFile );
 
103
      }
 
104
 
 
105
 
 
106
      /* This method set the implementations with the values listed in the wrapper file */
 
107
      void NumericalMathFunctionImplementation::initImplementations(const WrapperFile & wrapperFile)
 
108
      {
 
109
        const String name = wrapperFile.getName();
 
110
 
100
111
        ComputedNumericalMathEvaluationImplementation * implementation = new ComputedNumericalMathEvaluationImplementation( name, wrapperFile );
101
112
        p_evaluationImplementation_.reset(implementation);
102
113
        try {
103
114
          p_gradientImplementation_.reset(new ComputedNumericalMathGradientImplementation( name, wrapperFile, implementation->getState() ));
104
115
        }
105
116
        catch (Common::Exception & ex) {
106
 
          Log::Debug(OSS() << "DBG - " << ex.type() << " catched. Using CenteredFiniteDifferenceGradient for gradient");
 
117
          Log::Debug(OSS() << "" << ex.type() << " catched. Using CenteredFiniteDifferenceGradient for gradient");
107
118
          p_gradientImplementation_.reset(new CenteredFiniteDifferenceGradient(sqrt(CenteredFiniteDifferenceGradient::DefaultEpsilon), p_evaluationImplementation_));
108
119
        }
109
120
          
111
122
          p_hessianImplementation_.reset(new ComputedNumericalMathHessianImplementation( name, wrapperFile, implementation->getState() ));
112
123
        }
113
124
        catch (Common::Exception & ex) {
114
 
          Log::Debug(OSS() << "DBG - " << ex.type() << " catched. Using CenteredFiniteDifferenceHessian for hessian");
 
125
          Log::Debug(OSS() << "" << ex.type() << " catched. Using CenteredFiniteDifferenceHessian for hessian");
115
126
          p_hessianImplementation_.reset(new CenteredFiniteDifferenceHessian(sqrt(CenteredFiniteDifferenceHessian::DefaultEpsilon), p_evaluationImplementation_));
116
127
        }
117
 
 
118
128
      }
119
129
 
 
130
 
120
131
      /* Analytical formula constructor */
121
132
      NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const Description & inputVariablesNames,
122
133
                                                                               const Description & outputVariablesNames,
123
 
                                                                               const Description & formulas,
124
 
                                                                               const String & name)
125
 
        : PersistentObject(name),
126
 
          p_evaluationImplementation_(new AnalyticalNumericalMathEvaluationImplementation(inputVariablesNames, outputVariablesNames, formulas, name)),
 
134
                                                                               const Description & formulas)
 
135
        : PersistentObject(),
 
136
          p_evaluationImplementation_(new AnalyticalNumericalMathEvaluationImplementation(inputVariablesNames, outputVariablesNames, formulas)),
127
137
          p_gradientImplementation_(new CenteredFiniteDifferenceGradient(CenteredFiniteDifferenceGradient::DefaultEpsilon, p_evaluationImplementation_)),
128
138
          p_hessianImplementation_(new CenteredFiniteDifferenceHessian(CenteredFiniteDifferenceHessian::DefaultEpsilon, p_evaluationImplementation_)),
129
139
          p_initialEvaluationImplementation_(p_evaluationImplementation_),
134
144
      }
135
145
 
136
146
      /* Single function implementation constructor */
137
 
      NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const EvaluationImplementation & evaluationImplementation,
138
 
                                                                               const String & name)
139
 
        : PersistentObject(name),
 
147
      NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const EvaluationImplementation & evaluationImplementation)
 
148
        : PersistentObject(),
140
149
          p_evaluationImplementation_(evaluationImplementation),
141
150
          p_gradientImplementation_(new CenteredFiniteDifferenceGradient(CenteredFiniteDifferenceGradient::DefaultEpsilon, p_evaluationImplementation_)),
142
151
          p_hessianImplementation_(new CenteredFiniteDifferenceHessian(CenteredFiniteDifferenceHessian::DefaultEpsilon, p_evaluationImplementation_)),
150
159
      /* Constructor from implementations */
151
160
      NumericalMathFunctionImplementation::NumericalMathFunctionImplementation(const EvaluationImplementation & evaluationImplementation,
152
161
                                                                               const GradientImplementation & gradientImplementation,
153
 
                                                                               const HessianImplementation  & hessianImplementation,
154
 
                                                                               const String & name)
155
 
        : PersistentObject(name),
 
162
                                                                               const HessianImplementation  & hessianImplementation)
 
163
        : PersistentObject(),
156
164
          p_evaluationImplementation_(evaluationImplementation),
157
165
          p_gradientImplementation_(gradientImplementation),
158
166
          p_hessianImplementation_(hessianImplementation),