queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
InterpolationSurrogateData.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 // This class
26 #include <queso/InterpolationSurrogateData.h>
27 
28 // QUESO
29 #include <queso/MpiComm.h>
30 #include <queso/GslVector.h>
31 #include <queso/GslMatrix.h>
32 #include <queso/math_macros.h>
33 
34 // C++
35 #include <sstream>
36 
37 namespace QUESO
38 {
39  template<class V, class M>
41  const std::vector<unsigned int>& 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  }
54 
55  template<class V, class M>
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  }
73 
74  template<class V, class M>
75  void InterpolationSurrogateData<V,M>::init_values( const std::vector<unsigned int>& n_points )
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  }
86 
87  template<class V, class M>
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  }
97 
98  template<class V, class M>
99  void InterpolationSurrogateData<V,M>::set_values( std::vector<double>& values )
100  {
101  queso_assert_equal_to( values.size(), m_values.size() );
102 
103  this->m_values = values;
104  }
105 
106  template<class V, class M>
107  void InterpolationSurrogateData<V,M>::set_value( unsigned int n, double value )
108  {
109  queso_assert_less( n, m_values.size() );
110 
111  this->m_values[n] = value;
112  }
113 
114  template<class V, class M>
115  double InterpolationSurrogateData<V,M>::spacing( unsigned int dim ) const
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  }
123 
124  template<class V, class M>
125  double InterpolationSurrogateData<V,M>::get_x( unsigned int dim, unsigned int index ) const
126  {
127  double x_min = this->x_min(dim);
128  double spacing = this->spacing(dim);
129 
130  return x_min + spacing*index;
131  }
132 
133  template<class V, class M>
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  }
143 
144 
145 } // end namespace QUESO
146 
147 // Instantiate
bool queso_isfinite(T arg)
Definition: math_macros.h:51
const std::vector< unsigned int > & m_n_points
vector to store number of points in each coordinate direction
double spacing(unsigned int dim) const
Spacing between points along dimension dim.
void set_value(unsigned int n, double value)
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:44
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.
int dim
Definition: ann_test.cpp:472
double get_x(unsigned int dim, unsigned int index) const
Get spatial coordinate value at the node index along coordinate direction dim.
The QUESO MPI Communicator Class.
Definition: MpiComm.h:203
void set_values(std::vector< double > &values)
Set all values. Dimension must be consistent with internal m_values.
void sync_values(unsigned int root)
Sync values across all processors from root processor.
void Bcast(void *buffer, int count, RawType_MPI_Datatype datatype, int root, const char *whereMsg, const char *whatMsg) const
Broadcast values from the root process to the slave processes.
Definition: MpiComm.C:191

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