queso-0.56.0
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-2015 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 
33 // C++
34 #include <sstream>
35 
36 namespace QUESO
37 {
38  template<class V, class M>
40  const std::vector<unsigned int>& n_points )
41  : m_domain(domain),
42  m_n_points(n_points)
43  {
44  // This checks that the dimension of n_points and the domain are consistent
45  this->check_dim_consistency();
46 
47  // Size m_values
48  this->init_values(this->m_n_points);
49  }
50 
51  template<class V, class M>
53  {
54  if( this->dim() != this->m_n_points.size() )
55  {
56  std::stringstream vspace_dim;
57  vspace_dim << this->m_domain.vectorSpace().dimGlobal();
58 
59  std::stringstream n_points_dim;
60  n_points_dim << this->m_n_points.size();
61 
62  std::string error = "ERROR: Mismatch between dimension of parameter space and number of points\n.";
63  error += " domain dimension = " + vspace_dim.str() + "\n";
64  error += " points dimension = " + n_points_dim.str() + "\n";
65 
66  queso_error_msg(error);
67  }
68  }
69 
70  template<class V, class M>
71  void InterpolationSurrogateData<V,M>::init_values( const std::vector<unsigned int>& n_points )
72  {
73  unsigned int n_total_points = 1.0;
74  for( std::vector<unsigned int>::const_iterator it = n_points.begin();
75  it != n_points.end(); ++it )
76  {
77  n_total_points *= *it;
78  }
79 
80  this->m_values.resize(n_total_points);
81  }
82 
83  template<class V, class M>
84  void InterpolationSurrogateData<V,M>::set_values( std::vector<double>& values )
85  {
86  queso_assert_equal_to( values.size(), m_values.size() );
87 
88  this->m_values = values;
89  }
90 
91  template<class V, class M>
92  void InterpolationSurrogateData<V,M>::set_value( unsigned int n, double value )
93  {
94  queso_assert_less( n, m_values.size() );
95 
96  this->m_values[n] = value;
97  }
98 
99  template<class V, class M>
100  double InterpolationSurrogateData<V,M>::spacing( unsigned int dim ) const
101  {
102  unsigned int n_intervals = this->m_n_points[dim]-1;
103  double x_min = this->x_min(dim);
104  double x_max = this->x_max(dim);
105 
106  return (x_max-x_min)/n_intervals;
107  }
108 
109  template<class V, class M>
110  double InterpolationSurrogateData<V,M>::get_x( unsigned int dim, unsigned int index ) const
111  {
112  double x_min = this->x_min(dim);
113  double spacing = this->spacing(dim);
114 
115  return x_min + spacing*index;
116  }
117 
118  template<class V, class M>
120  {
121  MpiComm full_comm = this->m_domain.env().fullComm();
122 
123  full_comm.Bcast( &this->m_values[0], this->n_values(),
124  RawValue_MPI_DOUBLE, root,
125  "InterpolationSurrogateData::sync_values()",
126  "MpiComm::Bcast() failed!" );
127  }
128 
129 
130 } // end namespace QUESO
131 
132 // Instantiate
int dim
Definition: ann2fig.cpp:81
void sync_values(unsigned int root)
Sync values across all processors from root processor.
const std::vector< unsigned int > & m_n_points
vector to store number of points in each coordinate direction
void set_values(std::vector< double > &values)
Set all values. Dimension must be consistent with internal m_values.
Class representing a subset of a vector space shaped like a hypercube.
Definition: BoxSubset.h:44
#define RawValue_MPI_DOUBLE
Definition: MpiComm.h:67
that you receive source code or can get it if you want it
Definition: License.txt:41
#define queso_assert_equal_to(expr1, expr2)
Definition: asserts.h:135
The QUESO MPI Communicator Class.
Definition: MpiComm.h:203
void set_value(unsigned int n, double value)
#define queso_assert_less(expr1, expr2)
Definition: asserts.h:141
double get_x(unsigned int dim, unsigned int index) const
Get spatial coordinate value at the node index along coordinate direction dim.
void init_values(const std::vector< unsigned int > &n_points)
Helper function for sizing m_values.
#define queso_error_msg(msg)
Definition: asserts.h:47
double spacing(unsigned int dim) const
Spacing between points along dimension dim.
void check_dim_consistency() const
Helper function for constructor.
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:181

Generated on Tue Nov 29 2016 10:53:11 for queso-0.56.0 by  doxygen 1.8.5