RSTT  3.2.0
Regional Seismic Travel Time
All Classes Namespaces Files Functions Variables Typedefs Friends Macros
Brents.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 National Technology & Engineering Solutions of Sandia, LLC
4 //- (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
5 //- Government retains certain rights in this software.
6 //-
7 //- BSD Open Source License
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- 1. Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //-
16 //- 2. Redistributions in binary form must reproduce the above copyright
17 //- notice, this list of conditions and the following disclaimer in the
18 //- documentation and/or other materials provided with the distribution.
19 //-
20 //- 3. Neither the name of the copyright holder nor the names of its
21 //- contributors may be used to endorse or promote products derived from
22 //- this software without specific prior written permission.
23 //-
24 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 //- POSSIBILITY OF SUCH DAMAGE.
35 //-
36 //- ****************************************************************************
37 
38 #ifndef BRENTS_H
39 #define BRENTS_H
40 
41 // **** _SYSTEM INCLUDES_ ******************************************************
42 
43 #include <vector>
44 
45 using namespace std;
46 // use standard library objects
47 
48 // **** _LOCAL INCLUDES_ *******************************************************
49 
50 #include "UtilGlobals.h"
51 
52 // **** _BEGIN UTIL NAMESPACE_ *************************************************
53 
54 namespace util {
55 
56 // **** _CLASS CONSTANTS_ ******************************************************
57 // **** _FORWARD REFERENCES_ ***************************************************
58 
59 // **** _CLASS DEFINITION_ *****************************************************
60 //
64 //
73 //
74 // *****************************************************************************
75 template<class F>
77 {
78  public:
79 
80  // **** _PUBLIC LIFCYCLES_ *************************************************
81 
83  Brents();
84 
88  Brents(F& f, double tol);
89 
91  Brents(const Brents<F>& zb);
92 
94  virtual ~Brents();
95 
96  // **** _PUBLIC OPERATORS_ *************************************************
97 
100 
101  // **** _PUBLIC METHODS_ ***************************************************
102 
104  //
144  double zeroF(double ax, double bx);
145 
148  //
154  double minF(double ax, double bx, double cx,
155  double& xmin);
156 
158  void setF(F& f);
159 
161  F& getF();
162 
164  const F& getF() const;
165 
167  void setTolerance(double tol);
168 
170  double getTolerance() const;
171 
175 
179 
182  bool isMinimumSearch() const;
183 
185  //static void getTest1(double a, double b, double tol);
186 
188  //static void getTest2(double a, double b, double c, double tol,
189  // const string& minmax);
190 
191 private:
192 
193  // **** _PRIVATE DATA_ *****************************************************
194 
196  double zbTol;
197 
200  F* zbF;
201 
208  double bMinMaxFlg;
209 };
210 
211 // **** _INLINE FUNCTION IMPLEMENTATIONS_ **************************************
212 
214 template<class F>
215 inline void Brents<F>::setF(F& f)
216 {
217  zbF = &f;
218 }
219 
221 template<class F>
222 inline F& Brents<F>::getF()
223 {
224  return *zbF;
225 }
226 
228 template<class F>
229 inline const F& Brents<F>::getF() const
230 {
231  return *zbF;
232 }
233 
235 template<class F>
236 inline void Brents<F>::setTolerance(double tol)
237 {
238  zbTol = tol;
239 }
240 
242 template<class F>
243 inline double Brents<F>::getTolerance() const
244 {
245  return zbTol;
246 }
247 
249 //
251 template<class F>
253 {
254  bMinMaxFlg = 1.0;
255 }
256 
258 //
260 template<class F>
262 {
263  bMinMaxFlg = -1.0;
264 }
265 
267 //
269 template<class F>
270 inline bool Brents<F>::isMinimumSearch() const
271 {
272  return ((bMinMaxFlg == 1.0) ? true : false);
273 }
274 
275 // **** _TEST FUNCTION IMPLEMENTATIONS_ **************************************
276 
281 //class TestZeroIn1
282 //{
283 // public:
284 //
285 // //! Default Constructor.
286 // TestZeroIn1() {};
287 //
288 // //! Copy Constructor.
289 // TestZeroIn1(const TestZeroIn1& tzif) {};
290 //
291 // //! Destructor.
292 // ~TestZeroIn1() {};
293 //
294 // //! Assignment Operator.
295 // TestZeroIn1& operator=(const TestZeroIn1& tzif)
296 // {return *this;};
297 //
298 // //! \brief Function parentheses operator(). Returns a double given a
299 // //! single double argument. This function is the function to be zeroed.
300 // //! and for which a maximum (or minimum) will be found.
301 // double operator()(double x)
302 // {
303 // ++fccnt;
304 // return 47 - (2.0 * x * x * x - 3.0 * x + 2.0);
305 // };
306 //
307 // //! Zeros the function call count.
308 // void resetFCCount() {fccnt = 0;};
309 //
310 // //! Returns the function call count.
311 // int getFCCount() const {return fccnt;};
312 //
313 // private:
314 //
315 // //! \brief The integrand function call count. Used to examine the
316 // //! number of times the operator()(double x) function is called.
317 // int fccnt;
318 //};
319 
324 //class TestMaxF2
325 //{
326 // public:
327 //
328 // //! Default Constructor.
329 // TestMaxF2() {};
330 //
331 // //! Copy Constructor.
332 // TestMaxF2(const TestMaxF2& tmf) {};
333 //
334 // //! Destructor.
335 // ~TestMaxF2() {};
336 //
337 // //! Assignment Operator.
338 // TestMaxF2& operator=(const TestMaxF2& tmf)
339 // {return *this;};
340 //
341 // //! \brief Function parentheses operator(). Returns a double given a
342 // //! single double argument. This function is the function for which
343 // //! a maximum (or minimum) will be found. These exist at +-sqrt(2)/2.
344 // double operator()(double x)
345 // {
346 // ++fccnt;
347 // return (2.0 * x * x * x - 3.0 * x + 2.0);
348 // };
349 //
350 // //! Zeros the function call count.
351 // void resetFCCount() {fccnt = 0;};
352 //
353 // //! Returns the function call count.
354 // int getFCCount() const {return fccnt;};
355 //
356 // private:
357 //
358 // //! \brief The integrand function call count. Used to examine the
359 // //! number of times the operator()(double x) function is called.
360 // int fccnt;
361 //};
362 
363 } // end namespace util
364 
365 #endif // BRENTS_H
#define UTIL_EXP
Definition: UtilGlobals.h:66
Class supports Brents zeroF and minF functions that finds the root of or minimum (maximum) of a provi...
Definition: Brents.h:77
void setTolerance(double tol)
Sets the tolerance value.
Definition: Brents.h:236
Brents< F > & operator=(const Brents< F > &zb)
Assignment Operator.
double zeroF(double ax, double bx)
function zeroF - obtains a function zero within the given range.
Brents(F &f, double tol)
Standard Constructor.
Brents()
Default Constructor.
void setMinimumSearch()
Sets the search method to a minimum (the default).
Definition: Brents.h:252
F & getF()
Returns a reference to the functional.
Definition: Brents.h:222
void setF(F &f)
Sets the functional to f.
Definition: Brents.h:215
bool isMinimumSearch() const
Returns true if the search method is a minimum.
Definition: Brents.h:270
double getTolerance() const
Returns the tolerance value.
Definition: Brents.h:243
virtual ~Brents()
Destructor.
const F & getF() const
Returns a const reference to the functional.
Definition: Brents.h:229
double minF(double ax, double bx, double cx, double &xmin)
Returns the functional minimum between the input abscissas ax and cx at the internall defined functio...
void setMaximumSearch()
Sets the search method to a maximum.
Definition: Brents.h:261
Brents(const Brents< F > &zb)
Copy Constructor.
Definition: Brents.h:54