queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::InterpolationSurrogateData< V, M > Class Template Reference

#include <InterpolationSurrogateBase.h>

Public Member Functions

 InterpolationSurrogateData (const BoxSubset< V, M > &domain, const std::vector< unsigned int > &n_points)
 
 ~InterpolationSurrogateData ()
 
const BoxSubset< V, M > & get_paramDomain () const
 
const std::vector< unsigned int > & get_n_points () const
 
const std::vector< double > & get_values () const
 
std::vector< double > & get_values ()
 
double get_value (unsigned int n) const
 
unsigned int n_values () const
 
void set_values (std::vector< double > &values)
 Set all values. Dimension must be consistent with internal m_values. More...
 
void set_value (unsigned int n, double value)
 
unsigned int dim () const
 Dimension of parameter space. More...
 
double x_min (unsigned int dim) const
 Lower bound of domain along dimension dim. More...
 
double x_max (unsigned int dim) const
 Upper bound of domain along dimension dim. More...
 
double spacing (unsigned int dim) const
 Spacing between points along dimension dim. More...
 
double get_x (unsigned int dim, unsigned int index) const
 Get spatial coordinate value at the node index along coordinate direction dim. More...
 
void sync_values (unsigned int root)
 Sync values across all processors from root processor. More...
 

Private Member Functions

 InterpolationSurrogateData ()
 
void check_dim_consistency () const
 Helper function for constructor. More...
 
void init_values (const std::vector< unsigned int > &n_points)
 Helper function for sizing m_values. More...
 
void check_domain_bounds () const
 Helper function for checking domain extent. More...
 

Private Attributes

const BoxSubset< V, M > & m_domain
 Parameter domain over which we use surrogate. More...
 
const std::vector< unsigned int > & m_n_points
 vector to store number of points in each coordinate direction More...
 
std::vector< double > m_values
 vector to store values to be interpolated More...
 

Detailed Description

template<typename V, typename M>
class QUESO::InterpolationSurrogateData< V, M >

Definition at line 34 of file InterpolationSurrogateBase.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::InterpolationSurrogateData< V, M >::InterpolationSurrogateData ( const BoxSubset< V, M > &  domain,
const std::vector< unsigned int > &  n_points 
)

Definition at line 40 of file InterpolationSurrogateData.C.

References QUESO::InterpolationSurrogateData< V, M >::check_dim_consistency(), QUESO::InterpolationSurrogateData< V, M >::check_domain_bounds(), QUESO::InterpolationSurrogateData< V, M >::init_values(), and QUESO::InterpolationSurrogateData< V, M >::m_n_points.

42  : m_domain(domain),
43  m_n_points(n_points)
44  {
45  // This checks that the dimension of n_points and the domain are consistent
46  this->check_dim_consistency();
47 
48  // Size m_values
49  this->init_values(this->m_n_points);
50 
51  // Check the domain is bounded
52  this->check_domain_bounds();
53  }
const std::vector< unsigned int > & m_n_points
vector to store number of points in each coordinate direction
void check_domain_bounds() const
Helper function for checking domain extent.
void init_values(const std::vector< unsigned int > &n_points)
Helper function for sizing m_values.
void check_dim_consistency() const
Helper function for constructor.
const BoxSubset< V, M > & m_domain
Parameter domain over which we use surrogate.
template<typename V, typename M>
QUESO::InterpolationSurrogateData< V, M >::~InterpolationSurrogateData ( )
inline

Definition at line 43 of file InterpolationSurrogateData.h.

43 {};
template<typename V, typename M>
QUESO::InterpolationSurrogateData< V, M >::InterpolationSurrogateData ( )
private

Member Function Documentation

template<class V , class M >
void QUESO::InterpolationSurrogateData< V, M >::check_dim_consistency ( ) const
private

Helper function for constructor.

Definition at line 56 of file InterpolationSurrogateData.C.

References dim.

Referenced by QUESO::InterpolationSurrogateData< V, M >::InterpolationSurrogateData().

