26 #include <queso/InterpolationSurrogateIOASCII.h>
29 #include <queso/StreamUtilities.h>
30 #include <queso/GslVector.h>
31 #include <queso/GslMatrix.h>
39 template<
class V,
class M>
44 template<
class V,
class M>
47 const std::string& vector_space_prefix,
51 int root = reading_rank;
63 input.open( filename.c_str() );
73 full_comm.
Bcast( &dim, 1, MPI_UNSIGNED, root,
74 "InterpolationSurrogateIOASCII::read()",
75 "MpiComm::Bcast() failed!" );
79 vector_space_prefix.c_str(),
84 this->m_n_points.resize(dim);
88 for(
unsigned int d = 0; d <
dim; d++ )
97 input >> this->m_n_points[d];
102 full_comm.
Bcast( &this->m_n_points[0], dim, MPI_UNSIGNED, root,
103 "InterpolationSurrogateIOASCII::read()",
104 "MpiComm::Bcast() failed!" );
107 std::vector<double> param_mins(dim);
108 std::vector<double> param_maxs(dim);
112 for(
unsigned int d = 0; d <
dim; d++ )
121 input >> param_mins[d] >> param_maxs[d];
126 full_comm.
Bcast( ¶m_mins[0], dim, MPI_DOUBLE, root,
127 "InterpolationSurrogateIOASCII::read()",
128 "MpiComm::Bcast() failed!" );
130 full_comm.
Bcast( ¶m_maxs[0], dim, MPI_DOUBLE, root,
131 "InterpolationSurrogateIOASCII::read()",
132 "MpiComm::Bcast() failed!" );
140 for(
unsigned int d = 0; d <
dim; d++ )
142 paramMins[d] = param_mins[d];
143 paramMaxs[d] = param_maxs[d];
146 this->m_domain.reset(
new BoxSubset<V,M>(vector_space_prefix.c_str(),
147 *(this->m_vector_space.get()),
158 for(
unsigned int n = 0; n < this->m_data->n_values(); n++ )
170 this->m_data->set_value( n, value );
178 this->m_data->sync_values(root);
183 template<
class V,
class M>
186 int writing_rank )
const
191 std::string error =
"ERROR: No values found in InterpolationSurrogateData.\n";
192 error +=
"Cannot write data without values.\n";
193 error +=
"Use InterpolationSurrogateBuilder or the read method to populate\n";
194 error +=
"data values.\n";
199 std::ofstream output;
204 output.open( filename.c_str() );
207 std::string header =
"# Data for interpolation surrogate\n";
208 header +=
"# Format is as follows:\n";
209 header +=
"# dimension (unsigned int)\n";
210 header +=
"# n_points in each dimension\n";
211 header +=
"# x_min, x_max pairs for each dimension\n";
212 header +=
"# values for each point in parameter space\n";
213 header +=
"# values must be ordered in structured format.\n";
218 output << dim << std::endl;
221 output <<
"# n_points" << std::endl;
222 for(
unsigned int d = 0; d <
dim; d++ )
228 output << std::scientific << std::setprecision(16);
231 output <<
"# domain bounds" << std::endl;
232 for(
unsigned int d = 0; d <
dim; d++ )
234 output << data.
x_min(d) <<
" "
235 << data.
x_max(d) << std::endl;
239 output <<
"# values" << std::endl;
240 for(
unsigned int n = 0; n < data.
n_values(); n++ )
242 output << data.
get_value(n) << std::endl;
const BoxSubset< V, M > & get_paramDomain() const
double x_min(unsigned int dim) const
Lower bound of domain along dimension dim.
int fullRank() const
Returns the process full rank.
#define queso_error_msg(msg)
const MpiComm & fullComm() const
Access function for MpiComm full communicator.
double get_value(unsigned int n) const
unsigned int n_values() const
const std::vector< unsigned int > & get_n_points() const
The QUESO MPI Communicator Class.
virtual void write(const std::string &filename, const InterpolationSurrogateData< V, M > &data, int writing_rank=0) const
Write interpolation surrogate data to filename using processor writing_rank.
Class for vector operations using GSL library.
This class sets up the full environment underlying the use of the QUESO library by an executable...
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.
static void skip_comment_lines(std::istream &in, const char comment_start)
Skips comment lines until a line without a comment character is encountered.
Class representing a subset of a vector space shaped like a hypercube.
virtual void read(const std::string &filename, const FullEnvironment &env, const std::string &vector_space_prefix, int reading_rank=0)
Read Interpolation surrogate data from filename using processor reading_rank.
double x_max(unsigned int dim) const
Upper bound of domain along dimension dim.
A class representing a vector space.
InterpolationSurrogateIOASCII()