4
* @brief Find the roots in a given direction according to the Proban
6
* (C) Copyright 2005-2010 EDF-EADS-Phimeca
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.
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.
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
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 $
26
#include "MediumSafe.hxx"
27
#include "NumericalPoint.hxx"
38
typedef OT::Base::Type::NumericalPoint NumericalPoint;
44
CLASSNAMEINIT(MediumSafe);
46
/* Constructor with parameters */
47
MediumSafe::MediumSafe():
48
RootStrategyImplementation()
53
/* Constructor with parameters */
54
MediumSafe::MediumSafe(const Solver & solver):
55
RootStrategyImplementation(solver)
60
/* Constructor with parameters */
61
MediumSafe::MediumSafe(const Solver & solver,
62
const NumericalScalar maximumDistance,
63
const NumericalScalar stepSize):
64
RootStrategyImplementation(solver, maximumDistance, stepSize)
69
/* Virtual constructor */
70
MediumSafe * MediumSafe::clone() const
72
return new MediumSafe(*this);
75
/* Solve gives all the roots found applying the root strategy */
76
MediumSafe::NumericalScalarCollection MediumSafe::solve(const NumericalMathFunction & function,
77
const NumericalScalar value)
79
NumericalScalarCollection result(0);
80
NumericalScalar infPoint(0.0);
81
NumericalScalar infValue;
82
// Get the value of the function at the origin
85
infValue = getOriginValue();
87
// If it has not yet been computed, compute it and store it
88
catch (NotDefinedException & ex)
90
infValue = function(NumericalPoint(1, infPoint))[0];
91
setOriginValue(infValue);
93
NumericalScalar maximumDistance(getMaximumDistance());
94
NumericalScalar stepSize(getStepSize());
95
Solver solver(getSolver());
96
while(infPoint < maximumDistance)
98
NumericalScalar supPoint(std::min(infPoint + stepSize, maximumDistance));
99
NumericalScalar supValue(function(NumericalPoint(1, supPoint))[0]);
100
if ((infValue - value) * (supValue - value) < 0.0)
102
result.add(solver.solve(function, value, infPoint, supPoint, infValue, supValue));
111
/* String converter */
112
String MediumSafe::__repr__() const
115
oss << "class=" << MediumSafe::GetClassName()
116
<< " derived from " << RootStrategyImplementation::__repr__();
120
} /* namespace Algorithm */
121
} /* namespace Uncertainty */
122
} /* namespace OpenTURNS */