57  {
58  if( this->dim() != this->m_n_points.size() )
59  {
60  std::stringstream vspace_dim;
61  vspace_dim << this->m_domain.vectorSpace().dimGlobal();
62 
63  std::stringstream n_points_dim;
64  n_points_dim << this->m_n_points.size();
65 
66  std::string error = "ERROR: Mismatch between dimension of parameter space and number of points\n.";
67  error += " domain dimension = " + vspace_dim.str() + "\n";
68  error += " points dimension = " + n_points_dim.str() + "\n";
69 
70  queso_error_msg(error);
71  }
72  }
const std::vector< unsigned int > & m_n_points
vector to store number of points in each coordinate direction
const BoxSubset< V, M > & m_domain
Parameter domain over which we use surrogate.
unsigned int dim() const
Dimension of parameter space.
template<class V , class M >
void QUESO::InterpolationSurrogateData< V, M >::check_domain_bounds ( ) const
private

Helper function for checking domain extent.

Definition at line 88 of file InterpolationSurrogateData.C.

References QUESO::queso_isfinite().

Referenced by QUESO::InterpolationSurrogateData< V, M >::InterpolationSurrogateData().

89  {
90  for (unsigned int i = 0; i < m_domain.vectorSpace().dimLocal(); i++) {
91  queso_require_msg(queso_isfinite(m_domain.minValues()[i]),
92  "Interpolation with an unbounded domain is unsupported");
93  queso_require_msg(queso_isfinite(m_domain.maxValues()[i]),
94  "Interpolation with an unbounded domain is unsupported");
95  }
96  }
bool queso_isfinite(T arg)
Definition: math_macros.h:51
const BoxSubset< V, M > & m_domain
Parameter domain over which we use surrogate.
template<typename V, typename M>
unsigned int QUESO::InterpolationSurrogateData< V, M >::dim ( ) const
inline

Dimension of parameter space.

Definition at line 72 of file InterpolationSurrogateData.h.

References QUESO::InterpolationSurrogateData< V, M >::m_domain.

Referenced by QUESO::InterpolationSurrogateData< V, M >::x_max(), and QUESO::InterpolationSurrogateData< V, M >::x_min().

73  { return this->m_domain.vectorSpace().dimGlobal(); };
const BoxSubset< V, M > & m_domain
Parameter domain over which we use surrogate.
template<typename V, typename M>
const std::vector<unsigned int>& QUESO::InterpolationSurrogateData< V, M >::get_n_points ( ) const
inline

Definition at line 48 of file InterpolationSurrogateData.h.

References QUESO::InterpolationSurrogateData< V, M >::m_n_points.

Referenced by QUESO::InterpolationSurrogateIOASCII< V, M >::write().

49  { return this->m_n_points; };
const std::vector< unsigned int > & m_n_points
vector to store number of points in each coordinate direction
template<typename V, typename M>
const BoxSubset<V,M>& QUESO::InterpolationSurrogateData< V, M >::get_paramDomain ( ) const
inline

Definition at line 45 of file InterpolationSurrogateData.h.

References QUESO::InterpolationSurrogateData< V, M >::m_domain.

Referenced by QUESO::InterpolationSurrogateBuilder< V, M >::sync_data(), and QUESO::InterpolationSurrogateIOASCII< V, M >::write().

46  { return this->m_domain; };
const BoxSubset< V, M > & m_domain
Parameter domain over which we use surrogate.
template<typename V, typename M>
double QUESO::InterpolationSurrogateData< V, M >::get_value ( unsigned int  n) const
inline

Definition at line 57 of file InterpolationSurrogateData.h.

References QUESO::InterpolationSurrogateData< V, M >::m_values.

Referenced by QUESO::InterpolationSurrogateIOASCII< V, M >::write().

58  { queso_assert_less(n,this->m_values.size());
59  return this->m_values[n]; };
std::vector< double > m_values
vector to store values to be interpolated
template<typename V, typename M>
const std::vector<double>& QUESO::InterpolationSurrogateData< V, M >::get_values ( ) const
inline

