26 #include <queso/InterpolationSurrogateIOASCII.h>
29 #include <queso/MpiComm.h>
30 #include <queso/StreamUtilities.h>
31 #include <queso/GslVector.h>
32 #include <queso/GslMatrix.h>
40 template<
class V,
class M>
45 template<
class V,
class M>
48 const std::string& vector_space_prefix,
52 int root = reading_rank;
64 input.open( filename.c_str() );
74 full_comm.
Bcast( &dim, 1, RawValue_MPI_UNSIGNED, root,
75 "InterpolationSurrogateIOASCII::read()",
76 "MpiComm::Bcast() failed!" );
80 vector_space_prefix.c_str(),
85 this->m_n_points.resize(dim);
89 for(
unsigned int d = 0; d <
dim; d++ )
96 queso_error_msg(
"ERROR: Found unexpected end-of-file");
98 input >> this->m_n_points[d];
103 full_comm.
Bcast( &this->m_n_points[0], dim, RawValue_MPI_UNSIGNED, root,
104 "InterpolationSurrogateIOASCII::read()",
105 "MpiComm::Bcast() failed!" );
108 std::vector<double> param_mins(dim);
109 std::vector<double> param_maxs(dim);
113 for(
unsigned int d = 0; d <
dim; d++ )
120 queso_error_msg(
"ERROR: Found unexpected end-of-file");
122 input >> param_mins[d] >> param_maxs[d];
127 full_comm.
Bcast( ¶m_mins[0], dim, RawValue_MPI_DOUBLE, root,
128 "InterpolationSurrogateIOASCII::read()",
129 "MpiComm::Bcast() failed!" );
131 full_comm.
Bcast( ¶m_maxs[0], dim, RawValue_MPI_DOUBLE, root,
132 "InterpolationSurrogateIOASCII::read()",
133 "MpiComm::Bcast() failed!" );
141 for(
unsigned int d = 0; d <
dim; d++ )
143 paramMins[d] = param_mins[d];
144 paramMaxs[d] = param_maxs[d];
147 this->m_domain.reset(
new BoxSubset<V,M>(vector_space_prefix.c_str(),
148 *(this->m_vector_space.get()),
159 for(
unsigned int n = 0; n < this->m_data->n_values(); n++ )
166 queso_error_msg(
"ERROR: Found unexpected end-of-file");
171 this->m_data->set_value( n, value );
179 this->m_data->sync_values(root);
184 template<
class V,
class M>
187 int writing_rank )
const
192 std::string error =
"ERROR: No values found in InterpolationSurrogateData.\n";
193 error +=
"Cannot write data without values.\n";
194 error +=
"Use InterpolationSurrogateBuilder or the read method to populate\n";
195 error +=
"data values.\n";
197 queso_error_msg(error);
200 std::ofstream output;
205 output.open( filename.c_str() );
208 std::string header =
"# Data for interpolation surrogate\n";
209 header +=
"# Format is as follows:\n";
210 header +=
"# dimension (unsigned int)\n";
211 header +=
"# n_points in each dimension\n";
212 header +=
"# x_min, x_max pairs for each dimension\n";
213 header +=
"# values for each point in parameter space\n";
214 header +=
"# values must be ordered in structured format.\n";
219 output << dim << std::endl;
222 output <<
"# n_points" << std::endl;
223 for(
unsigned int d = 0; d <
dim; d++ )
229 output << std::scientific << std::setprecision(16);
232 output <<
"# domain bounds" << std::endl;
233 for(
unsigned int d = 0; d <
dim; d++ )
235 output << data.
x_min(d) <<
" "
236 << data.
x_max(d) << std::endl;
240 output <<
"# values" << std::endl;
241 for(
unsigned int n = 0; n < data.
n_values(); n++ )
243 output << data.
get_value(n) << std::endl;
const BoxSubset< V, M > & get_paramDomain() const
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.
A class representing a vector space.
double get_value(unsigned int n) const
const std::vector< unsigned int > & get_n_points() const
This class sets up the full environment underlying the use of the QUESO library by an executable...
int fullRank() const
Returns the rank of the MPI process in QUESO's full communicator.
unsigned int n_values() const
Class representing a subset of a vector space shaped like a hypercube.
static void skip_comment_lines(std::istream &in, const char comment_start)
Skips comment lines until a line without a comment character is encountered.
double x_max(unsigned int dim) const
Upper bound of domain along dimension dim.
Class for vector operations using GSL library.
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.
The QUESO MPI Communicator Class.
const MpiComm & fullComm() const
Access function for the communicator that was passed to QUESO's environment.
InterpolationSurrogateIOASCII()
double x_min(unsigned int dim) const
Lower bound of domain 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.