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

« back to all changes in this revision

Viewing changes to lib/src/Uncertainty/Algorithm/MetaModel/Taylor/QuadraticTaylor.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:
 
1
//                                               -*- C++ -*-
 
2
/**
 
3
 *  @file  QuadraticTaylor.cxx
 
4
 *  @brief Second order polynomial response surface by Taylor expansion
 
5
 *
 
6
 *  (C) Copyright 2005-2007 EDF-EADS-Phimeca
 
7
 *
 
8
 *  This library is free software; you can redistribute it and/or
 
9
 *  modify it under the terms of the GNU Lesser General Public
 
10
 *  License as published by the Free Software Foundation; either
 
11
 *  version 2.1 of the License.
 
12
 *
 
13
 *  This library is distributed in the hope that it will be useful
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 *  Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public
 
19
 *  License along with this library; if not, write to the Free Software
 
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
21
 *
 
22
 *  @author: $LastChangedBy: dutka $
 
23
 *  @date:   $LastChangedDate: 2008-09-13 22:37:56 +0200 (sam 13 sep 2008) $
 
24
 *  Id:      $Id: QuadraticTaylor.cxx 929 2008-09-13 20:37:56Z dutka $
 
25
 */
 
26
#include "QuadraticTaylor.hxx"
 
27
#include "QuadraticNumericalMathEvaluationImplementation.hxx"
 
28
#include "LinearNumericalMathGradientImplementation.hxx"
 
29
#include "ConstantNumericalMathHessianImplementation.hxx"
 
30
 
 
31
namespace OpenTURNS {
 
32
 
 
33
  namespace Uncertainty {
 
34
 
 
35
    namespace Algorithm {
 
36
 
 
37
      typedef Base::Func::QuadraticNumericalMathEvaluationImplementation QuadraticNumericalMathEvaluationImplementation;
 
38
      typedef Base::Func::LinearNumericalMathGradientImplementation    LinearNumericalMathGradientImplementation;
 
39
      typedef Base::Func::ConstantNumericalMathHessianImplementation   ConstantNumericalMathHessianImplementation;
 
40
 
 
41
      CLASSNAMEINIT(QuadraticTaylor);
 
42
 
 
43
      QuadraticTaylor::QuadraticTaylor(const String & name):
 
44
        PersistentObject(name)
 
45
      {
 
46
        // Nothing to do
 
47
      }
 
48
 
 
49
      /* Constructor with parameters */
 
50
      QuadraticTaylor::QuadraticTaylor(const NumericalPoint & center,
 
51
                                       const NumericalMathFunction & inputFunction,
 
52
                                       const String & name):
 
53
        PersistentObject(name),
 
54
        center_(center),
 
55
        inputFunction_(inputFunction)
 
56
      {
 
57
        // Nothing to do
 
58
      }
 
59
 
 
60
      /* Virtual constructor */
 
61
      QuadraticTaylor * QuadraticTaylor::clone() const
 
62
      {
 
63
        return new QuadraticTaylor(*this);
 
64
      }
 
65
 
 
66
      /* String converter */
 
67
      String QuadraticTaylor::str() const
 
68
      {
 
69
        OSS oss;
 
70
        oss << "class=" << GetClassName()
 
71
            << " name=" << getName()
 
72
            << " center=" << center_
 
73
            << " function=" << inputFunction_
 
74
            << " responseSurface=" << responseSurface_
 
75
            << " constant=" << constant_
 
76
            << " linear=" << linear_
 
77
            << " quadratic=" << quadratic_;
 
78
        return oss;
 
79
      }
 
80
 
 
81
      /* Response surface computation */
 
82
      void QuadraticTaylor::run()
 
83
      {
 
84
        /* Compute the three first terms of the Taylor expansion */
 
85
        constant_ = inputFunction_(center_);
 
86
        linear_ = inputFunction_.gradient(center_);
 
87
        quadratic_ = inputFunction_.hessian(center_);
 
88
        /* Build the several implementations and set it into the response surface */
 
89
        responseSurface_.setEvaluationImplementation(new QuadraticNumericalMathEvaluationImplementation(center_, constant_, linear_, quadratic_));
 
90
        responseSurface_.setGradientImplementation(new LinearNumericalMathGradientImplementation(center_, linear_, quadratic_));
 
91
        responseSurface_.setHessianImplementation(new ConstantNumericalMathHessianImplementation(quadratic_));
 
92
        responseSurface_.setDescription(inputFunction_.getDescription());
 
93
      }
 
94
 
 
95
      /* Center accessor */
 
96
      QuadraticTaylor::NumericalPoint QuadraticTaylor::getCenter() const
 
97
      {
 
98
        return center_;
 
99
      }
 
100
 
 
101
      /* Constant accessor */
 
102
      QuadraticTaylor::NumericalPoint QuadraticTaylor::getConstant() const
 
103
      {
 
104
        return constant_;
 
105
      }
 
106
 
 
107
      /* Linear accessor */
 
108
      QuadraticTaylor::Matrix QuadraticTaylor::getLinear() const
 
109
      {
 
110
        return linear_;
 
111
      }
 
112
 
 
113
      /* Quadratic accessor */
 
114
      QuadraticTaylor::SymmetricTensor QuadraticTaylor::getQuadratic() const
 
115
      {
 
116
        return quadratic_;
 
117
      }
 
118
 
 
119
      /* Function accessor */
 
120
      QuadraticTaylor::NumericalMathFunction QuadraticTaylor::getInputFunction() const
 
121
      {
 
122
        return inputFunction_;
 
123
      }
 
124
 
 
125
      /* Response surface accessor */
 
126
      QuadraticTaylor::NumericalMathFunction QuadraticTaylor::getResponseSurface() const
 
127
      {
 
128
        return responseSurface_;
 
129
      }
 
130
 
 
131
    } /* namespace Algorithm */
 
132
  } /* namespace Uncertainty */
 
133
} /* namespace OpenTURNS */