Definition at line 51 of file InterpolationSurrogateData.h.

References QUESO::InterpolationSurrogateData< V, M >::m_values.

52  { return this->m_values; };
std::vector< double > m_values
vector to store values to be interpolated
template<typename V, typename M>
std::vector<double>& QUESO::InterpolationSurrogateData< V, M >::get_values ( )
inline

Definition at line 54 of file InterpolationSurrogateData.h.

References QUESO::InterpolationSurrogateData< V, M >::m_values.

55  { return this->m_values; };
std::vector< double > m_values
vector to store values to be interpolated
template<class V , class M >
double QUESO::InterpolationSurrogateData< V, M >::get_x ( unsigned int  dim,
unsigned int  index 
) const

Get spatial coordinate value at the node index along coordinate direction dim.

Definition at line 125 of file InterpolationSurrogateData.C.

126  {
127  double x_min = this->x_min(dim);
128  double spacing = this->spacing(dim);
129 
130  return x_min + spacing*index;
131  }
double spacing(unsigned int dim) const
Spacing between points along dimension dim.
unsigned int dim() const
Dimension of parameter space.
double x_min(unsigned int dim) const
Lower bound of domain along dimension dim.
template<class V , class M >
void QUESO::InterpolationSurrogateData< V, M >::init_values ( const std::vector< unsigned int > &  n_points)
private

Helper function for sizing m_values.

Definition at line 75 of file InterpolationSurrogateData.C.

Referenced by QUESO::InterpolationSurrogateData< V, M >::InterpolationSurrogateData().

76  {
77  unsigned int n_total_points = 1.0;
78  for( std::vector<unsigned int>::const_iterator it = n_points.begin();
79  it != n_points.end(); ++it )
80  {
81  n_total_points *= *it;
82  }
83 
84  this->m_values.resize(n_total_points);
85  }
std::vector< double > m_values
vector to store values to be interpolated
template<typename V, typename M>
unsigned int QUESO::InterpolationSurrogateData< V, M >::n_values ( ) const
inline

Definition at line 61 of file InterpolationSurrogateData.h.

References QUESO::InterpolationSurrogateData< V, M >::m_values.

Referenced by QUESO::InterpolationSurrogateBuilder< V, M >::sync_data(), and QUESO::InterpolationSurrogateIOASCII< V, M >::write().

62  { return this->m_values.size(); };
std::vector< double > m_values
vector to store values to be interpolated
template<class V , class M >
void QUESO::InterpolationSurrogateData< V, M >::set_value ( unsigned int  n,
double  value 
)

Definition at line 107 of file InterpolationSurrogateData.C.

Referenced by QUESO::InterpolationSurrogateBuilder< V, M >::sync_data().

108  {
109  queso_assert_less( n, m_values.size() );
110 
111  this->m_values[n] = value;
112  }
std::vector< double > m_values
vector to store values to be interpolated
template<class V , class M >
void QUESO::InterpolationSurrogateData< V, M >::set_values ( std::vector< double > &  values)

Set all values. Dimension must be consistent with internal m_values.

This does a full copy of the values vector. This is mainly for testing, users are encouraged to use the InterpolationSurrogateBuilder.

Definition at line 99 of file InterpolationSurrogateData.C.

100  {
101  queso_assert_equal_to( values.size(), m_values.size() );
102 
103  this->m_values = values;
104  }
std::vector< double > m_values
vector to store values to be interpolated
template<class V , class M >
double QUESO::InterpolationSurrogateData< V, M >::spacing ( unsigned int  dim) const

Spacing between points along dimension dim.

Definition at line 115 of file InterpolationSurrogateData.C.

References dim.

