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

Generated on Thu Jun 11 2015 13:52:33 for queso-0.53.0 by  doxygen 1.8.5