queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
UniformOneDGrid.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2017 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
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. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/UniformOneDGrid.h>
26 
27 namespace QUESO {
28 
29 // Constructor-------------------------------------------
30 template<class T>
32  const BaseEnvironment& env,
33  const char* prefix,
34  unsigned int size,
35  T minPosition,
36  T maxPosition)
37  :
38  BaseOneDGrid<T>(env,prefix),
39  m_size (size),
40  m_minPosition(minPosition),
41  m_maxPosition(maxPosition)
42 {
43  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
44  *m_env.subDisplayFile() << "Entering UniformOneDGrid<T>::constructor()"
45  << ": prefix = " << m_prefix
46  << std::endl;
47  }
48 
49  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 5)) {
50  *m_env.subDisplayFile() << "Leaving UniformOneDGrid<T>::constructor()"
51  << ": prefix = " << m_prefix
52  << std::endl;
53  }
54 }
55 // Destructor--------------------------------------------
56 template<class T>
58 {
59 }
60 // Math methods------------------------------------------
61 template<class T>
62 unsigned int
64 {
65  return m_size;
66 }
67 //-------------------------------------------------------
68 template<class T>
69 T
70 UniformOneDGrid<T>::operator[](unsigned int i) const
71 {
72  queso_require_less_msg(i, m_size, "too large i");
73 
74  T ratio = ((T) i)/(((T)m_size)-1.); // IMPORTANT: Yes, '-1.'
75  T position = (1.-ratio)*m_minPosition + ratio*m_maxPosition;
76  return position;
77 }
78 //-------------------------------------------------------
79 template<class T>
80 unsigned int
81 UniformOneDGrid<T>::findIntervalId(const T& paramValue) const
82 {
83  queso_require_msg(!((paramValue < m_minPosition) || (m_maxPosition < paramValue)), "paramValue is out of domain");
84 
85  T ratio = (paramValue - m_minPosition)/(m_maxPosition - m_minPosition);
86  unsigned int i = (unsigned int) (ratio*(m_size-1.));
87  if ((i > 0 ) &&
88  ((*this)[i] > paramValue)) {
89  i--;
90  }
91 
92  return i;
93 }
94 
95 } // End namespace QUESO
96 
97 template class QUESO::UniformOneDGrid<double>;
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:198
std::string m_prefix
Definition: OneDGrid.h:83
~UniformOneDGrid()
Destructor.
Base class for accommodating one-dimensional grids.
Definition: OneDGrid.h:46
const BaseEnvironment & m_env
Definition: OneDGrid.h:82
unsigned int size() const
Grid size; the amount of points that defines the grid.
unsigned int findIntervalId(const T &paramValue) const
Finds the ID of an interval. See template specialization.
T operator[](unsigned int i) const
Returns the position of the i-th point in the grid.
UniformOneDGrid(const BaseEnvironment &env, const char *prefix, unsigned int size, T minPosition, T maxPosition)
Default constructor.
Class for accommodating uniform one-dimensional grids.
unsigned int displayVerbosity() const
Definition: Environment.C:450
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320

Generated on Tue Jun 5 2018 19:48:55 for queso-0.57.1 by  doxygen 1.8.5