116  {
117  unsigned int n_intervals = this->m_n_points[dim]-1;
118  double x_min = this->x_min(dim);
119  double x_max = this->x_max(dim);
120 
121  return (x_max-x_min)/n_intervals;
122  }
const std::vector< unsigned int > & m_n_points
vector to store number of points in each coordinate direction
double x_max(unsigned int dim) const
Upper bound of domain along dimension dim.
unsigned int dim() const
Dimension of parameter space.
double x_min(unsigned int dim) const
Lower bound of domain along dimension dim.
template<class V , class M >
void QUESO::InterpolationSurrogateData< V, M >::sync_values ( unsigned int  root)

Sync values across all processors from root processor.

m_values may only be set on one processor, so this method is used for MPI_Bcast'ing those values to all processors. This calls MPI_Bcast, which is collective, so this MUST be called from all processors in env.fullComm().

Definition at line 134 of file InterpolationSurrogateData.C.

References QUESO::MpiComm::Bcast().

Referenced by QUESO::InterpolationSurrogateBuilder< V, M >::sync_data().

135  {
136  MpiComm full_comm = this->m_domain.env().fullComm();
137 
138  full_comm.Bcast( &this->m_values[0], this->n_values(),
139  RawValue_MPI_DOUBLE, root,
140  "InterpolationSurrogateData::sync_values()",
141  "MpiComm::Bcast() failed!" );
142  }
std::vector< double > m_values
vector to store values to be interpolated
const BoxSubset< V, M > & m_domain
Parameter domain over which we use surrogate.
template<typename V, typename M>
double QUESO::InterpolationSurrogateData< V, M >::x_max ( unsigned int  dim) const
inline

Upper bound of domain along dimension dim.

Definition at line 80 of file InterpolationSurrogateData.h.

References QUESO::InterpolationSurrogateData< V, M >::dim(), and QUESO::InterpolationSurrogateData< V, M >::m_domain.

Referenced by QUESO::InterpolationSurrogateIOASCII< V, M >::write().

81  { return this->m_domain.maxValues()[dim]; };
const BoxSubset< V, M > & m_domain
Parameter domain over which we use surrogate.
unsigned int dim() const
Dimension of parameter space.
template<typename V, typename M>
double QUESO::InterpolationSurrogateData< V, M >::x_min ( unsigned int  dim) const
inline

Lower bound of domain along dimension dim.

Definition at line 76 of file InterpolationSurrogateData.h.

References QUESO::InterpolationSurrogateData< V, M >::dim(), and QUESO::InterpolationSurrogateData< V, M >::m_domain.

Referenced by QUESO::InterpolationSurrogateIOASCII< V, M >::write().

77  { return this->m_domain.minValues()[dim]; };
const BoxSubset< V, M > & m_domain
Parameter domain over which we use surrogate.
unsigned int dim() const
Dimension of parameter space.

Member Data Documentation

template<typename V, typename M>
const std::vector<unsigned int>& QUESO::InterpolationSurrogateData< V, M >::m_n_points
private

vector to store number of points in each coordinate direction

We assume that the spacing in each coordinate direction is constant so we only need to know the number of points.

Definition at line 115 of file InterpolationSurrogateData.h.

Referenced by QUESO::InterpolationSurrogateData< V, M >::get_n_points(), and QUESO::InterpolationSurrogateData< V, M >::InterpolationSurrogateData().

template<typename V, typename M>
std::vector<double> QUESO::InterpolationSurrogateData< V, M >::m_values
private

vector to store values to be interpolated

These will be stored in a particular ordering. Helper functions will provide mapping between grid coordinates and a global coordinate; the global coordinate will be used to index into the values.

Todo:
We currently store all values reside on all processes. Generalization would be to partition values across processes allocated for the subenvironment.

Definition at line 123 of file InterpolationSurrogateData.h.

Referenced by QUESO::InterpolationSurrogateData< V, M >::get_value(), QUESO::InterpolationSurrogateData< V, M >::get_values(), and QUESO::InterpolationSurrogateData< V, M >::n_values().


The documentation for this class was generated from the following files:

Generated on Tue Jun 5 2018 19:49:40 for queso-0.57.1 by  doxygen 1.8.5