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

« back to all changes in this revision

Viewing changes to lib/src/Uncertainty/Algorithm/Simulation/MediumSafe.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-05-10 17:27:55 UTC
  • mfrom: (1.1.4 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100510172755-cb5ynskknqqi5rhp
Tags: 0.13.2-2ubuntu1
* Merge with Debian testing. No changes left.
* ubuntu_fix-python-2.6.patch: fix detection of python 2.6 libs, to not use
  LOCALMODLIBS. This pulls a dependency on SSL and makes the package FTBFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//                                               -*- C++ -*-
 
2
/**
 
3
 *  @file  MediumSafe.cxx
 
4
 *  @brief Find the roots in a given direction according to the Proban
 
5
 *
 
6
 *  (C) Copyright 2005-2010 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: 2010-02-04 16:44:49 +0100 (jeu. 04 févr. 2010) $
 
24
 *  Id:      $Id: MediumSafe.cxx 1473 2010-02-04 15:44:49Z dutka $
 
25
 */
 
26
#include "MediumSafe.hxx"
 
27
#include "NumericalPoint.hxx"
 
28
 
 
29
namespace OpenTURNS
 
30
{
 
31
 
 
32
  namespace Uncertainty 
 
33
  {
 
34
 
 
35
    namespace Algorithm
 
36
    {
 
37
 
 
38
      typedef OT::Base::Type::NumericalPoint NumericalPoint;
 
39
 
 
40
      /**
 
41
       * @class MediumSafe
 
42
       */
 
43
 
 
44
      CLASSNAMEINIT(MediumSafe);
 
45
 
 
46
      /* Constructor with parameters */
 
47
      MediumSafe::MediumSafe():
 
48
        RootStrategyImplementation()
 
49
      {
 
50
        // Nothing to do
 
51
      }
 
52
 
 
53
      /* Constructor with parameters */
 
54
      MediumSafe::MediumSafe(const Solver & solver):
 
55
        RootStrategyImplementation(solver)
 
56
      {
 
57
        // Nothing to do
 
58
      }
 
59
 
 
60
      /* Constructor with parameters */
 
61
      MediumSafe::MediumSafe(const Solver & solver,
 
62
                             const NumericalScalar maximumDistance,
 
63
                             const NumericalScalar stepSize):
 
64
        RootStrategyImplementation(solver, maximumDistance, stepSize)
 
65
      {
 
66
        // Nothing to do
 
67
      }
 
68
 
 
69
      /* Virtual constructor */
 
70
      MediumSafe * MediumSafe::clone() const
 
71
      {
 
72
        return new MediumSafe(*this);
 
73
      }
 
74
 
 
75
      /* Solve gives all the roots found applying the root strategy */
 
76
      MediumSafe::NumericalScalarCollection MediumSafe::solve(const NumericalMathFunction & function,
 
77
                                                              const NumericalScalar value)
 
78
      {
 
79
        NumericalScalarCollection result(0);
 
80
        NumericalScalar infPoint(0.0);
 
81
        NumericalScalar infValue;
 
82
        // Get the value of the function at the origin
 
83
        try
 
84
          {
 
85
            infValue = getOriginValue();
 
86
          }
 
87
        // If it has not yet been computed, compute it and store it
 
88
        catch (NotDefinedException & ex)
 
89
          {
 
90
            infValue = function(NumericalPoint(1, infPoint))[0];
 
91
            setOriginValue(infValue);
 
92
          }
 
93
        NumericalScalar maximumDistance(getMaximumDistance());
 
94
        NumericalScalar stepSize(getStepSize());
 
95
        Solver solver(getSolver());
 
96
        while(infPoint < maximumDistance)
 
97
          {
 
98
            NumericalScalar supPoint(std::min(infPoint + stepSize, maximumDistance));
 
99
            NumericalScalar supValue(function(NumericalPoint(1, supPoint))[0]);
 
100
            if ((infValue - value) * (supValue - value) < 0.0)
 
101
              {
 
102
                result.add(solver.solve(function, value, infPoint, supPoint, infValue, supValue));
 
103
                return result;
 
104
              }
 
105
            infPoint = supPoint;
 
106
            infValue = supValue;
 
107
          }
 
108
        return result;
 
109
      }
 
110
 
 
111
      /* String converter */
 
112
      String MediumSafe::__repr__() const
 
113
      {
 
114
        OSS oss;
 
115
        oss << "class=" << MediumSafe::GetClassName()
 
116
            << " derived from " << RootStrategyImplementation::__repr__();
 
117
        return oss;
 
118
      }
 
119
 
 
120
    } /* namespace Algorithm */
 
121
  } /* namespace Uncertainty */
 
122
} /* namespace OpenTURNS */